diff --git a/static/js/collapse-native.js b/static/js/collapse-native.js new file mode 100644 index 00000000..2da5eee2 --- /dev/null +++ b/static/js/collapse-native.js @@ -0,0 +1,204 @@ +// Native Javascript for Bootstrap 3 | Collapse +// by dnp_theme + +(function(factory){ + + // CommonJS/RequireJS and "native" compatibility + if(typeof module !== "undefined" && typeof exports == "object") { + // A commonJS/RequireJS environment + if(typeof window != "undefined") { + // Window and document exist, so return the factory's return value. + module.exports = factory(); + } else { + // Let the user give the factory a Window and Document. + module.exports = factory; + } + } else { + // Assume a traditional browser. + window.Collapse = factory(); + } + +})(function(){ + + // COLLAPSE DEFINITION + // =================== + var Collapse = function( element, options ) { + options = options || {}; + + this.btn = typeof element === 'object' ? element : document.querySelector(element); + this.accordion = null; + this.collapse = null; + this.duration = 300; // default collapse transition duration + this.options = {}; + this.options.duration = /ie/.test(document.documentElement.className) ? 0 : (options.duration || this.duration); + this.init(); + } + + // COLLAPSE METHODS + // ================ + Collapse.prototype = { + + init : function() { + this.actions(); + this.btn.addEventListener('click', this.toggle, false); + + // allows the collapse to expand + // ** when window gets resized + // ** or via internal clicks handers such as dropwowns or any other + document.addEventListener('click', this.update, false); + window.addEventListener('resize', this.update, false) + }, + + actions : function() { + var self = this; + + this.toggle = function(e) { + self.btn = self.getTarget(e).btn; + self.collapse = self.getTarget(e).collapse; + + if (!/in/.test(self.collapse.className)) { + self.open(e) + } else { + self.close(e) + } + }, + this.close = function(e) { + e.preventDefault(); + self.btn = self.getTarget(e).btn; + self.collapse = self.getTarget(e).collapse; + self._close(self.collapse); + self.btn.className = self.btn.className.replace(' collapsed',''); + }, + this.open = function(e) { + e.preventDefault(); + self.btn = self.getTarget(e).btn; + self.collapse = self.getTarget(e).collapse; + self.accordion = self.btn.getAttribute('data-parent') && self.getClosest(self.btn, self.btn.getAttribute('data-parent')); + + self._open(self.collapse); + self.btn.className += ' collapsed'; + + if ( self.accordion !== null ) { + var active = self.accordion.querySelectorAll('.collapse.in'), al = active.length, i = 0; + for (i;i {% endcompress %}