Clean Dom and Dom tests.
This commit is contained in:
committed by
Andrey Breslav
parent
cde74504d4
commit
f2b9b370e1
@@ -333,13 +333,7 @@ public fun NodeList?.toXmlString(xmlDeclaration: Boolean = false): String {
|
||||
|
||||
/** Converts the collection of nodes to an XML String */
|
||||
public fun nodesToXmlString(nodes: Iterable<Node>, xmlDeclaration: Boolean = false): String {
|
||||
// TODO this should work...
|
||||
// return this.map{it.toXmlString()}.join("")
|
||||
val builder = StringBuilder()
|
||||
for (n in nodes) {
|
||||
builder.append(n.toXmlString(xmlDeclaration))
|
||||
}
|
||||
return builder.toString()
|
||||
return nodes.map { it.toXmlString(xmlDeclaration) }.join()
|
||||
}
|
||||
|
||||
// Syntax sugar
|
||||
|
||||
@@ -5,23 +5,17 @@ import org.w3c.dom.Node
|
||||
import org.w3c.dom.events.*
|
||||
|
||||
/**
|
||||
* Turns an event handler function into an [EventListener]
|
||||
*/
|
||||
* Turns an event handler function into an [EventListener]
|
||||
*/
|
||||
public fun eventHandler(handler: (Event) -> Unit): EventListener {
|
||||
return EventListenerHandler(handler)
|
||||
}
|
||||
|
||||
private class EventListenerHandler(private val handler: (Event) -> Unit) : EventListener {
|
||||
public override fun handleEvent(e: Event) {
|
||||
if (e != null) {
|
||||
handler(e)
|
||||
}
|
||||
handler(e)
|
||||
}
|
||||
/*
|
||||
TODO: needs KT-2507 fixed
|
||||
|
||||
public override fun toString(): String? = "EventListenerHandler($handler)"
|
||||
*/
|
||||
public override fun toString(): String = "EventListenerHandler($handler)"
|
||||
}
|
||||
|
||||
public fun mouseEventHandler(handler: (MouseEvent) -> Unit): EventListener {
|
||||
@@ -56,16 +50,12 @@ private class CloseableEventListener(
|
||||
private val listener: EventListener,
|
||||
private val name: String,
|
||||
private val capture: Boolean
|
||||
) : Closeable {
|
||||
) : Closeable {
|
||||
public override fun close() {
|
||||
target.removeEventListener(name, listener, capture)
|
||||
}
|
||||
|
||||
/*
|
||||
TODO: needs KT-2507 fixed
|
||||
|
||||
public override fun toString(): String? = "CloseableEventListener($target, $name)"
|
||||
*/
|
||||
public override fun toString(): String = "CloseableEventListener($target, $name)"
|
||||
}
|
||||
|
||||
public fun Node?.onClick(capture: Boolean = false, handler: (MouseEvent) -> Unit): Closeable? {
|
||||
|
||||
@@ -156,12 +156,12 @@ public fun Element.removeClass(cssClass: String): Boolean {
|
||||
|
||||
/** Creates a new document with the given document builder*/
|
||||
public fun createDocument(builder: DocumentBuilder): Document {
|
||||
return builder.newDocument()!!
|
||||
return builder.newDocument()
|
||||
}
|
||||
|
||||
/** Creates a new document with an optional DocumentBuilderFactory */
|
||||
public fun createDocument(builderFactory: DocumentBuilderFactory = defaultDocumentBuilderFactory()): Document {
|
||||
return createDocument(builderFactory.newDocumentBuilder()!!)
|
||||
return createDocument(builderFactory.newDocumentBuilder())
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -175,7 +175,7 @@ public fun defaultDocumentBuilderFactory(): DocumentBuilderFactory {
|
||||
* Returns the default [[DocumentBuilder]]
|
||||
*/
|
||||
public fun defaultDocumentBuilder(builderFactory: DocumentBuilderFactory = defaultDocumentBuilderFactory()): DocumentBuilder {
|
||||
return builderFactory.newDocumentBuilder()!!
|
||||
return builderFactory.newDocumentBuilder()
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user