Browse Source

Revert "Fixed "active" class bug with toggle"

This reverts commit 790d5300b0.
pull/839/head
thewax 9 years ago
parent
commit
5ca4ef5259
  1. 95
      js/segmented-controllers.js

95
js/segmented-controllers.js

@ -7,61 +7,64 @@
* ======================================================================== */ * ======================================================================== */
!(function () { !(function () {
'use strict'; 'use strict';
var getTarget = function (target) {
var i;
var segmentedControls = document.querySelectorAll('.segmented-control .control-item');
for (; target && target !== document; target = target.parentNode) {
for (i = segmentedControls.length; i--;) {
if (segmentedControls[i] === target) {
return target;
}
}
}
};
var tabTouchEnd = function (e) {
var activeTab;
var activeBodies;
var targetBody;
var targetTab = getTarget(e.target);
var className = 'active';
var classSelector = '.control-content.active';
var tabClassSelector = '.control-item.active';
if (!targetTab) {
return;
}
activeTab = targetTab.parentNode.querySelector(tabClassSelector); var getTarget = function (target) {
var i;
var segmentedControls = document.querySelectorAll('.segmented-control .control-item');
if (activeTab) { for (; target && target !== document; target = target.parentNode) {
activeTab.classList.remove(className); for (i = segmentedControls.length; i--;) {
if (segmentedControls[i] === target) {
return target;
} }
}
}
};
targetTab.classList.add(className); window.addEventListener('touchend', function (e) {
var activeTab;
var activeBodies;
var targetBody;
var targetTab = getTarget(e.target);
var className = 'active';
var classSelector = '.' + className;
if (!targetTab.hash) { if (!targetTab) {
return; return;
} }
targetBody = document.querySelector(targetTab.hash); activeTab = targetTab.parentNode.querySelector(classSelector);
if (!targetBody) { if (activeTab) {
return; activeTab.classList.remove(className);
} }
activeBodies = targetBody.parentNode.querySelectorAll(classSelector); targetTab.classList.add(className);
for (var i = 0; i < activeBodies.length; i++) { if (!targetTab.hash) {
activeBodies[i].classList.remove(className); return;
} }
targetBody = document.querySelector(targetTab.hash);
if (!targetBody) {
return;
}
activeBodies = targetBody.parentNode.querySelectorAll(classSelector);
for (var i = 0; i < activeBodies.length; i++) {
activeBodies[i].classList.remove(className);
}
targetBody.classList.add(className);
});
targetBody.classList.add(className); window.addEventListener('click', function (e) {
}; if (getTarget(e.target)) {
window.addEventListener('touchend', tabTouchEnd); e.preventDefault();
window.addEventListener("MSPointerUp", tabTouchEnd); }
});
window.addEventListener('click', function (e) { if (getTarget(e.target)) { preventDef(e); } });
}()); }());

Loading…
Cancel
Save