mirror of https://github.com/twbs/ratchet.git
Build mobile apps with simple HTML, CSS, and JS components.
http://goratchet.com/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.4 KiB
49 lines
1.4 KiB
12 years ago
|
/* ----------------------------------
|
||
11 years ago
|
* TABS v1.0.0
|
||
12 years ago
|
* Licensed under The MIT License
|
||
|
* http://opensource.org/licenses/MIT
|
||
|
* ---------------------------------- */
|
||
|
|
||
|
!function () {
|
||
|
var getTarget = function (target) {
|
||
11 years ago
|
var i, popovers = document.querySelectorAll('.segmented-controller li a');
|
||
12 years ago
|
for (; target && target !== document; target = target.parentNode) {
|
||
11 years ago
|
for (i = popovers.length; i--;) { if (popovers[i] === target) return target; }
|
||
12 years ago
|
}
|
||
|
};
|
||
|
|
||
|
window.addEventListener("touchend", function (e) {
|
||
|
var activeTab;
|
||
12 years ago
|
var activeBodies;
|
||
12 years ago
|
var targetBody;
|
||
11 years ago
|
var targetTab;
|
||
11 years ago
|
var className = 'active';
|
||
12 years ago
|
var classSelector = '.' + className;
|
||
11 years ago
|
var targetAnchor = getTarget(e.target);
|
||
12 years ago
|
|
||
11 years ago
|
if (!targetAnchor) return;
|
||
12 years ago
|
|
||
11 years ago
|
targetTab = targetAnchor.parentNode;
|
||
12 years ago
|
activeTab = targetTab.parentNode.querySelector(classSelector);
|
||
|
|
||
|
if (activeTab) activeTab.classList.remove(className);
|
||
|
|
||
|
targetTab.classList.add(className);
|
||
|
|
||
11 years ago
|
if (!targetAnchor.hash) return;
|
||
12 years ago
|
|
||
11 years ago
|
targetBody = document.querySelector(targetAnchor.hash);
|
||
12 years ago
|
|
||
|
if (!targetBody) return;
|
||
|
|
||
12 years ago
|
activeBodies = targetBody.parentNode.querySelectorAll(classSelector);
|
||
12 years ago
|
|
||
12 years ago
|
for (var i = 0; i < activeBodies.length; i++) {
|
||
12 years ago
|
activeBodies[i].classList.remove(className);
|
||
12 years ago
|
}
|
||
12 years ago
|
|
||
12 years ago
|
targetBody.classList.add(className);
|
||
12 years ago
|
});
|
||
|
|
||
|
window.addEventListener('click', function (e) { if (getTarget(e.target)) e.preventDefault(); });
|
||
|
}();
|