document.addEventListener('dependency-update', this.updateTabs.bind(this));
this.updateTabs();
-
- if (!groups.length)
- this.setActiveTabId(-1, -1);
},
initTabGroup: function(panes) {
active = pane.getAttribute('data-tab-active') === 'true';
menu.appendChild(E('li', {
+ 'style': L.dom.isEmpty(pane) ? 'display:none' : null,
'class': active ? 'cbi-tab' : 'cbi-tab-disabled',
'data-tab': name
}, E('a', {
group.parentNode.insertBefore(menu, group);
if (selected === null) {
- selected = this.getActiveTabId(groupId);
+ selected = this.getActiveTabId(panes[0]);
if (selected < 0 || selected >= panes.length || L.dom.isEmpty(panes[selected])) {
for (var i = 0; i < panes.length; i++) {
menu.childNodes[selected].classList.remove('cbi-tab-disabled');
panes[selected].setAttribute('data-tab-active', 'true');
- this.setActiveTabId(groupId, selected);
+ this.setActiveTabId(panes[selected], selected);
+ }
+ },
+
+ getPathForPane: function(pane) {
+ var path = [], node = null;
+
+ for (node = pane ? pane.parentNode : null;
+ node != null && node.hasAttribute != null;
+ node = node.parentNode)
+ {
+ if (node.hasAttribute('data-tab'))
+ path.unshift(node.getAttribute('data-tab'));
+ else if (node.hasAttribute('data-section-id'))
+ path.unshift(node.getAttribute('data-section-id'));
}
+
+ return path.join('/');
},
getActiveTabState: function() {
try {
var val = JSON.parse(window.sessionStorage.getItem('tab'));
- if (val.page === page && Array.isArray(val.groups))
+ if (val.page === page && L.isObject(val.paths))
return val;
}
catch(e) {}
window.sessionStorage.removeItem('tab');
- return { page: page, groups: [] };
+ return { page: page, paths: {} };
},
- getActiveTabId: function(groupId) {
- return +this.getActiveTabState().groups[groupId] || 0;
+ getActiveTabId: function(pane) {
+ var path = this.getPathForPane(pane);
+ return +this.getActiveTabState().paths[path] || 0;
},
- setActiveTabId: function(groupId, tabIndex) {
+ setActiveTabId: function(pane, tabIndex) {
+ var path = this.getPathForPane(pane);
+
try {
var state = this.getActiveTabState();
- state.groups[groupId] = tabIndex;
+ state.paths[path] = tabIndex;
window.sessionStorage.setItem('tab', JSON.stringify(state));
}
updateTabs: function(ev, root) {
(root || document).querySelectorAll('[data-tab-title]').forEach(function(pane) {
var menu = pane.parentNode.previousElementSibling,
- tab = menu.querySelector('[data-tab="%s"]'.format(pane.getAttribute('data-tab'))),
+ tab = menu ? menu.querySelector('[data-tab="%s"]'.format(pane.getAttribute('data-tab'))) : null,
n_errors = pane.querySelectorAll('.cbi-input-invalid').length;
+ if (!menu || !tab)
+ return;
+
if (L.dom.isEmpty(pane)) {
tab.style.display = 'none';
tab.classList.remove('flash');
if (L.dom.matches(pane, '[data-tab]')) {
if (pane.getAttribute('data-tab') === name) {
pane.setAttribute('data-tab-active', 'true');
- L.ui.tabs.setActiveTabId(groupId, index);
+ L.ui.tabs.setActiveTabId(pane, index);
}
else {
pane.setAttribute('data-tab-active', 'false');