<commit_before>package net.yested.ext.bootstrap3

import net.yested.core.html.setClassPresence
import net.yested.core.html.setDisabled
import net.yested.core.html.*
import net.yested.core.properties.Property
import net.yested.core.properties.ReadOnlyProperty
import net.yested.core.utils.with
import org.w3c.dom.*
import org.w3c.dom.events.Event
import kotlin.dom.addClass
import kotlin.dom.plus
import kotlin.dom.removeClass

class NavbarMenuDropDown(val ul: HTMLUListElement) {

    fun item(active: Property<Boolean>? = null, init: HTMLLIElement.()->Unit) {
        ul with {
            li {
                active?.let { setClassPresence("active", it) }
                this.init()
            }
        }
    }

    fun separator() {
        ul with {
            li { className = "divider" }
        }
    }

    fun dropDownHeader(init: HTMLLIElement.()->Unit) {
        ul with {
            li { className = "dropdown-header"
                this.init()
            }
        }
    }

}

class NavbarMenu(val ul: HTMLUListElement) {

    fun item(active: Property<Boolean>? = null, init: HTMLLIElement.()->Unit) {
        ul with {
            li {
                active?.let { setClassPresence("active", it) }
                this.init()
            }
        }
    }

    fun dropDown(label: String, init: NavbarMenuDropDown.()->Unit) {

        var el:HTMLUListElement? = null
        ul with {
            li {
                a {
                    href = "#"; className = "dropdown-toggle"
                    setAttribute("data-toggle", "dropdown")
                    plus(label)
                    span { className = "caret" }
                }
                el = ul {
                    className = "dropdown-menu"
                }
            }
        }
        NavbarMenuDropDown(el!!).init()
    }

}

enum class NavbarPosition(val code: String) {
    Left("navbar-left"),
    Right("navbar-right")
}

class NavbarContext(
        val brand:HTMLElement,
        val contentElement: HTMLDivElement) {

    fun brand(init:HTMLElement.()->Unit) {
        brand.init()
    }

    fun menu(
            position: NavbarPosition = NavbarPosition.Left,
            init:NavbarMenu.()->Unit) {
        contentElement.ul { className = "nav navbar-nav ${position.code}"
            NavbarMenu(ul = this).init()
        }
    }

    fun form(
            position: NavbarPosition = NavbarPosition.Left,
            init: HTMLFormElement.()->Unit) {
        contentElement.form { className = "navbar-form ${position.code}"
            init()
        }
    }

    fun button(
            position: NavbarPosition = NavbarPosition.Left,
            look: ButtonLook = ButtonLook.Default,
            onclick: ((Event)->Unit)? = null,
            active: Property<Boolean>? = null,
            disabled: ReadOnlyProperty<Boolean>? = null,
            init: HTMLButtonElement.()->Unit) {
        contentElement.btsButton { className = "btn navbar-btn ${position.code} btn-${look.code}"; type = "submit"
            addEventListener("click", {  event ->
                onclick?.let { onclick(event) }
                active?.set(!active.get())
            }, false)
            init()
            active?.let { setClassPresence("active", it) }
            disabled?.let { setDisabled(it) }
        }
    }

    fun text(
            position: NavbarPosition = NavbarPosition.Left,
            init: HTMLParagraphElement.()->Unit) {
        contentElement.p { className = "navbar-text ${position.code}"
            init()
        }
    }

}

enum class NavbarCompletePosition(val code: String) {
    Top(code = ""),
    FixedTop(code = "navbar-fixed-top"),
    FixedBottom(code = "navbar-fixed-bottom"),
    StaticTop(code = "navbar-static-top")
}

fun HTMLElement.navbar(
        position: NavbarCompletePosition = NavbarCompletePosition.Top,
        inverted: Boolean = false,
        init: NavbarContext.()->Unit) {

    var brand:HTMLElement? = null
    var contentElement:HTMLDivElement? = null

    nav {  className = "navbar ${if (inverted) "navbar-inverse" else ""} ${position.code}"
        div { className = "container"
            div { className = "navbar-header"
                /*
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                  </button>
                 */
                a { className = "navbar-brand"; href = "#"
                    brand = this
                }
            }
            div { id = "navbar"; className = "navbar-collapse collapse"
                contentElement = this
            }
        }
    }

    NavbarContext(brand = brand!!,  contentElement = contentElement!!).init()

}<commit_msg>Add navbar-toggle hamburger button.<commit_after>package net.yested.ext.bootstrap3

import net.yested.core.html.setClassPresence
import net.yested.core.html.setDisabled
import net.yested.core.html.*
import net.yested.core.properties.Property
import net.yested.core.properties.ReadOnlyProperty
import net.yested.core.utils.with
import org.w3c.dom.*
import org.w3c.dom.events.Event
import kotlin.dom.*

class NavbarMenuDropDown(val ul: HTMLUListElement) {

    fun item(active: Property<Boolean>? = null, init: HTMLLIElement.()->Unit) {
        ul with {
            li {
                active?.let { setClassPresence("active", it) }
                this.init()
            }
        }
    }

    fun separator() {
        ul with {
            li { className = "divider" }
        }
    }

    fun dropDownHeader(init: HTMLLIElement.()->Unit) {
        ul with {
            li { className = "dropdown-header"
                this.init()
            }
        }
    }

}

class NavbarMenu(val ul: HTMLUListElement) {

    fun item(active: Property<Boolean>? = null, init: HTMLLIElement.()->Unit) {
        ul with {
            li {
                active?.let { setClassPresence("active", it) }
                this.init()
            }
        }
    }

    fun dropDown(label: String, init: NavbarMenuDropDown.()->Unit) {

        var el:HTMLUListElement? = null
        ul with {
            li {
                a {
                    href = "#"; className = "dropdown-toggle"
                    setAttribute("data-toggle", "dropdown")
                    plus(label)
                    span { className = "caret" }
                }
                el = ul {
                    className = "dropdown-menu"
                }
            }
        }
        NavbarMenuDropDown(el!!).init()
    }

}

enum class NavbarPosition(val code: String) {
    Left("navbar-left"),
    Right("navbar-right")
}

class NavbarContext(
        private val navbarToggle: HTMLElement,
        private val navbarHeader: HTMLElement,
        val contentElement: HTMLDivElement) {

    fun brand(init:HTMLElement.()->Unit) {
        navbarToggle.removeClass("pull-left")
        navbarHeader.a { className = "navbar-brand"; href = "#"
            init ()
        }
    }

    fun menu(
            position: NavbarPosition = NavbarPosition.Left,
            init:NavbarMenu.()->Unit) {
        contentElement.ul { className = "nav navbar-nav ${position.code}"
            NavbarMenu(ul = this).init()
        }
    }

    fun form(
            position: NavbarPosition = NavbarPosition.Left,
            init: HTMLFormElement.()->Unit) {
        contentElement.form { className = "navbar-form ${position.code}"
            init()
        }
    }

    fun button(
            position: NavbarPosition = NavbarPosition.Left,
            look: ButtonLook = ButtonLook.Default,
            onclick: ((Event)->Unit)? = null,
            active: Property<Boolean>? = null,
            disabled: ReadOnlyProperty<Boolean>? = null,
            init: HTMLButtonElement.()->Unit) {
        contentElement.btsButton { className = "btn navbar-btn ${position.code} btn-${look.code}"; type = "submit"
            addEventListener("click", {  event ->
                onclick?.let { onclick(event) }
                active?.set(!active.get())
            }, false)
            init()
            active?.let { setClassPresence("active", it) }
            disabled?.let { setDisabled(it) }
        }
    }

    fun text(
            position: NavbarPosition = NavbarPosition.Left,
            init: HTMLParagraphElement.()->Unit) {
        contentElement.p { className = "navbar-text ${position.code}"
            init()
        }
    }

}

enum class NavbarCompletePosition(val code: String) {
    Top(code = ""),
    FixedTop(code = "navbar-fixed-top"),
    FixedBottom(code = "navbar-fixed-bottom"),
    StaticTop(code = "navbar-static-top")
}

fun HTMLElement.navbar(
        position: NavbarCompletePosition = NavbarCompletePosition.Top,
        inverted: Boolean = false,
        init: NavbarContext.()->Unit) {

    var navbarHeader: HTMLElement? = null
    var navbarToggle: HTMLElement? = null
    var contentElement: HTMLDivElement? = null

    nav {  className = "navbar ${if (inverted) "navbar-inverse " else ""}${position.code}"
        div { className = "container"
            div { className = "navbar-header"
                // pull-left will be removed if a brand is added.
                button {
                    className = "navbar-toggle collapsed pull-left"; type = "button"
                    setAttribute("data-toggle", "collapse")
                    setAttribute("data-target", "#navbar")
                    setAttribute("aria-expanded", "false")
                    setAttribute("aria-controls", "navbar")
                    span { className = "sr-only"; appendText("Toggle Navigation") }
                    glyphicon("menu-hamburger")
                    navbarToggle = this
                }
                navbarHeader = this
            }
            div { id = "navbar"; className = "navbar-collapse collapse"
                setAttribute("aria-expanded", "false")
                contentElement = this
            }
        }
    }

    NavbarContext(navbarToggle = navbarToggle!!, navbarHeader = navbarHeader!!,  contentElement = contentElement!!).init()

}
{'fraction_non_alphanumeric': 0.1221182598630269, 'fraction_numerical': 0.0005787595254171891, 'mean_word_length': 1.7863477559795753, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2136146', 'n_tokens_mistral': 2922, 'n_tokens_neox': 2818, 'n_words': 572}