2015-03-26 00:33:11 +01:00
|
|
|
define([], function () {
|
|
|
|
return function () {
|
2017-03-17 03:14:57 +01:00
|
|
|
var self = this;
|
2015-03-26 00:33:11 +01:00
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
var tabs = document.createElement("ul");
|
|
|
|
tabs.classList.add("tabs");
|
2015-03-26 00:33:11 +01:00
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
var container = document.createElement("div");
|
2015-03-26 00:33:11 +01:00
|
|
|
|
2015-03-29 21:44:05 +02:00
|
|
|
function gotoTab(li) {
|
2017-03-17 03:14:57 +01:00
|
|
|
for (var i = 0; i < tabs.children.length; i++) {
|
|
|
|
tabs.children[i].classList.remove("visible");
|
|
|
|
}
|
2015-07-07 17:42:41 +02:00
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
while (container.firstChild) {
|
|
|
|
container.removeChild(container.firstChild);
|
|
|
|
}
|
2015-03-26 00:33:11 +01:00
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
li.classList.add("visible");
|
2015-07-07 17:42:41 +02:00
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
var tab = document.createElement("div");
|
|
|
|
tab.classList.add("tab");
|
|
|
|
container.appendChild(tab);
|
|
|
|
li.child.render(tab);
|
2015-03-29 21:44:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function switchTab() {
|
2017-03-17 03:14:57 +01:00
|
|
|
gotoTab(this);
|
2015-03-26 00:33:11 +01:00
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
return false;
|
2015-03-26 00:33:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
self.add = function (title, d) {
|
2017-03-17 03:14:57 +01:00
|
|
|
var li = document.createElement("li");
|
|
|
|
li.textContent = title;
|
|
|
|
li.onclick = switchTab;
|
|
|
|
li.child = d;
|
|
|
|
tabs.appendChild(li);
|
2015-07-12 00:46:15 +02:00
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
var anyVisible = false;
|
2015-07-12 00:46:15 +02:00
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
for (var i = 0; i < tabs.children.length; i++) {
|
2015-07-12 00:46:15 +02:00
|
|
|
if (tabs.children[i].classList.contains("visible")) {
|
2017-03-17 03:14:57 +01:00
|
|
|
anyVisible = true;
|
|
|
|
break;
|
2015-07-12 00:46:15 +02:00
|
|
|
}
|
2017-03-17 03:14:57 +01:00
|
|
|
}
|
2015-07-12 00:46:15 +02:00
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
if (!anyVisible) {
|
|
|
|
gotoTab(li);
|
|
|
|
}
|
|
|
|
};
|
2015-03-26 00:33:11 +01:00
|
|
|
|
|
|
|
self.render = function (el) {
|
2017-03-17 03:14:57 +01:00
|
|
|
el.appendChild(tabs);
|
|
|
|
el.appendChild(container);
|
|
|
|
};
|
2015-03-26 00:33:11 +01:00
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
return self;
|
|
|
|
};
|
|
|
|
});
|