scala.js

using scala.js method as callback

依然范特西╮ 提交于 2019-12-12 17:41:51
问题 I am loading google map in async way , @JSExport("sample") object Sample { def loadScript = { val script = document.createElement("script").asInstanceOf[HTMLScriptElement] script.`type` = "text/javascript" //case 1 script.src = "https://maps.googleapis.com/maps/api/js?v=3.exp&callback=sample().initialize" // case 2 script.src = "https://maps.googleapis.com/maps/api/js?v=3.exp&callback=sample.initialize" document.body.appendChild(script) } @JSExport def initialize() :Unit = { println(" map

Is there a way to use Play routing in scala js files?

天涯浪子 提交于 2019-12-12 16:32:41
问题 I use Play! Scala 2.4 with scala js, and I would like to know if there is a way to get the routing config file from the scala js files. It would be very convenient since it would allow me to replace urls as string by something like application.routes.Application.admin() . Do you know any workaround to do this? 回答1: You can use javascript reverse routing. It will help you to define routes from your js code. It will look like this: @helper.javascriptRouter("jsRoutes")( routes.javascript

How to export properties of shared case classes

眉间皱痕 提交于 2019-12-12 08:32:59
问题 I am trying to share a case class between server and client. I am using upickle on both ends. The objects and their data are nicely available on both ends. shared class case class Foo(var id : Long,var title: Description) However i need to export the fields of the case class on the client side. I could add the @ExportAll annotation, but that means pulling in the scalajs libraries on the server project. Is there perhaps a better way of exposing the members id and title to the javascript. tx.,

Is it possilble to a create type-safe library in ScalaJS for using from JavaScript?

北慕城南 提交于 2019-12-12 05:43:36
问题 If so how? In my last question I asked why this snippet is crashing: @JSExport("Test") object TestScalaJs { @JSExport def callMe[A: ClassTag](f: js.Function1[Int, A]): Array[A] = Array(f(4)) } on: var res = Test().callMe(function(x) {return x + 'x';}); console.log('TestScalaJs:', res.join(', ')); with: $c_jl_Throwable.fillInStackTrace__jl_Throwable @ VM153:4161 $c_sjsr_UndefinedBehaviorError.fillInStackTrace__jl_Throwable @ VM153:9241 $c_jl_Throwable.init___T__jl_Throwable @ VM153:4177 $c

Scala-js - Navigator.oscpu

给你一囗甜甜゛ 提交于 2019-12-12 05:28:14
问题 Can you advice me how to get Navigator.oscpu using Scala-js? Mapping to native Navigator does not seems to have the oscpu. https://developer.mozilla.org/en-US/docs/Web/API/Navigator/oscpu 回答1: This appears to be a Firefox-only feature (based on a quick look around), so it's not supported by Scala.js out of the box. You'll need to add it yourself, by adding a side-facade to Navigator. This isn't terribly hard -- see the definition of BeaconNavigator for an example of how to do this. So you

Access the JS this from scala.js

蓝咒 提交于 2019-12-12 05:12:59
问题 I need to implement a call from scala.js a method like: sigma.classes.graph.addMethod('getNodesCount', function() { return this.nodesArray.length; }); that is the way that bring the library in JS to access the internal array nodesArray of the class sigma.clasess.graph. I tried something like trait GraphClassesJS extends js.Object { def addMethod(name:String,handler: js.Function0[Any]):Unit=js.native } I try to call with s.classes.graph.addMethod("getNodesCount",()=>js.ThisFunction.nodesArray

Call jquery .each method from scala.js

冷暖自知 提交于 2019-12-12 02:46:26
问题 Is this doc out-dated? http://www.scala-js.org/doc/calling-javascript.html Can't seem to get this right in intellij: import org.scalajs.dom.html import org.scalajs.dom import org.scalajs.dom.raw.HTMLElement import scala.scalajs.js import js.JSConverters._ import fr.iscpif.scaladget.d3._ import fr.iscpif.scaladget.mapping._ import scala.scalajs.js import scala.scalajs.js.annotation.JSExport import org.scalajs.jquery.jQuery /** * Created by IDEA on 31/10/15. */ @JSExport object LearnD3 {

How to convert Map to Json object in Scala.js?

不打扰是莪最后的温柔 提交于 2019-12-12 01:58:09
问题 I'm trying to write a facade for C3.js line chart. The Javascript code I'm trying to generate is var chart = c3.generate({ data: { json: { "data1": [49.1, 20, 50, 40, 60, 50], "data2": [200.3, 130, 90, 240, 130, 220], "data3": [300.88, 200, 160, 400, 250, 250] } } }); This is how I'm invoking the facade I've written C3Chart.generate(scope.props.data) The problem is that I'm not able to convert the apply method in C3MyChartDataset class to return a json object to emit this object json: {

How to import UglifyJS from Scala.js?

陌路散爱 提交于 2019-12-12 01:39:20
问题 I can use jQuery from Scala.js quite well: jsDependencies += "org.webjars" % "jquery" % "2.2.1" / "jquery.js" minified "jquery.min.js" Now I would like to use UglifyJS and its webjar structure seems a bit different. There seems to be no minified js file, and even the main file which probably contains the complete library looks different, it has no .js extension and it starts with following lines: #! /usr/bin/env node // -*- js -*- "use strict"; var UglifyJS = require("../tools/node"); Can

How to translate a JQuery function value in Javascript to ScalaJS (scalajs-jquery)

柔情痞子 提交于 2019-12-11 13:45:13
问题 In my ScalaJS project I use Semantic-UI with scala-js-jquery I use this to monkey patch JQuery: // Monkey patching JQuery @js.native trait SemanticJQuery extends JQuery { def dropdown(params: js.Any*): SemanticJQuery = js.native def popup(params: js.Any*): SemanticJQuery = js.native // and more } // Monkey patching JQuery with implicit conversion implicit def jq2semantic(jq: JQuery): SemanticJQuery = jq.asInstanceOf[SemanticJQuery] For example $('select.dropdown').dropdown(); translates to