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


Scala global类代码示例

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


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

示例1: DocumentTest

//设置package包名称以及导入依赖的类
package ch.epfl.callgraph.visualization

import ch.epfl.callgraph.utils.Utils.CallGraph
import ch.epfl.callgraph.visualization.view.{D3GraphView, HtmlView}
import org.junit.Assert._
import org.junit.{Before, Test}
import org.scalajs.dom.html._
import org.scalajs.{dom => sdom}
import upickle.{default => upickle}

import scala.scalajs
import scala.scalajs.js
import scala.scalajs.js.Dynamic.global

class DocumentTest {

  val $ = global.jQuery

  @Before
  def setupDocument() : Unit = {
    $("body").html("")
    $("body")
      .append(
        global.jQuery("<div id=\"header\"><h1>Scala.js Call Graph Visualization</h1></div>" +
          "<div id=\"nav\" style=\"overflow:auto\"></div>" +
          "<div id=\"main\" style=\"overflow:auto\"></div>"))
    HtmlView.main() // setup the file upload button
    D3GraphView.setCallGraph(upickle.read[CallGraph](generateGraph))
    HtmlView.updateHtmlAfterLoad(sdom.document.getElementById("nav").asInstanceOf[Div])
    D3GraphView.renderGraph()
  }

  def generateGraph = {
    """{"classes":[{"encodedName":"s_Predef$Triple$2","displayName":"scala.Predef$Triple$2","isExported":true,"superClass":[],"interfaces":[],"methods":[]}]}"""
  }

  @Test def testInitialDOM(): Unit = {
    assertEquals(1, $("#header").length)
    assertEquals(1, $("#nav").length)
    assertEquals(1, $("#main").length)
  }

  @Test def testInitialLayer : Unit = {
    HtmlView.showLayers
    assertEquals(1, $("li > a.active").length)
  }

  @Test def testSvgSingleNode : Unit = {
    println($("svg").html())
    $("svg").find("circle").each({(li: Html) => {
      println($(li).attr("class"))
    //  $(li).contextmenu()
    }}: scalajs.js.ThisFunction)
    assertEquals(1, $("svg").find("circle").length)

  }


} 
开发者ID:lionelfleury,项目名称:scala-js-call-graph,代码行数:60,代码来源:DocumentTest.scala

示例2: Hellp

//设置package包名称以及导入依赖的类
import scala.scalajs.js
import scala.scalajs.js.Dynamic.global
import org.scalajs.dom
import scalatags.JsDom.all._
import shared.SharedMessages
import org.scalajs.dom.ext.Ajax
import scala.concurrent.ExecutionContext

object Hellp extends js.JSApp {

  def main(): Unit = {
    if (!js.isUndefined(global.window.console)) {
      global.console.log("Welcome to your Play application's JavaScript!");
    }
    addItems
  }

  def addItems = {
    import scala.concurrent.ExecutionContext.Implicits.global
    dom.document
      .getElementById("scalajsclientDiv")
      .appendChild(ul(id := "itemList")(li("ScalaJS shouts out: ", em(SharedMessages.itWorks))).render)

    timeAt("UTC")
    timeAt("ECT")

  }

  def timeAt(tz: String)(implicit ec: ExecutionContext) = {
    Ajax.get("/api/timeAt/" + tz).onSuccess {
      case xhr =>
        dom.document
          .getElementById("itemList").appendChild(li(s"Time service (timeAt $tz): ", em(xhr.responseText)).render)
    }
  }

} 
开发者ID:oswaldo,项目名称:lagom-scala-scalajs-scalatags,代码行数:38,代码来源:Hello.scala

示例3: Hellp

//设置package包名称以及导入依赖的类
import scala.scalajs.js
import scala.scalajs.js.Dynamic.global
import org.scalajs.dom
import scalatags.JsDom.all._
import shared.SharedMessages

object Hellp extends js.JSApp {
  def main(): Unit = {
    if (!js.isUndefined(global.window.console)) {
      global.console.log("Welcome to your Play application's JavaScript!");
    }

    dom.document
      .getElementById("scalajsclientDiv")
      .appendChild(
          ul(li("ScalaJS shouts out: ", em(SharedMessages.itWorks))).render)

  }
} 
开发者ID:oswaldo,项目名称:play-scala-scalajs-scalatags,代码行数:20,代码来源:Hello.scala

示例4: CanvasTest

//设置package包名称以及导入依赖的类
package org.scalajs.jsenv.selenium

import org.junit.Assert._
import org.junit.Test

import scala.scalajs.js
import scala.scalajs.js.Dynamic.global

class CanvasTest {

  @Test def testCanvas(): Unit = {
    // create the element
    val canvasId = "testCanvas"
    CanvasCreator.create(canvasId)
    CanvasCreator.paint(canvasId)

    val body = global.document.getElementsByTagName("body")
        .asInstanceOf[js.Array[js.Dynamic]].head

    assertEquals("canvas", body.lastChild.tagName.toString.toLowerCase)
  }
} 
开发者ID:scala-js,项目名称:scala-js-env-selenium,代码行数:23,代码来源:CanvasTest.scala

示例5: JQueryTest

//设置package包名称以及导入依赖的类
package org.scalajs.jsenv.selenium

import org.junit.Assert._
import org.junit.Test

import scala.scalajs.js.Dynamic.global
import scala.scalajs.js.isUndefined

class JQueryTest {

  @Test def jQuery(): Unit = {
    assertFalse(isUndefined(global.jQuery))
    assertFalse(isUndefined(global.window.jQuery))
  }

  @Test def `$`(): Unit = {
    assertFalse(isUndefined(global.$))
    assertFalse(isUndefined(global.window.$))
  }
} 
开发者ID:scala-js,项目名称:scala-js-env-selenium,代码行数:21,代码来源:JQueryTest.scala

示例6: ElementCreatorTest

//设置package包名称以及导入依赖的类
package org.scalajs.jsenv.selenium

import org.junit.Assert._
import org.junit.Test

import scala.scalajs.js
import scala.scalajs.js.Dynamic.global

class ElementCreatorTest {

  @Test def should_be_able_to_create_an_element_in_the_body(): Unit = {
    // create the element
    ElementCreator.create("<h1>Testing DOM.</h1>")

    // jquery would make this easier, but I wanted to
    // only use pure html in the test itself
    val body = global.document.getElementsByTagName("body")
      .asInstanceOf[js.Array[js.Dynamic]].head

    // the Scala.js DOM API would make this easier
    assertEquals("H1", body.lastChild.tagName.toString)
    assertEquals("Testing DOM.", body.lastChild.innerHTML.toString)
  }
} 
开发者ID:scala-js,项目名称:scala-js-env-selenium,代码行数:25,代码来源:ElementCreatorTest.scala

示例7: TaskClient

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

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

import upickle.default._


abstract class TaskClient[Prompt : Reader, Response : Writer] {
  import scala.scalajs.js.Dynamic.global

  lazy val assignmentId: String = {
    global.turkSetAssignmentID()
    jQuery("#assignmentId").attr("value").get
  }

  lazy val isNotAssigned = assignmentId == "ASSIGNMENT_ID_NOT_AVAILABLE"

  lazy val taskKey: String = {
    read[String](jQuery(s"#$taskKeyLabel").attr("value").get)
  }

  lazy val serverDomain: String = {
    read[String](jQuery(s"#$serverDomainLabel").attr("value").get)
  }

  lazy val httpPort: Int = {
    read[Int](jQuery(s"#$httpPortLabel").attr("value").get)
  }

  lazy val httpsPort: Int = {
    read[Int](jQuery(s"#$httpsPortLabel").attr("value").get)
  }

  lazy val websocketUri: String = {
    val isHttps = dom.document.location.protocol == "https:"
    val wsProtocol = if (isHttps) "wss" else "ws"
    val serverPort = if(isHttps) httpsPort else httpPort
    s"$wsProtocol://$serverDomain:$serverPort/websocket?taskKey=$taskKey"
  }

  lazy val prompt: Prompt = {
    read[Prompt](jQuery(s"#$promptLabel").attr("value").get)
  }

  lazy val externalSubmitURL: String = {
    jQuery(s"form#$mturkFormLabel").attr("action").get
  }

  def setResponse(response: Response): Unit = {
    jQuery(s"#$responseLabel").attr("value", write(response))
  }

  def main(): Unit
} 
开发者ID:julianmichael,项目名称:turkey,代码行数:58,代码来源:TaskClient.scala

示例8: taskMapping

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

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

import upickle.default._


trait TaskDispatcher {

  // override this with the mapping from your task key to your task's main method
  def taskMapping: Map[String, () => Unit]

  import scala.scalajs.js.Dynamic.global

  lazy val taskKey: String = {
    read[String](jQuery(s"#$taskKeyLabel").attr("value").get)
  }

  final def main(): Unit = jQuery { () =>
    // this needs to be done in order for the form submit to work
    global.turkSetAssignmentID()
    // dispatch to specific task
    taskMapping.get(taskKey) match {
      case None => System.err.println(s"Invalid task key: $taskKey")
      case Some(func) => func()
    }
  }
} 
开发者ID:julianmichael,项目名称:turkey,代码行数:31,代码来源:TaskDispatcher.scala


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