diff options
author | hackademix | 2018-07-01 01:01:23 +0200 |
---|---|---|
committer | hackademix | 2018-07-01 01:01:23 +0200 |
commit | eceae7187a6f0e9510bc1165f6977256b87f490f (patch) | |
tree | d943f1ec73c09efa70954dcedb55eac82a726148 /src/lib/flextabs.js | |
download | noscript-eceae7187a6f0e9510bc1165f6977256b87f490f.tar.gz noscript-eceae7187a6f0e9510bc1165f6977256b87f490f.tar.xz noscript-eceae7187a6f0e9510bc1165f6977256b87f490f.zip |
Initial commit starting at version 10.1.8.3rc4.
Diffstat (limited to 'src/lib/flextabs.js')
-rw-r--r-- | src/lib/flextabs.js | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/lib/flextabs.js b/src/lib/flextabs.js new file mode 100644 index 0000000..12842c5 --- /dev/null +++ b/src/lib/flextabs.js @@ -0,0 +1,68 @@ +(function(root, factory) { + if (typeof define === 'function' && define.amd) { + define([], factory); + } else if (typeof module === 'object' && module.exports) { + module.exports = factory(); + } else { + root.flextabs = factory(); + } +}(this, function() { + + var flextabs = function(target) { + + var _ = {}; + + _.flextabs = target; + + _.toggle = _.flextabs.querySelectorAll('.flextabs__toggle'); + + _.content = _.flextabs.querySelectorAll('.flextabs__content'); + + _.reset = function() { + for (var i = 0; i < _.toggle.length; i += 1) { + _.toggle[i].classList.remove('flextabs__toggle--active--last'); + _.content[i].classList.remove('flextabs__content--active--last'); + } + }; + + _.activate = function() { + var i = Array.prototype.indexOf.call(_.toggle, this); + _.toggle[i].classList.toggle('flextabs__toggle--active'); + _.toggle[i].classList.add('flextabs__toggle--active--last'); + _.content[i].classList.toggle('flextabs__content--active'); + _.content[i].classList.add('flextabs__content--active--last'); + }; + + _.aria = function() { + for (var i = 0; i < _.toggle.length; i += 1) { + var style = getComputedStyle(_.content[i]); + if (style.getPropertyValue('display') !== 'none') { + _.toggle[i].setAttribute('aria-expanded', true); + } else { + _.toggle[i].setAttribute('aria-expanded', false); + } + } + }; + + _.click = function(e) { + e.preventDefault(); + _.reset(); + _.activate.call(this); + _.aria(); + }; + + _.init = function() { + for (var i = 0; i < _.toggle.length; i += 1) { + window.addEventListener('load', _.aria); + window.addEventListener('resize', _.aria); + _.toggle[i].addEventListener('click', _.click); + } + }; + + return _; + + }; + + return flextabs; + +})); |