2016-05-27 21:59:01 +00:00
|
|
|
define(function () {
|
2017-01-29 23:51:08 +00:00
|
|
|
'use strict';
|
2016-05-27 21:59:01 +00:00
|
|
|
|
2015-03-25 23:33:11 +00:00
|
|
|
return function () {
|
2016-05-22 11:23:43 +00:00
|
|
|
var self = this;
|
2015-03-25 23:33:11 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
var tabs = document.createElement('ul');
|
|
|
|
tabs.classList.add('tabs');
|
2015-03-25 23:33:11 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
var container = document.createElement('div');
|
2015-03-25 23:33:11 +00:00
|
|
|
|
2015-03-29 19:44:05 +00:00
|
|
|
function gotoTab(li) {
|
2016-05-22 12:51:30 +00:00
|
|
|
for (var i = 0; i < tabs.children.length; i++) {
|
2017-01-29 23:51:08 +00:00
|
|
|
tabs.children[i].classList.remove('visible');
|
2016-05-22 12:51:30 +00:00
|
|
|
}
|
2015-07-07 15:42:41 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
while (container.firstChild) {
|
2016-05-22 11:23:43 +00:00
|
|
|
container.removeChild(container.firstChild);
|
2016-05-22 12:51:30 +00:00
|
|
|
}
|
2015-03-25 23:33:11 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
li.classList.add('visible');
|
2015-07-07 15:42:41 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
var tab = document.createElement('div');
|
|
|
|
tab.classList.add('tab');
|
2016-05-22 11:23:43 +00:00
|
|
|
container.appendChild(tab);
|
|
|
|
li.child.render(tab);
|
2015-03-29 19:44:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function switchTab() {
|
2016-05-22 11:23:43 +00:00
|
|
|
gotoTab(this);
|
2015-03-25 23:33:11 +00:00
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
return false;
|
2015-03-25 23:33:11 +00:00
|
|
|
}
|
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
self.add = function add(title, d) {
|
|
|
|
var li = document.createElement('li');
|
2017-01-28 14:33:13 +00:00
|
|
|
li.textContent = _.t(title);
|
2016-05-22 11:23:43 +00:00
|
|
|
li.onclick = switchTab;
|
|
|
|
li.child = d;
|
|
|
|
tabs.appendChild(li);
|
2015-07-11 22:46:15 +00:00
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
var anyVisible = false;
|
2015-07-11 22:46:15 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
for (var i = 0; i < tabs.children.length; i++) {
|
2017-01-29 23:51:08 +00:00
|
|
|
if (tabs.children[i].classList.contains('visible')) {
|
2016-05-22 11:23:43 +00:00
|
|
|
anyVisible = true;
|
|
|
|
break;
|
2015-07-11 22:46:15 +00:00
|
|
|
}
|
2016-05-22 12:51:30 +00:00
|
|
|
}
|
2015-07-11 22:46:15 +00:00
|
|
|
|
2016-05-22 12:51:30 +00:00
|
|
|
if (!anyVisible) {
|
2016-05-22 11:23:43 +00:00
|
|
|
gotoTab(li);
|
2016-05-22 12:51:30 +00:00
|
|
|
}
|
2016-05-22 11:23:43 +00:00
|
|
|
};
|
2015-03-25 23:33:11 +00:00
|
|
|
|
2017-01-29 23:51:08 +00:00
|
|
|
self.render = function render(el) {
|
2016-05-22 11:23:43 +00:00
|
|
|
el.appendChild(tabs);
|
|
|
|
el.appendChild(container);
|
|
|
|
};
|
2015-03-25 23:33:11 +00:00
|
|
|
|
2016-05-22 11:23:43 +00:00
|
|
|
return self;
|
|
|
|
};
|
|
|
|
});
|