scala.scalajs.js.annotation.JSGlobal Scala Examples

The following examples show how to use scala.scalajs.js.annotation.JSGlobal. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.
Example 1
Source File: Management.scala    From scala-js-chrome   with MIT License 5 votes vote down vote up
package chrome.management.bindings

import chrome.events.bindings.Event
import chrome.management.bindings.ExtensionInfo.LaunchType
import chrome.runtime.bindings.Runtime.AppID

import scala.scalajs.js
import scala.scalajs.js.annotation.JSGlobal

@js.native
@JSGlobal("chrome.management")
object Management extends js.Object {

  val onInstalled: Event[js.Function1[ExtensionInfo, _]] = js.native
  val onUninstalled: Event[js.Function1[String, _]] = js.native
  val onEnabled: Event[js.Function1[ExtensionInfo, _]] = js.native
  val onDisabled: Event[js.Function1[ExtensionInfo, _]] = js.native

  def getAll(callback: js.Function1[js.Array[ExtensionInfo], _]): Unit =
    js.native

  def get(id: AppID, callback: js.Function1[ExtensionInfo, _]): Unit =
    js.native

  def getSelf(callback: js.Function1[ExtensionInfo, _]): Unit = js.native

  def getPermissionWarningsById(
      id: AppID,
      callback: js.Function1[js.Array[String], _]): Unit = js.native

  def getPermissionWarningsByManifest(
      manifestStr: String,
      callback: js.Function1[js.Array[String], _]): Unit = js.native

  def setEnabled(id: AppID,
                 enabled: Boolean,
                 callback: js.UndefOr[js.Function0[_]] = js.undefined): Unit =
    js.native

  def uninstall(id: AppID,
                options: js.UndefOr[js.Object] = js.undefined,
                callback: js.UndefOr[js.Function0[_]] = js.undefined): Unit =
    js.native

  def uninstallSelf(
      options: js.UndefOr[js.Object] = js.undefined,
      callback: js.UndefOr[js.Function0[_]] = js.undefined): Unit = js.native

  def launchApp(id: AppID,
                callback: js.UndefOr[js.Function0[_]] = js.undefined): Unit =
    js.native

  def createAppShortcut(
      id: AppID,
      callback: js.UndefOr[js.Function0[_]] = js.undefined): Unit = js.native

  def setLaunchType(
      id: AppID,
      launchType: LaunchType,
      callback: js.UndefOr[js.Function0[_]] = js.undefined): Unit = js.native

  def generateAppForLink(url: String,
                         title: String,
                         callback: js.UndefOr[js.Function1[ExtensionInfo, _]] =
                           js.undefined): Unit = js.native

} 
Example 2
Source File: IncomingMessage.scala    From RosHTTP   with MIT License 5 votes vote down vote up
package fr.hmil.roshttp.node.http

import fr.hmil.roshttp.node.events.EventEmitter

import scala.scalajs.js
import scala.scalajs.js.annotation.JSGlobal

@js.native
@JSGlobal
private[roshttp] class IncomingMessage extends EventEmitter {
  val headers: js.Dictionary[String] = js.native
  val httpVersion: String = js.native
  val method: String = js.native
  val rawHeaders: js.Dictionary[String] = js.native
  val rawTrailers: js.Dictionary[String] = js.native
  def setTimeout(msecs: Int, callback: js.Function): IncomingMessage = js.native
  val statusCode: Int = js.native
  val statusMessage: String = js.native
  // message.socket -- not facaded here
  val trailers: js.Dictionary[String] = js.native
  val url: String = js.native

  def pause(): Unit = js.native
  def resume(): Unit = js.native
} 
Example 3
Source File: PakoSuite.scala    From metabrowse   with Apache License 2.0 5 votes vote down vote up
package metabrowse

import metabrowse.schema.Workspace
import org.scalatest.FunSuite
import scala.meta.internal.io.PathIO
import scala.scalajs.js
import scala.scalajs.js.annotation.JSGlobal
import scala.scalajs.js.annotation.JSImport
import scala.scalajs.js.typedarray.ArrayBuffer
import scala.scalajs.js.typedarray.TypedArrayBuffer
import scala.scalajs.js.typedarray.Uint8Array

class PakoSuite extends FunSuite {
  test("deflate") {
    val path = PathIO.workingDirectory
      .resolve("target")
      .resolve("metabrowse")
      .resolve("index.workspace.gz")
    val in = path.readAllBytes
    val input = new ArrayBuffer(in.length)
    val bbuf = TypedArrayBuffer.wrap(input)
    bbuf.put(in)
    val output = Pako.inflate(input)
    val out = Array.ofDim[Byte](output.byteLength)
    TypedArrayBuffer.wrap(output).get(out)
    val workspace = Workspace.parseFrom(out)
    val obtained =
      workspace.toProtoString.linesIterator.toList.sorted.mkString("\n").trim
    val expected =
      """
        |filenames: "paiges/core/src/main/scala/org/typelevel/paiges/Chunk.scala"
        |filenames: "paiges/core/src/main/scala/org/typelevel/paiges/Doc.scala"
        |filenames: "paiges/core/src/main/scala/org/typelevel/paiges/Document.scala"
        |filenames: "paiges/core/src/main/scala/org/typelevel/paiges/package.scala"
        |filenames: "paiges/core/src/test/scala/org/typelevel/paiges/DocumentTests.scala"
        |filenames: "paiges/core/src/test/scala/org/typelevel/paiges/Generators.scala"
        |filenames: "paiges/core/src/test/scala/org/typelevel/paiges/JsonTest.scala"
        |filenames: "paiges/core/src/test/scala/org/typelevel/paiges/PaigesTest.scala"
      """.stripMargin.trim
    assert(obtained == expected)
  }
} 
Example 4
Source File: Utils.scala    From scalafiddle-editor   with Apache License 2.0 5 votes vote down vote up
package scalafiddle.client

import org.scalajs.dom

import scala.language.implicitConversions
import scala.scalajs.js
import scala.scalajs.js.JSConverters._
import scala.scalajs.js.annotation.JSGlobal
import scala.scalajs.js.typedarray.Uint8Array
import scala.scalajs.js.|

class JsVal(val value: js.Dynamic) {
  def get(name: String): Option[JsVal] = {
    (value.selectDynamic(name): Any) match {
      case () => None
      case v  => Some(JsVal(v.asInstanceOf[js.Dynamic]))
    }
  }

  def apply(name: String): JsVal = get(name).get
  def apply(index: Int): JsVal   = value.asInstanceOf[js.Array[JsVal]](index)

  def keys: Seq[String]  = js.Object.keys(value.asInstanceOf[js.Object]).toSeq.map(x => x: String)
  def values: Seq[JsVal] = keys.map(x => JsVal(value.selectDynamic(x)))

  def isDefined: Boolean = !js.isUndefined(value)
  def isNull: Boolean    = value eq null

  def asDouble: Double   = value.asInstanceOf[Double]
  def asBoolean: Boolean = value.asInstanceOf[Boolean]
  def asString: String   = value.asInstanceOf[String]

  override def toString: String = js.JSON.stringify(value)
}

object JsVal {
  implicit def jsVal2jsAny(v: JsVal): js.Any = v.value

  implicit def jsVal2String(v: JsVal): js.Any = v.toString

  def parse(value: String) = new JsVal(js.JSON.parse(value))

  def apply(value: js.Any) = new JsVal(value.asInstanceOf[js.Dynamic])

  def obj(keyValues: (String, js.Any)*) = {
    val obj = new js.Object().asInstanceOf[js.Dynamic]
    for ((k, v) <- keyValues) {
      obj.updateDynamic(k)(v.asInstanceOf[js.Any])
    }
    new JsVal(obj)
  }

  def arr(values: js.Any*) = {
    new JsVal(values.toJSArray.asInstanceOf[js.Dynamic])
  }
}

@JSGlobal("Zlib.Gzip")
@js.native
class Gzip(data: js.Array[Byte]) extends js.Object {
  def compress(): Uint8Array = js.native
}

@JSGlobal("Zlib.Gunzip")
@js.native
class Gunzip(data: js.Array[Byte]) extends js.Object {
  def decompress(): Uint8Array = js.native
}

@JSGlobal("sha1")
@js.native
object SHA1 extends js.Object {
  def apply(s: String): String = js.native
}

@js.native
@JSGlobal("ScalaFiddleConfig")
object ScalaFiddleConfig extends js.Object {
  val compilerURL: String               = js.native
  val helpURL: String                   = js.native
  val scalaVersions: js.Array[String]   = js.native
  val scalaJSVersions: js.Array[String] = js.native
}

@js.native
@JSGlobal
object Mousetrap extends js.Object {
  def bind(key: String | js.Array[String], f: js.Function1[dom.KeyboardEvent, Boolean], event: String = js.native): Unit =
    js.native

  def bindGlobal(
      key: String | js.Array[String],
      f: js.Function1[dom.KeyboardEvent, Boolean],
      event: String = js.native
  ): Unit = js.native

  def unbind(key: String): Unit = js.native

  def reset(): Unit = js.native
} 
Example 5
Source File: JQuery.scala    From scalafiddle-editor   with Apache License 2.0 5 votes vote down vote up
package scalafiddle.client.component

import org.scalajs.dom._

import scala.scalajs.js
import scala.scalajs.js.annotation.JSGlobal


@js.native
trait JQueryEventObject extends Event {
  var data: js.Any = js.native
}

@js.native
@JSGlobal("jQuery")
object JQueryStatic extends js.Object {
  def apply(selector: js.Any): JQuery = js.native
}

@js.native
trait JQuery extends js.Object {} 
Example 6
Source File: AbortController.scala    From sttp   with Apache License 2.0 5 votes vote down vote up
package sttp.client.dom.experimental

import scala.scalajs.js
import scala.scalajs.js.annotation.JSGlobal

// remove when https://github.com/scala-js/scala-js-dom/pull/328 is merged and released
// also remove `requestInitDynamic` from AbstractFetchBackend

@js.native
@JSGlobal
class AbortController() extends js.Object {
  val signal: AbortSignal = js.native

  def abort(): Unit = js.native
}

@js.native
trait AbortSignal extends js.Object 
Example 7
Source File: File.scala    From sttp   with Apache License 2.0 5 votes vote down vote up
package sttp.client.dom.experimental

import org.scalajs.dom.raw.Blob

import scala.scalajs.js
import scala.scalajs.js.annotation.JSGlobal

// the File interface in scala.js does not match the spec
// https://developer.mozilla.org/en-US/docs/Web/API/File

@js.native
@JSGlobal
class File(
    parts: js.Array[js.Any] = js.native,
    val name: String = js.native,
    options: FilePropertyBag = js.native
) extends Blob {
  val lastModified: Int = js.native
}

@js.native
@JSGlobal
object File extends js.Object

@js.native
trait FilePropertyBag extends js.Object {
  def `type`: String = js.native

  def lastModified: Int = js.native
}

object FilePropertyBag {
  @inline
  def apply(
      `type`: js.UndefOr[String] = js.undefined,
      lastModified: js.UndefOr[Int] = js.undefined
  ): FilePropertyBag = {
    val result = js.Dynamic.literal()
    `type`.foreach(result.`type` = _)
    lastModified.foreach(result.lastModified = _)
    result.asInstanceOf[FilePropertyBag]
  }
} 
Example 8
Source File: BooApp.scala    From boopickle   with Apache License 2.0 5 votes vote down vote up
package boopickle.perftests

import boopickle.BufferPool
import org.scalajs.dom
import org.scalajs.dom.html

import scala.scalajs.js
import scala.scalajs.js.annotation.{JSExport, JSExportTopLevel, JSGlobal, JSName}
import scala.scalajs.js.typedarray.Uint8Array
import scalatags.JsDom.all._

@JSGlobal("Zlib.Gzip")
@js.native
class Gzip(data: js.Array[Byte]) extends js.Object {
  def compress(): Uint8Array = js.native
}

@JSExportTopLevel("BooApp")
object BooApp {

  import scala.scalajs.js.JSConverters._

  def runTests(resultsDiv: html.Div) = {
    val resView = pre.render
    resultsDiv.innerHTML = ""
    resultsDiv.appendChild(div(cls := "bold", s"Running ${Tests.suites.size} tests").render)
    resultsDiv.appendChild(resView)
    def runNext(suites: Seq[PerfTestSuite]): Unit = {
      val suite  = suites.head
      val header = s"${1 + Tests.suites.size - suites.size}/${Tests.suites.size} : ${suite.name}"
      resView.innerHTML = resView.innerHTML + header + "\n"
      resView.innerHTML = resView.innerHTML + "=" * header.length + "\n"
      resView.innerHTML = resView.innerHTML + f"${"Library"}%-10s ${"ops/s"}%-10s ${"%"}%-10s ${"size"}%-10s ${"%"}%-10s ${"size.gz"}%-10s ${"%"}%-10s" + "\n"
      val tester = new PerfTester(suite)
      val res    = tester.runSuite
      // zip result data to see how small it gets
      val resSizes = res.results.map { r =>
        val rawSize = r.data.length
        val gz      = new Gzip(r.data.toJSArray)
        (r, rawSize, gz.compress().length)
      }
      val maxCount  = resSizes.map(_._1.count).max
      val minSize   = resSizes.map(_._2).min
      val minGZSize = resSizes.map(_._3).min
      resSizes.foreach { r =>
        resView.innerHTML = resView.innerHTML + f"${r._1.name}%-10s ${r._1.count}%-10d ${f"${r._1.count * 100.0 / maxCount}%.1f%%"}%-10s ${r._2}%-10d ${f"${r._2 * 100.0 / minSize}%.0f%%"}%-10s ${r._3}%-10d ${f"${r._3 * 100.0 / minGZSize}%.0f%%"}%-10s" + "\n"
      }
      resView.innerHTML = resView.innerHTML + "\n"
      if (suites.tail.nonEmpty)
        dom.window.setTimeout(() => runNext(suites.tail), 100)
      else {
        resultsDiv.appendChild(h4("Completed!").render)
      }
      // print out buffer pool usage
      println(s"""BufferPool:
            |  allocations = ${BufferPool.allocOk}
            |  misses      = ${BufferPool.allocMiss}
            """.stripMargin)
      ()
    }
    dom.window.setTimeout(() => runNext(Tests.suites), 10)
  }

  @JSExport
  def main(): Unit = {
    val contentRoot = dom.document.getElementById("contentRoot")
    val runButton   = button(cls := "waves-effect waves-light btn", i(cls := "mdi-av-play-arrow right"), "Run tests").render
    val results     = div(cls := "row").render
    runButton.onclick = (e: dom.Event) => runTests(results)

    contentRoot.appendChild(div(cls := "row", runButton).render)
    contentRoot.appendChild(results)
    ()
  }
} 
Example 9
Source File: WebRequest.scala    From scala-js-chrome   with MIT License 5 votes vote down vote up
package chrome.webRequest.bindings

import scala.scalajs.js
import scala.scalajs.js.annotation.JSGlobal

@js.native
@JSGlobal("chrome.webRequest")
object WebRequest extends js.Object {

  // (R <: ResourceRequest) => Unit
  type Callback[R <: ResourceRequest] = js.Function1[R, Unit]
  // (R <: ResourceRequest) => ?BlockingResponse
  type BlockableCallback[R <: ResourceRequest] = js.Function1[R, js.UndefOr[BlockingResponse]]
  // (R <: ResourceRequest, ?(BlockingResponse) => _) => ?BlockingResponse
  type BlockableAuthCallback[R <: ResourceRequest] = js.Function2[R,
    js.UndefOr[js.Function1[BlockingResponse, _]], js.UndefOr[BlockingResponse]]

  
  var onErrorOccurred: WebRequestEvent[Callback[WebResponseErrorDetails]] = js.native
} 
Example 10
Source File: Processes.scala    From scala-js-chrome   with MIT License 5 votes vote down vote up
package chrome.processes.bindings

import chrome.events.bindings.Event
import chrome.tabs.bindings.Tab

import scala.scalajs.js
import scala.scalajs.js.annotation.JSGlobal

@js.native
@JSGlobal("chrome.processes")
object Processes extends js.Object {

  val onUpdated: Event[js.Function1[Map[Process.Id, Process], _]] = js.native
  val onUpdatedWithMemory: Event[js.Function1[Map[Process.Id, Process], _]] =
    js.native
  val onCreated: Event[js.Function1[Process, _]] = js.native
  val onUnresponsive: Event[js.Function1[Process, _]] = js.native
  val onExited: Event[
      js.Function3[Process.Id, Process.ExitType, js.UndefOr[Int], _]] =
    js.native

  def terminate(
      processId: Process.Id,
      callback: js.UndefOr[js.Function1[Boolean, _]] = js.undefined): Unit =
    js.native
  def getProcessIdForTab(tabId: Tab.Id,
                         callback: js.Function1[Process.Id, _]): Unit =
    js.native
  def getProcessInfo(
      processIds: js.Array[Process.Id],
      includeMemory: Boolean,
      callback: js.Function1[Map[Process.Id, Process], _]): Unit = js.native

} 
Example 11
Source File: Storage.scala    From scala-js-chrome   with MIT License 5 votes vote down vote up
package chrome.storage.bindings

import chrome.events.bindings.Event

import scala.scalajs.js
import scala.scalajs.js.annotation.JSGlobal

@js.native
trait StorageChange extends js.Object {

  val oldValue: js.UndefOr[js.Any] = js.native
  val newValue: js.UndefOr[js.Any] = js.native

}

@js.native
trait StorageArea extends js.Object {

  def get(keys: js.UndefOr[js.Any] = js.undefined,
          callback: js.Function1[js.Dictionary[js.Any], _]): Unit = js.native
  def getBytesInUse(keys: js.UndefOr[js.Any] = js.undefined,
                    callback: js.Function1[Int, _]): Unit = js.native
  def set(items: js.Dictionary[js.Any],
          callback: js.UndefOr[js.Function0[_]] = js.undefined): Unit =
    js.native
  def remove(keys: js.Any,
             callback: js.UndefOr[js.Function0[_]] = js.undefined): Unit =
    js.native
  def clear(callback: js.UndefOr[js.Function0[_]] = js.undefined): Unit =
    js.native

}

@js.native
@JSGlobal("chrome.storage")
object Storage extends js.Object {

  val onChanged: Event[js.Function2[Map[String, StorageChange], String, _]] =
    js.native

  val sync: StorageArea = js.native
  val local: StorageArea = js.native
  val managed: StorageArea = js.native

} 
Example 12
Source File: TCP.scala    From scala-js-chrome   with MIT License 5 votes vote down vote up
package chrome.sockets.tcp.bindings

import chrome.events.bindings.Event

import scala.scalajs.js
import scala.scalajs.js.annotation.JSGlobal
import scala.scalajs.js.typedarray.ArrayBuffer
import scala.scalajs.js.{UndefOr, native, undefined}

@js.native
@JSGlobal("chrome.sockets.tcp")
object TCP extends js.Object {

  val onReceive: Event[js.Function1[ReceiveEvent, _]] = native
  val onReceiveError: Event[js.Function1[ReceiveErrorEvent, _]] = native

  def create(properties: UndefOr[SocketProperties] = undefined,
             callback: js.Function1[CreateInfo, _]): Unit = native

  def update(socketId: SocketId,
             properties: SocketProperties,
             callback: UndefOr[js.Function0[_]] = undefined): Unit = native

  def setPaused(socketId: SocketId,
                paused: Boolean,
                callback: UndefOr[js.Function0[_]] = undefined): Unit = native

  def setKeepAlive(socketId: SocketId,
                   enable: Boolean,
                   delay: UndefOr[Int] = undefined,
                   callback: js.Function1[Int, _]): Unit = native

  def setNoDelay(socketId: SocketId,
                 noDelay: Boolean,
                 callback: js.Function1[Int, _]): Unit = native

  def connect(socketId: SocketId,
              peerAddress: String,
              peerPort: Int,
              callback: js.Function1[Int, _]): Unit = native

  def disconnect(socketId: SocketId,
                 callback: UndefOr[js.Function0[_]] = undefined): Unit = native

  def secure(socketId: SocketId,
             options: UndefOr[SecureOptions] = undefined,
             callback: js.Function0[_]): Unit = native

  def send(socketId: SocketId,
           data: ArrayBuffer,
           callback: js.Function1[SendInfo, _]): Unit = native

  def close(socketId: SocketId, callback: js.Function0[_]): Unit = native

  def getInfo(socketId: SocketId,
              callback: js.Function1[SocketInfo, _]): Unit = native

  def getSockets(callback: js.Function1[js.Array[SocketInfo], _]): Unit =
    native

} 
Example 13
Source File: TCPServer.scala    From scala-js-chrome   with MIT License 5 votes vote down vote up
package chrome.sockets.tcpServer.bindings

import chrome.events.bindings.Event

import scala.scalajs.js
import scala.scalajs.js.annotation.JSGlobal
import scala.scalajs.js.{UndefOr, native, undefined}

@js.native
@JSGlobal("chrome.sockets.tcpServer")
object TCPServer extends js.Object {

  val onAccept: Event[js.Function1[AcceptEvent, _]] = native
  val onAcceptError: Event[js.Function1[AcceptErrorEvent, _]] = native

  def create(properties: UndefOr[SocketProperties] = undefined,
             callback: js.Function1[CreateInfo, _]): Unit = native

  def update(socketId: SocketId,
             properties: SocketProperties,
             callback: UndefOr[js.Function0[_]] = undefined): Unit = native

  def setPaused(socketId: SocketId,
                paused: Boolean,
                callback: UndefOr[js.Function0[_]] = undefined): Unit = native

  def listen(socketId: SocketId,
             address: String,
             port: Int,
             backlog: UndefOr[Int] = undefined,
             callback: js.Function1[Int, _]): Unit = native

  def disconnect(socketId: SocketId,
                 callback: UndefOr[js.Function0[_]] = undefined): Unit = native

  def close(socketId: SocketId,
            callback: UndefOr[js.Function0[_]] = undefined): Unit = native

  def getInfo(socketId: SocketId,
              callback: js.Function1[SocketInfo, _]): Unit = native

  def getSockets(callback: js.Function1[js.Array[SocketInfo], _]): Unit =
    native

} 
Example 14
Source File: Elliptic.scala    From iotchain   with MIT License 5 votes vote down vote up
package jbok.crypto.facade

import scala.scalajs.js
import scala.scalajs.js.annotation.{JSGlobal, JSImport}
import scala.scalajs.js.typedarray.Uint8Array

@js.native
@JSImport("elliptic", "ec")
class EC(curve: String) extends js.Object {
  def genKeyPair(options: Option[js.Dynamic] = None): KeyPairEC = js.native
  def keyPair(options: js.Dynamic): KeyPairEC                   = js.native
  def keyFromPublic(pub: String, enc: String): KeyPairEC        = js.native
  def keyFromPrivate(priv: String, enc: String): KeyPairEC      = js.native

  def sign(msg: Uint8Array, key: KeyPairEC): SignatureEC                = js.native
  def verify(msg: Uint8Array, sig: js.Dynamic, key: KeyPairEC): Boolean = js.native

  def getKeyRecoveryParam(msg: Uint8Array, signature: js.Dynamic): Int           = js.native
  def recoverPubKey(msg: Uint8Array, signature: js.Dynamic, recId: Int): ECPoint = js.native
}

@js.native
@JSImport("elliptic/ec/key", JSImport.Default)
class KeyPairEC(ec: EC, options: js.Dynamic) extends js.Object {
  def getPublic(compact: Boolean, enc: String): String = js.native
  def getPrivate(enc: String): String                  = js.native
//  val priv: js.Any                                     = js.native
//  val pub: js.Any                                      = js.native
}

@js.native
@JSImport("elliptic/ec/signature", JSImport.Default)
class SignatureEC() extends js.Object {
  def r: Any             = js.native
  def s: Any             = js.native
  def recoveryParam: Int = js.native
}

object SignatureEC {
  def apply(r: BN, s: BN, recoveryParam: Int): js.Dynamic =
    js.Dynamic.literal(r = r, s = s, recoveryParam = recoveryParam)
}

@js.native
@JSGlobal
class ECPoint() extends js.Object {
  def encode(enc: String, compact: Boolean): String = js.native
} 
Example 15
Source File: Omnibox.scala    From scala-js-chrome   with MIT License 5 votes vote down vote up
package chrome.omnibox.bindings

import chrome.events.bindings.Event

import scala.scalajs.js
import scala.scalajs.js.annotation.JSGlobal

@js.native
@JSGlobal("chrome.omnibox")
object Omnibox extends js.Object {

  val onInputStarted: Event[js.Function0[_]] = js.native
  val onInputChanged: Event[
      js.Function2[String, js.Function1[js.Array[SuggestResult], _], _]] =
    js.native
  val onInputEntered: Event[js.Function2[String, OnInputEnteredDisposition, _]] =
    js.native
  val onInputCancelled: Event[js.Function0[_]] = js.native

  def setDefaultSuggestion(suggestion: DefaultSuggestion): Unit = js.native

} 
Example 16
Source File: ContextMenus.scala    From scala-js-chrome   with MIT License 5 votes vote down vote up
package chrome.contextMenus.bindings

import chrome.events.bindings.Event
import chrome.tabs.bindings.Tab

import scala.scalajs.js
import scala.scalajs.js.annotation.JSGlobal
import scala.scalajs.js.|

object MenuContexts {
  val ALL = "all"
  val PAGE = "page"
  val FRAME = "frame"
  val SELECTION = "selection"
  val LINKE = "link"
  val EDITABLE = "editable"
  val IMAGE = "image"
  val VIDEO = "video"
  val AUDIO = "audio"
  val LAUNCHER = "launcher"
  val BROWSER_ACTION = "browser_action"
  val PAGE_ACTION = "page_action"
}

object MenuType {
  val NORMAL = "normal"
  val CHECKBOX = "checkbox"
  val RADIO = "radio"
  val SEPARATOR = "separator"
}

@js.native
@JSGlobal("chrome.contextMenus")
object ContextMenus extends js.Object {

  def create(createProperties: CreateProperties): String | Int = js.native

  def update(id: String | Int, properties: UpdateProperties): Unit = js.native

  def remove(menuItemId: String | Int,
             callback: js.Function0[Unit]): String | Int = js.native

  def removeAll(callback: js.Function0[Unit]): Unit = js.native

  val onClicked: Event[js.Function2[MenuInfo, Tab, _]] = js.native

}

class UpdateProperties(
    val `type`: String = MenuType.NORMAL,
    val title: String,
    val checked: js.UndefOr[Boolean] = js.undefined,
    val contexts: js.UndefOr[js.Array[String]] = js.undefined,
    val onclick: js.UndefOr[js.Function2[MenuInfo, Tab, Unit]],
    val parentId: js.UndefOr[String | Int] = js.undefined,
    val documentUrlPatterns: js.UndefOr[js.Array[String]] = js.undefined,
    val targetUrlPatterns: js.UndefOr[js.Array[String]] = js.undefined,
    val enabled: Boolean = true
) extends js.Object

object CreateProperties {

  def apply(id: String,
            title: String,
            contexts: js.Array[String] = js.Array(MenuContexts.ALL))
    : CreateProperties =
    new CreateProperties(id = id, title = title, contexts = contexts)
}

class CreateProperties(
    val `type`: String = MenuType.NORMAL,
    val id: String | Int,
    val title: String,
    val checked: js.UndefOr[Boolean] = js.undefined,
    val contexts: js.UndefOr[js.Array[String]] = js.undefined,
    val onclick: js.UndefOr[js.Function2[MenuInfo, Tab, Unit]] = js.undefined,
    val parentId: js.UndefOr[String | Int] = js.undefined,
    val documentUrlPatterns: js.UndefOr[js.Array[String]] = js.undefined,
    val targetUrlPatterns: js.UndefOr[js.Array[String]] = js.undefined,
    val enabled: Boolean = true
) extends js.Object

@js.native
trait MenuInfo extends js.Object {
  val menuItemId: String | Int = js.native
  val parentMenuItemId: js.UndefOr[String | Int]
  val mediaType: js.UndefOr[String]
  val linkUrl: js.UndefOr[String]
  val srcUrl: js.UndefOr[String]
  val pageUrl: js.UndefOr[String]
  val frameUrl: js.UndefOr[String]
  val selectionText: js.UndefOr[String]
  val editable: Boolean
  val wasChecked: js.UndefOr[Boolean]
  val checked: js.UndefOr[Boolean]
} 
Example 17
Source File: Wallpaper.scala    From scala-js-chrome   with MIT License 5 votes vote down vote up
package chrome.wallpaper.bindings

import scala.scalajs.js
import scala.scalajs.js.annotation.JSGlobal

@js.native
trait WallpaperDetails extends js.Object {
  val binary: js.UndefOr[js.Any] = js.native
  val url: js.UndefOr[String] = js.native
  val layout: WallpaperLayout = js.native
  val filename: String = js.native
  val thumbnail: js.UndefOr[Boolean] = js.native
}

object WallpaperDetails {
  def apply(
      filename: String,
      layout: WallpaperLayout,
      binary: js.UndefOr[js.Any] = js.undefined,
      url: js.UndefOr[String] = js.undefined,
      thumbnail: js.UndefOr[Boolean] = js.undefined): WallpaperDetails = {
    js.Dynamic
      .literal(
          filename = filename,
          layout = layout,
          binary = binary,
          url = url,
          thumbnail = thumbnail
      )
      .asInstanceOf[WallpaperDetails]
  }
}

@js.native
@JSGlobal("chrome.wallpaper")
object Wallpaper extends js.Object {

  def setWallpaper(details: WallpaperDetails,
                   callback: js.Function1[js.UndefOr[js.Any], _]): Unit =
    js.native

} 
Example 18
Source File: Permissions.scala    From scala-js-chrome   with MIT License 5 votes vote down vote up
package chrome.permissions.bindings

import chrome.events.bindings.Event

import scala.scalajs.js
import scala.scalajs.js.annotation.JSGlobal
import scala.scalajs.js.{UndefOr, native, undefined}

@js.native
@JSGlobal("chrome.permissions")
object Permissions extends js.Object {

  val onAdded: Event[js.Function1[PermissionList, _]] = native
  val onRemoved: Event[js.Function1[PermissionList, _]] = native

  def getAll(callback: js.Function1[PermissionList, _]): Unit = native

  def contains(permissions: PermissionList,
               callback: js.Function1[Boolean, _]): Unit = native

  def request(permissions: PermissionList,
              callback: UndefOr[js.Function1[Boolean, _]] = undefined): Unit =
    native

  def remove(permissions: PermissionList,
             callback: UndefOr[js.Function1[Boolean, _]] = undefined): Unit =
    native

}

@js.native
trait PermissionList extends js.Object {

  var permissions: UndefOr[js.Array[String]] = native
  var origins: UndefOr[js.Array[String]] = native

}

object PermissionList {

  def apply(permissions: UndefOr[js.Array[String]] = undefined,
            origins: UndefOr[js.Array[String]] = undefined): PermissionList = {
    js.Dynamic
      .literal(
          permissions = permissions,
          origins = origins
      )
      .asInstanceOf[PermissionList]
  }

} 
Example 19
Source File: Downloads.scala    From scala-js-chrome   with MIT License 5 votes vote down vote up
package chrome.downloads.bindings

import chrome.events.bindings.Event

import scala.scalajs.js
import scala.scalajs.js.annotation.JSGlobal

@js.native
@JSGlobal("chrome.downloads")
object Downloads extends js.Object {

  type Suggest = Option[Suggestion] => Unit

  val onCreated: Event[js.Function1[DownloadItem, _]] = js.native
  val onErased: Event[js.Function1[DownloadItem.Id, _]] = js.native
  val onChanged: Event[js.Function1[DownloadDelta, _]] = js.native
  val onDeterminingFilename: Event[js.Function2[DownloadItem, Suggest, _]] = js.native

  def download(options: DownloadOptions, callback: js.UndefOr[js.Function1[DownloadItem.Id, _]] = js.native): Unit = js.native

  def pause(id: DownloadItem.Id, callback: js.UndefOr[js.Function0[_]] = js.native): Unit = js.native
  def resume(id: DownloadItem.Id, callback: js.UndefOr[js.Function0[_]] = js.native): Unit = js.native
  def cancel(id: DownloadItem.Id, callback: js.UndefOr[js.Function0[_]] = js.native): Unit = js.native
  def getFileIcon(
       id: DownloadItem.Id,
       options: js.UndefOr[FileIconOptions] = js.native,
       callback: js.UndefOr[js.Function1[js.UndefOr[String], _]]
  ): Unit = js.native
  def open(id: DownloadItem.Id): Unit = js.native
  def show(id: DownloadItem.Id): Unit = js.native
  def showDefaultFolder(): Unit = js.native

  def erase(query: Query, callback: js.UndefOr[js.Function1[js.Array[DownloadItem.Id], _]] = js.native): Unit = js.native
  def search(query: Query, callback: js.Function1[js.Array[DownloadItem], _]): Unit = js.native

  def removeFile(id: DownloadItem.Id, callback: js.UndefOr[js.Function0[_]] = js.native): Unit = js.native
  def acceptDanger(id: DownloadItem.Id, callback: js.UndefOr[js.Function0[_]] = js.native): Unit = js.native
  def drag(id: DownloadItem.Id): Unit = js.native
  def setShelfEnabled(enabled: Boolean): Unit = js.native

} 
Example 20
Source File: Notifications.scala    From scala-js-chrome   with MIT License 5 votes vote down vote up
package chrome.notifications.bindings

import chrome.events.bindings.Event

import scala.scalajs.js
import scala.scalajs.js.annotation.JSGlobal

@js.native
@JSGlobal("chrome.notifications")
object Notifications extends js.Object {

  type Id = String

  val onClose: Event[js.Function2[Id, Boolean, _]] = js.native
  val onClicked: Event[js.Function1[Id, _]] = js.native
  val onButtonClicked: Event[js.Function2[Id, Int, _]] = js.native
  val onPermissionLevelChanged: Event[js.Function1[PermissionLevel, _]] =
    js.native
  val onShowSettings: Event[js.Function0[_]] = js.native

  def create(id: js.UndefOr[Id] = js.undefined,
             options: NotificationOptions,
             callback: js.UndefOr[js.Function1[Id, _]] = js.undefined): Unit =
    js.native

  def update(
      id: Id,
      options: NotificationOptions,
      callback: js.UndefOr[js.Function1[Boolean, _]] = js.undefined): Unit =
    js.native

  def clear(
      id: Id,
      callback: js.UndefOr[js.Function1[Boolean, _]] = js.undefined): Unit =
    js.native

  def getAll(callback: js.Function1[Map[Id, Boolean], _]): Unit = js.native

  def getPermissionLevel(callback: js.Function1[PermissionLevel, _]): Unit =
    js.native

} 
Example 21
Source File: JQuery.scala    From scalajs-spa-tutorial   with Apache License 2.0 5 votes vote down vote up
package spatutorial.client.components

import org.scalajs.dom._

import scala.scalajs.js
import scala.scalajs.js.annotation.JSGlobal


@js.native
trait JQueryEventObject extends Event {
  var data: js.Any = js.native
}

@js.native
@JSGlobal("jQuery")
object JQueryStatic extends js.Object {
  def apply(element: Element): JQuery = js.native
}

@js.native
trait JQuery extends js.Object {
  def on(events: String, selector: js.Any, data: js.Any, handler: js.Function1[JQueryEventObject, js.Any]): JQuery = js.native
  def off(events: String): JQuery = js.native
} 
Example 22
Source File: IO.scala    From scala-commons   with MIT License 5 votes vote down vote up
package com.avsystem.commons
package testutil

import scala.scalajs.js
import scala.scalajs.js.annotation.{JSBracketAccess, JSGlobal, JSImport}

@js.native
@JSImport("fs", JSImport.Namespace)
object NodeFS extends js.Object {
  def readFileSync(path: String, encoding: String = js.native): String = js.native
  def writeFileSync(path: String, data: String, encoding: String = js.native): Unit = js.native
}

@js.native
@JSImport("path", JSImport.Namespace)
object NodePath extends js.Object {
  val sep: String = js.native
}

@js.native
@JSGlobal("process.env")
object NodeEnv extends js.Object {
  @JSBracketAccess
  def get(name: String): String = js.native
}

object IO {
  private final val ResourcesPath = NodeEnv.get("RESOURCES_DIR")

  private def nativePath(path: String): String =
    ResourcesPath + path.replaceAllLiterally("/", NodePath.sep)

  def readTestResource(path: String): String =
    NodeFS.readFileSync(nativePath(path), "UTF-8")

  def writeTestResource(path: String, data: String): Unit =
    NodeFS.writeFileSync(nativePath(path), data, "UTF-8")
} 
Example 23
Source File: CodeBlock.scala    From udash-core   with Apache License 2.0 5 votes vote down vote up
package io.udash
package web.commons.components

import com.avsystem.commons._
import io.udash.bindings.modifiers.Binding
import io.udash.bootstrap.progressbar.UdashProgressBar
import io.udash.bootstrap.utils.BootstrapStyles
import io.udash.web.commons.styles.components.CodeBlockStyles
import org.scalajs.dom.Element
import org.scalajs.dom.html.Pre
import scalatags.JsDom
import scalatags.JsDom.all._

import scala.scalajs.js
import scala.scalajs.js.annotation.JSGlobal

object CodeBlock {
  import io.udash.css.CssView._

  @js.native
  @JSGlobal("Prism")
  private object Prism extends js.Object {
    //https://prismjs.com/extending.html#api
    def highlightAllUnder(element: Element): Unit = js.native
  }

  def apply(data: String, language: String = "language-scala")(styles: CodeBlockStyles): JsDom.TypedTag[Pre] = {
    pre(styles.codeWrapper)(
      ol(styles.codeBlock)(
        data.split("\\r?\\n").map(line =>
          li(code(cls := language)(line))
        )
      )
    )
  }

  def lines(lines: Iterator[String], language: String = "language-scala")(styles: CodeBlockStyles): JsDom.TypedTag[Pre] = {
    pre(styles.codeWrapper)(
      ol(styles.codeBlock)(
        lines.map(line =>
          li(code(cls := language)(line))
        ).toList
      )
    )
  }

  def reactive(data: ReadableProperty[String], placeholder: Modifier, language: String = "language-scala")(styles: CodeBlockStyles): Binding = {
    val progressBar = UdashProgressBar(
      progress = 100.toProperty,
      showPercentage = true.toProperty,
      barStyle = Some(BootstrapStyles.Color.Success).toProperty,
      stripped = true.toProperty,
      animated = true.toProperty
    ) { case _ => b(placeholder) }
    produceWithNested(data)((data, nested) =>
      if (data.isEmpty) ForceBootstrap(nested(progressBar)).render
      else apply(data)(styles).render.setup(rendered => Prism.highlightAllUnder(rendered))
    )
  }
} 
Example 24
Source File: Promise.scala    From scalajs-rxjs   with MIT License 5 votes vote down vote up
//     Project: scalajs-rxjs
//      Module:
// Description: Façade trait for Promises

// Copyright (c) 2016. Distributed under the MIT License (see included LICENSE file).
package rxjs.core

import scala.scalajs.js
import scala.scalajs.js.annotation.{JSGlobal, JSName}

@js.native
@JSGlobal("Promise")
class IPromise[T](f: js.Function2[js.Function1[T,Unit],js.Function1[T,Unit],_]) extends js.Object {
  @JSName("then")
  def andThen[U](onFulfilled: js.Function1[T,U], onRejected: js.Function1[js.Any,_]): IPromise[U] = js.native
}

object IPromise {
  implicit class RichIPromise[T](val p: IPromise[T]) extends AnyVal {
    @inline
    final def andThen[U](onFulfilled: T=>U, onRejected: js.Any=>_): IPromise[U] = p.andThen[U](
      onFulfilled:js.Function1[T,U],
      onRejected: js.Function1[js.Any,_]
    )

    @inline
    final def onSuccess[U](f: T=>U): IPromise[U] = p.andThen[U](f,null)
  }

//  def apply[T](resolve: =>T): IPromise[T] = new IPromise[T]((resolve:js.Function1[T,Unit],reject:js))
}

@js.native
@JSGlobal("Promise")
object Promise extends js.Object {
  def resolve[T](value: T): IPromise[T] = js.native
  def reject[T](value: T): IPromise[T] = js.native
} 
Example 25
Source File: RxPromise.scala    From scalajs-rxjs   with MIT License 5 votes vote down vote up
//     Project: scalajs-rxjs
//      Module: RxPromise
// Description: Provides an extension of js.Promise with simplified event handling

// Copyright (c) 2016. Distributed under the MIT License (see included LICENSE file).
package rxjs

import scala.scalajs.js
import scala.scalajs.js.annotation.{JSGlobal, JSName}
import scala.language.implicitConversions

@js.native
trait RxPromise[T] extends js.Promise[T] {

  @JSName("then")
  def andThen[R](onFulfilled: js.Function1[T,R]): RxPromise[R] = js.native

  @JSName("then")
  def andThen[R](onFulfilled: js.Function1[T,R],
                 onRejected: js.UndefOr[js.Function1[js.Any,R]]): RxPromise[R] = js.native

  @JSName("catch")
  def orCatch(onError: js.Function1[js.Any,_]): RxPromise[T] = js.native
}

object RxPromise {
  @inline
  implicit def toObservable[T](p: RxPromise[T]): Observable[T] = Observable.fromPromise(p)

  type ResolveFun[T] = Function1[T,js.Promise[T]]
  type RejectFun = Function1[Any,js.Promise[Nothing]]

  @JSGlobal("Promise")
  @js.native
  private class Impl[T](executor: js.Function2[js.Function1[T,Unit],js.Function1[Any,Unit],Any]) extends js.Object

  def apply[T](executor: Function2[js.Function1[T,Unit],js.Function1[Any,Unit],Any]): RxPromise[T] = new Impl(executor).asInstanceOf[RxPromise[T]]
  def resolve[T](value: T): RxPromise[T] = js.Promise.resolve[T](value).asInstanceOf[RxPromise[T]]
  def reject(reason: Any): RxPromise[Nothing] = js.Promise.reject(reason).asInstanceOf[RxPromise[Nothing]]

  implicit final class RichRxPromise[T](val p: RxPromise[T]) extends AnyVal {
    @inline
    def map[R](f: T=>R): RxPromise[R] = p.andThen(f)
    @inline
    @deprecated("Use map() instead","0.0.2")
    def onFulfilled[R](f: T=>R): RxPromise[R] = p.andThen(f)
    @inline
    def onError(f: js.Any=>_): RxPromise[T] = p.orCatch(f)
  }
}