2015-03-25 23:33:11 +00:00
|
|
|
define([], function () {
|
|
|
|
return function () {
|
|
|
|
var self = this
|
|
|
|
|
|
|
|
var tabs = document.createElement("ul")
|
|
|
|
tabs.classList.add("tabs")
|
|
|
|
|
|
|
|
var container = document.createElement("div")
|
|
|
|
|
2015-03-29 19:44:05 +00:00
|
|
|
function gotoTab(li) {
|
2015-07-08 19:28:56 +00:00
|
|
|
var visible = li.classList.contains("visible")
|
|
|
|
|
2015-07-07 15:42:41 +00:00
|
|
|
for (var i = 0; i < tabs.children.length; i++)
|
|
|
|
tabs.children[i].classList.remove("visible")
|
|
|
|
|
|
|
|
while (container.firstChild)
|
|
|
|
container.removeChild(container.firstChild)
|
2015-03-25 23:33:11 +00:00
|
|
|
|
2015-07-08 19:28:56 +00:00
|
|
|
if (visible)
|
|
|
|
return
|
|
|
|
|
2015-03-29 19:44:05 +00:00
|
|
|
li.classList.add("visible")
|
2015-07-07 15:42:41 +00:00
|
|
|
|
|
|
|
var tab = document.createElement("div")
|
|
|
|
tab.classList.add("tab")
|
|
|
|
container.appendChild(tab)
|
|
|
|
li.child.render(tab)
|
2015-03-29 19:44:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function switchTab() {
|
|
|
|
gotoTab(this)
|
2015-03-25 23:33:11 +00:00
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
self.add = function (title, d) {
|
|
|
|
var li = document.createElement("li")
|
|
|
|
li.textContent = title
|
|
|
|
li.onclick = switchTab
|
2015-07-07 15:42:41 +00:00
|
|
|
li.child = d
|
2015-03-25 23:33:11 +00:00
|
|
|
tabs.appendChild(li)
|
|
|
|
}
|
|
|
|
|
|
|
|
self.render = function (el) {
|
|
|
|
el.appendChild(tabs)
|
|
|
|
el.appendChild(container)
|
|
|
|
}
|
|
|
|
|
|
|
|
return self
|
|
|
|
}
|
|
|
|
})
|