当前位置: 首页>>代码示例>>Scala>>正文


Scala jQuery类代码示例

本文整理汇总了Scala中org.scalajs.jquery.jQuery的典型用法代码示例。如果您正苦于以下问题:Scala jQuery类的具体用法?Scala jQuery怎么用?Scala jQuery使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了jQuery类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。

示例1: TorrentStreamFrontend

//设置package包名称以及导入依赖的类
package com.karasiq.torrentstream.frontend

import com.karasiq.bootstrap.BootstrapImplicits._
import com.karasiq.bootstrap.grid.GridSystem
import com.karasiq.bootstrap.icons.FontAwesome
import com.karasiq.bootstrap.navbar.{NavigationBar, NavigationTab}
import com.karasiq.torrentstream.frontend.components.TorrentManagementPanel
import org.scalajs.dom
import org.scalajs.jquery.jQuery
import rx._

import scala.scalajs.js.JSApp
import scala.scalajs.js.annotation.JSExport
import scalatags.JsDom.all._

@JSExport
object TorrentStreamFrontend extends JSApp {
  private implicit val context = implicitly[Ctx.Owner]

  @JSExport
  override def main(): Unit = {
    jQuery(() ? {
      val navigationBar = NavigationBar(
        NavigationTab("Torrents", "torrents", "file".fontAwesome(FontAwesome.fixedWidth), new TorrentManagementPanel)
      )
      val body = dom.document.body
      body.appendChild(navigationBar.navbar("TorrentStream").render)
      body.appendChild {
        GridSystem.container(id := "main-container")(
          GridSystem.mkRow(navigationBar.content)
        ).render
      }
    })
  }
} 
开发者ID:Karasiq,项目名称:torrentstream,代码行数:36,代码来源:TorrentStreamFrontend.scala

示例2: Client

//设置package包名称以及导入依赖的类
package kartograffel.client

import eu.timepit.refined.api.RefType
import io.circe.syntax._
import kartograffel.shared.model.Position
import kartograffel.shared.model.Position.{Latitude, Longitude}
import org.scalajs.dom
import org.scalajs.dom.{window, Coordinates, PositionError, PositionOptions}
import org.scalajs.jquery.jQuery

import scala.scalajs.js

object Client {
  def main(args: Array[String]): Unit = {

    jQuery("body").append("<p>Hallo!</p>")

    val opts = js.Object().asInstanceOf[PositionOptions]
    opts.timeout = 50000
    opts.enableHighAccuracy = true

    window.navigator.geolocation.getCurrentPosition(
      { pos: dom.Position =>
        val loc = locationFrom(pos.coords).get
        println("Location" + locationFrom(pos.coords))
        println(pos)
        jQuery.post(url = "/api/post",
                    data = loc.asJson.spaces2,
                    success = null,
                    dataType = null)

      }, { err: PositionError =>
        println(err.code)
        println(err.message)
      },
      opts
    )

    println("Hello, world!1111")
  }

  def locationFrom(coordinates: Coordinates): Option[Position] = {
    val location = for {
      latitude <- RefType.applyRef[Latitude](coordinates.latitude)
      longitude <- RefType.applyRef[Longitude](coordinates.longitude)
    } yield Position(latitude, longitude)
    location.toOption
  }
} 
开发者ID:fthomas,项目名称:kartograffel,代码行数:50,代码来源:Client.scala

示例3: JSCarousel

//设置package包名称以及导入依赖的类
package com.karasiq.bootstrap.carousel

import com.karasiq.bootstrap.components.BootstrapComponents
import com.karasiq.bootstrap.context.JSRenderingContext
import com.karasiq.bootstrap.utils.Utils
import org.scalajs.jquery.jQuery
import rx.Rx

import scala.language.postfixOps
import scala.scalajs.js

trait JSCarousels { self: JSRenderingContext with Carousels with BootstrapComponents with Utils ?
  import scalaTags.all._ 

  class JSCarousel(carouselId: String, content: Rx[Seq[Modifier]]) extends Carousel(carouselId, content) {
    def create(interval: Int = 5000, pause: String = "hover", wrap: Boolean = true, keyboard: Boolean = true, modifiers: Modifier = ()): Element = {
      val element = carousel(modifiers).render
      val options = js.Object().asInstanceOf[JSCarouselOptions]
      options.interval = interval
      options.pause = pause
      options.wrap = wrap
      options.keyboard = keyboard
      jQuery(element).carousel(options)
      element
    }

    override def render(md: Modifier*): Modifier = {
      create(modifiers = md)
    }
  }

  
  object Carousel extends CarouselFactory {
    def apply(data: Rx[Seq[Modifier]], id: String = Bootstrap.newId): Carousel = {
      new JSCarousel(id, data)
    }
  }
} 
开发者ID:Karasiq,项目名称:scalajs-bootstrap,代码行数:39,代码来源:JSCarousels.scala

示例4: JSModalOps

//设置package包名称以及导入依赖的类
package com.karasiq.bootstrap.modal

import com.karasiq.bootstrap.context.JSRenderingContext
import org.scalajs.jquery.jQuery

import scala.language.postfixOps
import scala.scalajs.js
import scala.scalajs.js.|

trait JSModals { self: JSRenderingContext with Modals ?
  implicit class JSModalOps(modal: Modal) {
    def show(backdrop: Boolean | String = true, keyboard: Boolean = true, show: Boolean = true): Unit = {
      val dialog = jQuery(modal.renderTag().render)
      val options = js.Object().asInstanceOf[JSModalOptions]
      options.backdrop = backdrop
      options.keyboard = keyboard
      options.show = show
      dialog.modal(options)
      dialog.on("hidden.bs.modal", () ? {
        // Remove from DOM
        dialog.remove()
      })
      dialog.modal("show")
    }
  }
} 
开发者ID:Karasiq,项目名称:scalajs-bootstrap,代码行数:27,代码来源:JSModals.scala

示例5: SheetView

//设置package包名称以及导入依赖的类
package spreadsheets

import org.scalajs.jquery.{JQuery, jQuery}

class SheetView(w: Int, h: Int, parent: JQuery, controller: Sheet) {
  private val table = jQuery("<table>"); parent.append(table)

  {
    def nToI(columnNumber: Int): String = {
      var dividend = columnNumber + 1
      var columnName = ""

      while (dividend > 0) {
        val modulo = (dividend - 1) % 26
        columnName = ('A' + modulo).toChar + columnName
        dividend = (dividend - modulo) / 26
      }

      columnName
    }

    val tr = jQuery("<tr>"); table.append(tr)
    tr.append(jQuery("<td>"))
    for (col <- 0 until w) tr.append(jQuery("<th>").text(s"${nToI(col)}"))
  }

  private val cells = for (row <- 0 until h) yield {
    val tr = jQuery("<tr>"); table.append(tr)
    tr.append(jQuery("<th>").text(s"${row + 1}"))
    for (col <- 0 until w) yield {
      val td = jQuery("<td>"); tr.append(td)
      new CellView(td, col, row, controller)
    }
  }

  def updateCell(col: Int, row: Int, source: String, value: String, error: String = ""): Unit = {
    cells(row)(col).updateCell(source, value, error)
  }
} 
开发者ID:AmatanHead,项目名称:yarpo,代码行数:40,代码来源:SheetView.scala

示例6: TutorialApp

//设置package包名称以及导入依赖的类
package tutorial.webapp

import scala.scalajs.js.JSApp
import org.scalajs.jquery.jQuery

object TutorialApp extends JSApp {
  def main(): Unit = {
    jQuery(setupUI _)
  }

  def setupUI(): Unit = {
    jQuery("#click-me-button").click(addClickedMessage _)
    jQuery("body").append("<p>Hello Scala.js!</p>")
  }

  def addClickedMessage(): Unit = {
    jQuery("body").append("<p>You clicked the button!</p>")
  }
} 
开发者ID:susu,项目名称:hello-scalajs,代码行数:20,代码来源:TutorialApp.scala

示例7: Tooltip

//设置package包名称以及导入依赖的类
package com.mogproject.mogami.playground.view.bootstrap

import com.mogproject.mogami.util.Implicits._
import org.scalajs.dom
import org.scalajs.dom.Element
import org.scalajs.dom.raw.HTMLElement
import org.scalajs.jquery.{JQuery, jQuery}

import scala.scalajs.js


object Tooltip {
  def enableHoverToolTip(isMobile: Boolean): Unit = enableHoverToolTip(jQuery("""[data-toggle="tooltip"]"""), isMobile)

  def enableHoverToolTip(elems: Seq[HTMLElement]): Unit = elems.foreach(e => enableHoverToolTip(jQuery(e)))

  def enableHoverToolTip(jQuery: JQuery, isMobile: Boolean = false): Unit = {
    jQuery.asInstanceOf[BootstrapJQuery].tooltip {
      val r = js.Dynamic.literal()
      r.trigger = isMobile.fold("focus", "hover")
      r.asInstanceOf[TooltipOptions]
    }
  }

  def hideAllToolTip(): Unit = {
    jQuery("""[data-toggle="tooltip"]""").asInstanceOf[BootstrapJQuery].tooltip("hide")
  }

  def display(elem: Element, message: String, displayTime: Int = 1000): Unit = {
    jQuery(elem).attr("data-original-title", message).asInstanceOf[BootstrapJQuery].tooltip("show")
    val f = () => jQuery(elem).asInstanceOf[BootstrapJQuery].tooltip("hide").attr("data-original-title", "")
    dom.window.setTimeout(f, displayTime)
  }
} 
开发者ID:mogproject,项目名称:mog-playground,代码行数:35,代码来源:Tooltip.scala

示例8: MenuPane

//设置package包名称以及导入依赖的类
package com.mogproject.mogami.playground.view.section

import org.scalajs.jquery.jQuery
import com.mogproject.mogami.playground.view.bootstrap.BootstrapJQuery
import com.mogproject.mogami.util.Implicits._
import org.scalajs.dom.html.Div

import scala.scalajs.js
import scalatags.JsDom.all._


case class MenuPane(isMobile: Boolean) {

  private[this] val sections: Seq[Section] = Seq(
    GameMenuSection,
    ActionSection
  ) ++ isMobile.fold(
    Seq(BranchSection), Seq.empty
  ) ++ Seq(
    AnalyzeSection,
    EditSection,
    SettingsSection,
    GameHelpSection,
    EditHelpSection,
    AboutSection
  )

  val output: Div = div(
    cls := "panel-group", id := "accordion", role := "tablist", aria.multiselectable := true,
    sections.map(_.outputs)
  ).render

  initialize()

  def initialize(): Unit = {
    sections.foreach(_.initialize())
  }

  def collapseMenu(): Unit = {
    jQuery(".panel-collapse").asInstanceOf[BootstrapJQuery].collapse {
      val r = js.Dynamic.literal()
      r.toggle = false
      r.parent = "#accordion" // necessary to keep group settings
      r
    }
    jQuery(".panel-collapse").asInstanceOf[BootstrapJQuery].collapse("hide")

    sections.foreach(_.collapseTitle())
  }

  def expandMenu(): Unit = {
    sections.foreach(_.expandTitle())
  }
} 
开发者ID:mogproject,项目名称:mog-playground,代码行数:55,代码来源:MenuPane.scala

示例9: Template

//设置package包名称以及导入依赖的类
import org.scalajs.dom
import org.scalajs.dom.document
import org.scalajs.jquery.jQuery

import scala.scalajs.js.JSApp
import scala.scalajs.js.annotation.JSExport

object Template extends JSApp {

  def appendPar(text:String) = {
    jQuery(document.body).append(s"<p>${text}</p>")
  }

  def setupUI() = {
    jQuery("<button type='button'>Click</button>")
      .appendTo(document.body)
      .click(() => appendPar("Template"))
  }

  @JSExport
  override def main(): Unit = {
    jQuery(setupUI _)
  }
} 
开发者ID:fbaumgardt,项目名称:scalajs-template,代码行数:25,代码来源:Template.scala

示例10: TemplateTest

//设置package包名称以及导入依赖的类
import utest._
import org.scalajs.jquery.jQuery

object TemplateTest extends TestSuite {

  Template.setupUI()

  def tests = this {

    def count = jQuery("p").length
    val button = jQuery("button")

    "Button exists"-{
      assert(button.length==1)
    }
    "Button Works"-{
      for (c <- 1 to 5) {
        button.click()
        assert(count == c)
      }
    }

  }

} 
开发者ID:fbaumgardt,项目名称:scalajs-template,代码行数:26,代码来源:TemplateTest.scala

示例11: SocketJS

//设置package包名称以及导入依赖的类
package com.malliina.logstreams.js

import org.scalajs.dom
import org.scalajs.dom.CloseEvent
import org.scalajs.dom.raw.{ErrorEvent, Event, MessageEvent}
import org.scalajs.jquery.jQuery
import upickle.Invalid

import scala.scalajs.js
import scala.scalajs.js.JSON

abstract class SocketJS(wsPath: String) {
  val statusElem = elem("status")

  val socket: dom.WebSocket = openSocket(wsPath)

  def handlePayload(payload: String)

  def openSocket(pathAndQuery: String) = {
    val wsUrl = s"$wsBaseUrl$pathAndQuery"
    val socket = new dom.WebSocket(wsUrl)
    socket.onopen = (_: Event) => setFeedback("Connected.")
    socket.onmessage = (event: MessageEvent) => onMessage(event)
    socket.onclose = (_: CloseEvent) => setFeedback("Connection closed.")
    socket.onerror = (_: ErrorEvent) => setFeedback("Connection error.")
    socket
  }

  def wsBaseUrl = {
    val location = dom.window.location
    val wsProto = if (location.protocol == "http:") "ws" else "wss"
    s"$wsProto://${location.host}"
  }

  def onMessage(msg: MessageEvent): Unit = {
    val event = JSON.parse(msg.data.toString)
    if (event.event.toString == "ping") {
    } else {
      handlePayload(JSON.stringify(event))
    }
  }

  def onInvalidData(message: String): PartialFunction[Invalid, Unit] = {
    case Invalid.Data(jsValue, errorMessage) =>
      println(s"JSON failed to parse: '$errorMessage' in value '$jsValue', message '$message'.")
    case Invalid.Json(errorMessage, in) =>
      println(s"Not JSON, '$errorMessage' in value '$in', message '$message'.")
  }

  def setFeedback(feedback: String) = statusElem html feedback

  def elem(id: String) = jQuery(s"#$id")

  def global = js.Dynamic.global

  def validate[T: PimpJSON.Reader](in: String): Either[Invalid, T] =
    PimpJSON.validate(in)
} 
开发者ID:malliina,项目名称:logstreams,代码行数:59,代码来源:SocketJS.scala

示例12: ExampleCallback

//设置package包名称以及导入依赖的类
package de.tu_berlin.formic.example

import de.tu_berlin.formic.client.NewInstanceCallback
import de.tu_berlin.formic.common.datastructure.client.{ClientDataStructureEvent, RemoteOperationEvent}
import de.tu_berlin.formic.common.datastructure.{DataStructureName, FormicDataStructure}
import de.tu_berlin.formic.datastructure.json.client.FormicJsonObject
import de.tu_berlin.formic.datastructure.linear.client.FormicString
import de.tu_berlin.formic.datastructure.tree.client.FormicIntegerTree
import org.scalajs.dom.document
import org.scalajs.jquery.jQuery


class ExampleCallback(val main: Main) extends NewInstanceCallback {

  override def newCallbackFor(instance: FormicDataStructure, dataType: DataStructureName): (ClientDataStructureEvent) => Unit = {
    instance match {
      case str: FormicString => main.updateUIForString(instance.dataStructureInstanceId)
      case tree: FormicIntegerTree => main.updateUIForTree(instance.dataStructureInstanceId)
      case json: FormicJsonObject => if(isBattleShip) main.newCallbackForBattleship(json) else main.updateUIForJson(instance.dataStructureInstanceId)
    }
  }

  override def doNewInstanceCreated(instance: FormicDataStructure, dataType: DataStructureName): Unit = {
    instance match {
      case str: FormicString =>
        main.strings += str
        val id = str.dataStructureInstanceId.id
        val inputId = id
        jQuery("body").append("<p>String data type with id " + id + "</p>")
        jQuery("body").append("<textarea rows=\"30\" cols=\"50\" class=\"stringInput\" id=\"" + inputId + "\"></textarea>")
        jQuery("#" + inputId).keypress(main.keyPressHandler(inputId))
        main.updateUIForString(str.dataStructureInstanceId)(RemoteOperationEvent(null))

      case tree: FormicIntegerTree =>
        main.trees += tree
        if (jQuery("body").has("#" + tree.dataStructureInstanceId.id).length == 0) {
          main.insertBasicTreeElements(tree.dataStructureInstanceId.id)
        }
        main.updateUIForTree(tree.dataStructureInstanceId)(null)

      case json: FormicJsonObject =>
        main.jsons += json
        if (isBattleShip) {
          //in order to force Battleship to update the UI we invoke the callback here manually
          json.callback(null)
        } else {
          if (jQuery("body").has("#" + json.dataStructureInstanceId.id).length == 0) {
            main.insertJsonManipulationElements(json.dataStructureInstanceId.id)
          }
          main.updateUIForJson(json.dataStructureInstanceId)(null)
        }
    }
  }

  def isBattleShip = document.location.href.contains("battleship")
} 
开发者ID:rbraeunlich,项目名称:formic,代码行数:57,代码来源:ExampleCallback.scala

示例13: Main

//设置package包名称以及导入依赖的类
package examplejs

import scala.scalajs.js.JSApp
import scala.util._
import org.scalajs.jquery.jQuery

import cats._
import cats.free._
import cats.implicits._
import cats.data.EitherT

import hammock._
import hammock.free._
import hammock.js.free._
import hammock.circe.implicits._

import io.circe._
import io.circe.generic.auto._

object Main extends JSApp {
  def main(): Unit = {

    import Codec._
    implicit val interpTrans = Interpreter

    case class Resp(json: String)
    case class Data(name: String, number: Int)


    type Target[A] = EitherT[Eval, Throwable, A]
    def Target = EitherT


    val uriFromString: Target[Uri] = Target.fromEither(Uri.fromString("http://httpbin.org/post").leftMap(new Exception(_)))

    val request: Target[Resp] = uriFromString >>= { uri =>
      Hammock
        .request(Method.POST, uri, Map(), Some(Data("name", 4).encode))
        .exec[Target]
        .as[Resp]
    }

    request.value.value match {
      case Right(resp) =>
        val dec = Codec[Data].decode(resp.json)
        jQuery("#result").append(s"""
<h3>Data you sent to the server:</h3>
<pre>$dec</pre>
""")
      case Left(ex) => ex.printStackTrace
    }
  }
} 
开发者ID:pepegar,项目名称:hammock,代码行数:54,代码来源:Main.scala

示例14: NanoboardFrontend

//设置package包名称以及导入依赖的类
package com.karasiq.nanoboard.frontend

import com.karasiq.bootstrap.BootstrapImplicits._
import com.karasiq.nanoboard.frontend.locales.BoardLocale
import com.karasiq.taboverridejs.TabOverride
import org.scalajs.jquery.jQuery
import org.widok.moment.Moment
import rx._

import scala.concurrent.ExecutionContext
import scala.scalajs.concurrent.JSExecutionContext
import scala.scalajs.js.JSApp
import scala.scalajs.js.annotation.JSExport

@JSExport
object NanoboardFrontend extends JSApp {
  implicit val ec: ExecutionContext = JSExecutionContext.queue
  implicit val ctx = implicitly[Ctx.Owner]

  @JSExport
  override def main(): Unit = {
    jQuery(() ? {
      TabOverride.tabSize(2)
      Moment.locale(BoardLocale.browserLanguage)
      NanoboardController().initialize()
    })
  }
} 
开发者ID:Karasiq,项目名称:nanoboard,代码行数:29,代码来源:NanoboardFrontend.scala

示例15: RxLocation

//设置package包名称以及导入依赖的类
package com.karasiq.nanoboard.frontend.utils

import org.scalajs.dom
import org.scalajs.dom.window
import org.scalajs.jquery.jQuery
import rx._

import scala.scalajs.js.UndefOr

final class RxLocation(implicit ctx: Ctx.Owner) {
  private def readHash(hash: UndefOr[String]): Option[String] = {
    hash
      .filter(_.nonEmpty)
      .map(_.tail)
      .toOption
  }

  val hash: Var[Option[String]] = Var(readHash(window.location.hash))

  hash.triggerLater {
    window.location.hash = hash.now.fold("")("#" + _)
  }

  jQuery(dom.window).on("hashchange", () ? {
    hash() = readHash(window.location.hash)
  })
}

object RxLocation {
  def apply()(implicit ctx: Ctx.Owner): RxLocation = {
    new RxLocation()
  }
} 
开发者ID:Karasiq,项目名称:nanoboard,代码行数:34,代码来源:RxLocation.scala


注:本文中的org.scalajs.jquery.jQuery类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。