|
1 |
| -scala-js-dom |
2 |
| -============ |
3 |
| - |
4 |
| -Scala-js-dom provides a nice statically typed interface to the DOM such that it can be called from Scala code without resorting to `js.Dynamic`. All javascript globals functions, singletons and classes are members of the `org.scalajs.dom` package, e.g. |
5 |
| - |
6 |
| -```scala |
7 |
| -import org.scalajs.dom |
8 |
| -dom.alert("HAI") |
9 |
| -``` |
10 |
| - |
11 |
| -Will cause a javascript alert box saying `HAI` to appear. Other javascript classes and objects can be similarly accessed e.g. `new dom.XMLHttpRequest()` to perform a new Ajax request, `dom.document` to access the global `document` object, or `dom.setInterval(() => ???, 1000)` to schedule a recurring task every second. The names of these functions/singletons/classes match their Javascript equivalents exactly, so if you want to know how to do something (e.g. "how do I open a websocket connection") the syntax is the same as if you were using raw Javascript. |
12 |
| - |
13 |
| -The goal of this project is to provide a thin-but-idiomatic-scala interface to modern browser APIs. In particular: |
14 |
| - |
15 |
| -- Deprecated properties/methods/types will not be present. |
16 |
| -- IE-only, Chrome-only, FF-only, and in general browser-specific attributes will not be present. |
17 |
| -- The name of a Scala type should map directly to the name of the corresponding Javascript type. |
18 |
| -- Any type which is a Javascript type (e.g. you can `instanceof` in javascript) should be a Scala `class`; any other interface which isn't a Javascript type should be a `trait`. |
19 |
| -- Read-only members should be `def`, and not-directly-instantiable classes should have `private` constructors. |
20 |
| - |
21 |
| -Extensions |
22 |
| ----------- |
23 |
| - |
24 |
| -Apart from `Color`, Scala-js-dom contains some useful helpers and implicit classes in `org.scalajs.dom.extensions` that serve no purpose other than to make your use of the DOM more pleasant. |
25 |
| -Examples include the `Ajax.get` and `Ajax.post` methods which let you avoid messing with `dom.XMLHttpRequest` directly, or `KeyCodes` which provides a nice list of the keycodes that result from pressing various keys on the keyboard. |
26 |
| - |
27 |
| -Usage |
28 |
| ------ |
29 |
| - |
30 |
| -Add the following to your sbt build definition: |
31 |
| - |
32 |
| -```scala |
33 |
| -libraryDependencies += "org.scala-lang.modules.scalajs" %%% "scalajs-dom" % "0.6" |
34 |
| -``` |
35 |
| - |
36 |
| -then enjoy the types available in `org.scalajs.dom`. |
37 |
| - |
38 |
| -scalajs-dom 0.6 is built and published for Scala.js 0.5.0 and following in |
39 |
| -the 0.5.x series, with both Scala 2.10 and 2.11. |
40 |
| - |
41 |
| -See also [roll](https://github.com/lihaoyi/roll) ([live demo](http://lihaoyi.github.io/roll/)) and [scala-js-games](https://github.com/lihaoyi/scala-js-games) for an example of its use. [Scala-js-fiddle](http://www.scala-js-fiddle.com/) also contains a pile of [fun examples](http://www.scala-js-fiddle.com/gist/9405209/Oscilloscope.scala) that demonstrate its usage. Pull requests/forks are welcome! |
42 |
| - |
43 |
| -Contributing |
44 |
| ------------- |
45 |
| - |
46 |
| -Scala-js-dom is a work in progress. The current code base is a hodgepodge of auto-generated/scraped/hand-tweaked code, and is full of rough edges. If you see something that you think can be improved, feel free to send a pull request. These could include: |
47 |
| - |
48 |
| -- Improved doc-comments; who doesn't love better docs? |
49 |
| -- Missing methods/properties/classes; send the PR adding it in including it together with a link to an authoritative source (e.g. MDN) and it should get merged. |
50 |
| -- Additional extensions (in `org.scalajs.dom.extensions`). These currently represent an arbitrary collection of helpers that have been needed so far. If there's some implicit that you find you need and you think other people will to, send a pull request and we can talk about it. |
51 |
| - |
52 |
| -License |
53 |
| -------- |
54 |
| - |
55 |
| -Documentation marked "MDN" is thanks to Mozilla Contributors |
56 |
| -at https://developer.mozilla.org/en-US/docs/Web/API and available |
57 |
| -under the Creative Commons Attribution-ShareAlike v2.5 or later. |
58 |
| -http://creativecommons.org/licenses/by-sa/2.5/ |
59 |
| - |
60 |
| -This should not affect you, as a user of the library, as long as you don't |
61 |
| -modify these MDN materials (e.g. you leave them as is, or replace them |
62 |
| -wholesale). In particular, packaging this library with MDN materials unchanged |
63 |
| -is fine for any purpose (including commercial) according to the |
64 |
| -CC-Attribute-ShareAlike License. |
65 |
| - |
66 |
| -Everything else (e.g. the code) is under the MIT License |
67 |
| - |
68 |
| -The MIT License (MIT) |
69 |
| - |
70 |
| -Copyright (c) 2013 Li Haoyi |
71 |
| - |
72 |
| -Permission is hereby granted, free of charge, to any person obtaining a copy |
73 |
| -of this software and associated documentation files (the "Software"), to deal |
74 |
| -in the Software without restriction, including without limitation the rights |
75 |
| -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
76 |
| -copies of the Software, and to permit persons to whom the Software is |
77 |
| -furnished to do so, subject to the following conditions: |
78 |
| - |
79 |
| -The above copyright notice and this permission notice shall be included in |
80 |
| -all copies or substantial portions of the Software. |
81 |
| - |
82 |
| -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
83 |
| -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
84 |
| -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
85 |
| -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
86 |
| -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
87 |
| -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
88 |
| -THE SOFTWARE. |
| 1 | +[Documentation](http://scala-js.github.io/scala-js-dom) |
0 commit comments