Add insertAsFirst option

This commit is contained in:
rnentjes
2017-04-02 17:01:47 +02:00
parent c636542b9e
commit 273525cd05
3 changed files with 13 additions and 3 deletions

6
.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@@ -1,4 +1,4 @@
#Sat Apr 01 17:12:59 CEST 2017 #Sun Apr 02 16:55:00 CEST 2017
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME

View File

@@ -16,10 +16,14 @@ object Komp {
elements[element] = component elements[element] = component
} }
fun create(parent: HTMLElement, component: HtmlComponent) { fun create(parent: HTMLElement, component: HtmlComponent, insertAsFirst: Boolean = false) {
val element = component.create() val element = component.create()
if (insertAsFirst && parent.childElementCount > 0) {
parent.insertBefore(element, parent.firstChild)
} else {
parent.appendChild(element) parent.appendChild(element)
}
elements[element] = component elements[element] = component
} }