CDATA sections are not supported in HTML documents
import scala.scalajs.js
a[js.JavaScriptException] should be thrownBy {
@html val myCData = <![CDATA[my data]]>
myCData.watch()
}
,
Process instructions
@html val myXmlStylesheet = <?my-instruction my data?>
myXmlStylesheet.watch()
myXmlStylesheet.value.target should be("my-instruction")
myXmlStylesheet.value.data should be("my data")
import org.scalajs.dom.document
@html def escaped =
 $minus
val div = document.createElement("div")
html.render(div, escaped)
assert(div.innerHTML == "
$minus")
,
XHTML comments
import org.scalajs.dom.document
@html def comment =
val div = document.createElement("div")
html.render(div, comment)
assert(div.innerHTML == "
")
,
Seq in DOM
import org.scalajs.dom.document
@html def myUl = {
{Seq(
- data1,
- data2)}
}
val div = document.createElement("div")
html.render(div, myUl)
div.firstChild.childNodes.length should be(2)
,
A child node must not be inserted more than once
an[IllegalStateException] should be thrownBy {
@html
val child = <hr/>
@html
val parent =
<span>{child.bind}</span><span>{child.bind}</span>
parent.watch()
}
import com.thoughtworks.binding.Binding.Vars
val v0 = Vars("original text 0","original text 1")
@html val monadicDiv =
<span> { for (s <- v0) yield <b>{s}</b> } </span>
monadicDiv.watch()
val div = monadicDiv.value
assert(monadicDiv.value.outerHTML == "
original text 0original text 1 ")
v0.value.prepend("prepended")
assert(div eq monadicDiv.value)
assert(monadicDiv.value.outerHTML == "
prependedoriginal text 0original text 1 ")
v0.value.remove(1)
assert(div eq monadicDiv.value)
assert(monadicDiv.value.outerHTML == "
prependedoriginal text 1 ")
,
Changing text
import com.thoughtworks.binding.Binding.Var
val v0 = Var("original text")
@html val monadicDiv =
<span> {v0.bind} </span>
monadicDiv.watch()
assert(monadicDiv.value.outerHTML == "
original text ")
v0.value = "changed"
assert(monadicDiv.value.outerHTML == "
changed ")
,
Text interpolation in an element
@html val monadicDiv =
{"text"}
monadicDiv.watch()
assert(monadicDiv.value.outerHTML == "
text")
,
Element list of XHTML literals
@html
val myDivs =
myDivs.watch()
import org.scalajs.dom.html.Div
inside(myDivs.value) {
case collection.Seq(div1: Div, div2: Div, div3: Div) =>
div1.nodeName should be("DIV")
div1.hasAttribute("class") should be(false)
div1.className should be("")
div2.title should be("my title")
div2.hasAttribute("class") should be(true)
div2.className should be("")
div3.className should be("my-class")
}
,
Opaque type aliases of HTMLInputElement
@html
val myMeta = <input name="myInput"type="radio"/>
myMeta.watch()
myMeta.value.outerHTML should be("""" type="radio">""")
,
Special character in attribute names
@html
val myMeta = <meta http-equiv="refresh" content="30"/>
myMeta.watch()
myMeta.value.outerHTML should be("""" content="30">""")
,
XHTML literals with text attributes
@html
val myDiv =
myDiv.value.nodeName should be("DIV")
myDiv.value.className should be("my-class")
myDiv.value.tabIndex should be(42)
Nested XHTML literals with interpolation:
@html
val myDiv2 =
text<span style={"color: blue;"} tabIndex={99}></span>
{myDiv.bind}
myDiv2.watch()
myDiv2.value.outerHTML should be("""
text" tabindex="99">
html
""")
An annotation to convert XHTML literals to data-bindable DOM nodes.
Author:
杨博 (Yang Bo) <[email protected]>
XML namespaces
CDATA sections are not supported in HTML documents
Process instructions
Entity references
Escape
XHTML comments
Seq in DOM
A child node must not be inserted more than once
Changing attribute values
Dynamc attributes
for
/yield
/if
expressions in XHTML interpolationfor
/yield
expressions in XHTML interpolationChanging text
Text interpolation in an element
Element list of XHTML literals
Opaque type aliases of HTMLInputElement
Special character in attribute names
XHTML literals with text attributes
Nested XHTML literals with interpolation: