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 mySelect = {
<select>{Seq(<option>data1</option>, <option>data2</option>)}</select>
}
val span = document.createElement("span")
html.render(span, mySelect)
span.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><i>{child.bind}</i><i>{child.bind}</i></span>
parent.watch()
}
import com.thoughtworks.binding.Binding.Vars
val v0 = Vars("original text 0","original text 1")
@html val monadicSpan = <span> <i> { for (s <- v0) yield <b>{s}</b> } </i> </span>
monadicSpan.watch()
val span = monadicSpan.value
assert(monadicSpan.value.outerHTML == "original text 0original text 1")
v0.value.prepend("prepended")
assert(span eq monadicSpan.value)
assert(monadicSpan.value.outerHTML == "prependedoriginal text 0original text 1")
v0.value.remove(1)
assert(span eq monadicSpan.value)
assert(monadicSpan.value.outerHTML == "prependedoriginal text 1")
,
Changing text
import com.thoughtworks.binding.Binding.Var
val v0 = Var("original text")
@html val monadicSpan = <span> <i> {v0.bind} </i> </span>
monadicSpan.watch()
assert(monadicSpan.value.outerHTML == " original text ")
v0.value = "changed"
assert(monadicSpan.value.outerHTML == " changed ")
,
Text interpolation in an element
@html val monadicSpan = <span>{"text"}</span>
monadicSpan.watch()
assert(monadicSpan.value.outerHTML == "text")
,
Element list of XHTML literals
@html
val mySpans = <span></span><span title={"my title"} class=""></span><span class="my-class"></span>
mySpans.watch()
import org.scalajs.dom.html.Span
inside(mySpans.value) {
case collection.Seq(span1: Span, span2: Span, span3: Span) =>
span1.nodeName should be("SPAN")
span1.hasAttribute("class") should be(false)
span1.className should be("")
span2.title should be("my title")
span2.hasAttribute("class") should be(true)
span2.className should be("")
span3.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 mySpan = <span class="my-class" tabindex="42"></span>
mySpan.value.nodeName should be("SPAN")
mySpan.value.className should be("my-class")
mySpan.value.tabIndex should be(42)
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: