Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Native Javascript for Bootstrap 3
- // by dnp_theme
- "strict mode";
- if(!String.prototype.trim) {
- String.prototype.trim = function() {
- return this.replace(/^\s+|\s+$/g, "");
- };
- }
- if(!Element.prototype.matches) {
- Element.prototype.matches = Element.prototype.matchesSelector || Element.prototype.mozMatchesSelector || Element.prototype.msMatchesSelector || Element.prototype.oMatchesSelector || Element.prototype.webkitMatchesSelector || function(s) {
- var matches = (this.document || this.ownerDocument).querySelectorAll(s);
- var i = matches.length;
- while(--i >= 0 && matches.item(i) !== this);
- return i > -1;
- };
- }
- Element.prototype.hasClass = function(cls) {
- return (" " + this.className + " ").indexOf(" " + cls + " ") > -1;
- };
- Element.prototype.addClass = function(cls) {
- if(!this.hasClass(cls)) {
- if(this.className) {
- this.className += " " + cls;
- } else {
- this.className = cls;
- }
- }
- };
- Element.prototype.removeClass = function(cls) {
- if(this.hasClass(cls)) {
- var classes = this.className.split(" ");
- classes.splice(classes.indexOf(cls), 1);
- this.className = classes.join(" ");
- }
- };
- // EventListener | CC0 | github.com/jonathantneal/EventListener
- this.Element&&Element.prototype.attachEvent&&!Element.prototype.addEventListener&&function(){function e(e,t){Window.prototype[e]=HTMLDocument.prototype[e]=Element.prototype[e]=t}function t(e){t.interval&&document.body&&(t.interval=clearInterval(t.interval),document.dispatchEvent(new CustomEvent("DOMContentLoaded")))}e("addEventListener",function(e,t){var n=this,r=n._c1_listeners=n._c1_listeners||{},o=r[e]=r[e]||[];o.length||n.attachEvent("on"+e,o.event=function(e){var t=n.document&&n.document.documentElement||n.documentElement||{scrollLeft:0,scrollTop:0};e.currentTarget=n,e.pageX=e.clientX+t.scrollLeft,e.pageY=e.clientY+t.scrollTop,e.preventDefault=function(){e.returnValue=!1},e.relatedTarget=e.fromElement||null,e.stopImmediatePropagation=function(){l=!1,e.cancelBubble=!0},e.stopPropagation=function(){e.cancelBubble=!0},e.target=e.srcElement||n,e.timeStamp=+new Date;for(var r,c=0,a=[].concat(o),l=!0;l&&(r=a[c]);++c)for(var i,u=0;i=o[u];++u)if(i==r){i.call(n,e);break}}),o.push(t)}),e("removeEventListener",function(e,t){for(var n,r=this,o=r._c1_listeners=r._c1_listeners||{},c=o[e]=o[e]||[],a=c.length-1;n=c[a];--a)if(n==t){c.splice(a,1);break}!c.length&&c.event&&r.detachEvent("on"+e,c.event)}),e("dispatchEvent",function(e){var t=this,n=e.type,r=t._c1_listeners=t._c1_listeners||{},o=r[n]=r[n]||[];try{return t.fireEvent("on"+n,e)}catch(c){return void(o.event&&o.event(e))}}),Object.defineProperty(Window.prototype,"CustomEvent",{get:function(){var e=this;return function(t,n){n=n||{};var r,o=e.document.createEventObject();o.type=t,o.returnValue=!n.cancelable,o.cancelBubble=!n.bubbles;for(r in n)o[r]=n[r];return o}}}),t.interval=setInterval(t,1),window.addEventListener("load",t)}();try{new window.CustomEvent("?")}catch(e){!function(){window.CustomEvent=function(e,t){var n;t=t||{bubbles:!1,cancelable:!1,detail:void 0};try{n=document.createEvent("CustomEvent"),n.initCustomEvent(e,t.bubbles,t.cancelable,t.detail)}catch(r){n=document.createEvent("Event"),n.initEvent(e,t.bubbles,t.cancelable),n.detail=t.detail}return n}}()}
- document.on = function(event, selector, handler) {
- if(!handler) {
- handler = selector;
- selector = false;
- }
- var handlerFunc;
- if(selector) {
- handlerFunc = function(e) {
- var target = e.target;
- while(target && target != document) {
- if(target.matches(selector)){
- e.currentTarget = target;
- handler.call(target, e);
- }
- target = target.parentNode;
- }
- };
- } else {
- handlerFunc = handler;
- }
- document.addEventListener(event, handlerFunc);
- };
- // AFFIX DEFINITION
- // ===================
- function Affix(el) {
- this.element = el;
- var self = this;
- this.init = function() {
- self.updateAffix();
- window.addEventListener("scroll", Affix.scrollHandler, false);
- window.addEventListener("resize", Affix.resizeHandler, false);
- };
- this.getTarget = function() {
- return document.querySelector(self.element.getAttribute("data-target"));
- };
- this.offsetTop = function() {
- if(self.getTarget() !== null) {
- return self.targetRect().top + self.scrollOffset();
- } else {
- return parseInt(self.element.getAttribute("data-offset-top"));
- }
- };
- this.offsetBottom = function () {
- return self.getMaxScroll() - self.elementHeight() - self.element.getAttribute("data-offset-bottom");
- };
- this.scrollOffset = function () {
- return window.pageYOffset || document.documentElement.scrollTop;
- };
- this.pinTop = function () {
- self.element.addClass("affix");
- };
- this.unPinTop = function () {
- self.element.removeClass("affix");
- };
- this.pinBottom = function () {
- self.element.addClass("affix-bottom");
- };
- this.unPinBottom = function () {
- self.element.removeClass("affix-bottom");
- };
- this.updatePin = function () {
- if(!self.element.hasClass("affix") && self.offsetTop() - self.scrollOffset() < 0) {
- self.pinTop();
- } else if(self.element.hasClass("affix") && self.scrollOffset() <= self.offsetTop()) {
- self.unPinTop();
- }
- if(!self.element.hasClass("affix-bottom") && self.offsetBottom() - self.scrollOffset() < 0) {
- self.pinBottom();
- } else if(self.element.hasClass("affix-bottom") && self.scrollOffset() <= self.offsetBottom()) {
- self.unPinBottom();
- }
- };
- this.updateAffix = function () {
- self.unPinTop();
- self.unPinBottom();
- self.updatePin();
- };
- this.elementHeight = function() {
- return self.element.offsetHeight;
- };
- this.targetRect = function(){
- return self.getTarget().getBoundingClientRect()
- };
- this.getMaxScroll = function() {
- return Math.max(document.body.scrollHeight, document.body.offsetHeight, document.documentElement.clientHeight, document.documentElement.scrollHeight, document.documentElement.offsetHeight);
- };
- this.on = function(par1, par2, par3) {
- this.element.addEventListener(par1, par2, par3);
- }
- }
- Affix.all = function(callback) {
- var elements = document.querySelectorAll('[data-spy="affix"]');
- for(var i = 0; i < elements.length; i++) {
- callback(new Affix(elements[i]));
- }
- };
- // AFFIX DATA API
- // =================
- Affix.scrollHandler = function() {
- Affix.all(function(affix) {
- affix.updatePin();
- });
- };
- Affix.resizeHandler = function() {
- Affix.all(function(affix) {
- setTimeout(function(){
- affix.updateAffix();
- }, 50);
- });
- };
- // ALERT DEFINITION
- // ===================
- function Alert(el) {
- this.element = el;
- var self = this;
- this.close = function() {
- var event = new CustomEvent("close.bs.alert", { "cancelable": true });
- self.element.dispatchEvent(event);
- if(!event.defaultPrevented) {
- if(self.element.hasClass("in")) {
- self.element.removeClass("in");
- setTimeout(function() {
- self._close();
- }, 150);
- } else {
- self._close();
- }
- }
- };
- this._close = function() {
- self.element.parentNode.removeChild(self.element);
- event = new CustomEvent("closed.bs.alert");
- self.element.dispatchEvent(event);
- }
- this.on = function(par1, par2, par3) {
- this.element.addEventListener(par1, par2, par3);
- }
- }
- Alert.all = function(callback) {
- var elements = document.querySelectorAll('.alert');
- for(var i = 0; i < elements.length; i++) {
- callback(new Alert(elements[i]));
- }
- };
- // ALERT DATA API
- // =================
- document.on("click", '[data-dismiss="alert"]', function(e) {
- var alert = this;
- while((alert = alert.parentNode) != document && !alert.hasClass("alert"));
- if(alert.hasClass("alert")) {
- new Alert(alert).close();
- e.preventDefault();
- }
- });
- // BUTTON DEFINITION
- // ===================
- function Button(el) {
- this.element = el;
- var self = this;
- this.setState = function(option) {
- if(!self.element.getAttribute("data-original-text")) {
- self.element.setAttribute("data-original-text", self.element.innerHTML.replace(/^\s+|\s+$/g, ""));
- }
- if(option === "loading") {
- self.element.addClass("disabled");
- self.element.disabled = true;
- }
- var text = self.element.getAttribute("data-" + option + "-text");
- if(text) {
- self.element.innerHTML = text
- }
- };
- this.reset = function() {
- if(self.element.disabled || self.element.hasClass("disabled")) {
- self.element.removeClass("disabled");
- self.element.disabled = false;
- }
- var text = self.element.getAttribute("data-original-text");
- if(text) {
- self.element.innerHTML = text;
- }
- };
- this.toggle = function(el) {
- var parent = el.parentNode;
- var label = el.tagName === "LABEL" ? el : parent.tagName === "LABEL" ? parent : null;
- if(label) {
- var target = self.element;
- labels = target.querySelectorAll(".btn");
- input = label.getElementsByTagName("INPUT")[0];
- if(input) {
- if(input.type === "checkbox") {
- if(input.checked) {
- label.removeClass("active");
- input.checked = false;
- } else {
- label.addClass("active");
- input.checked = true;
- }
- }
- if(input.type === "radio") {
- if(!input.checked) {
- label.addClass("active");
- input.checked = true;
- for(var i = 0; i < labels.length; i++) {
- var l = labels[i];
- if(l !== label && l.hasClass("active")) {
- var inp = l.getElementsByTagName("INPUT")[0];
- l.removeClass("active");
- inp.checked = false;
- }
- }
- }
- }
- }
- }
- };
- this.on = function(par1, par2, par3) {
- this.element.addEventListener(par1, par2, par3);
- }
- }
- Button.all = function(callback) {
- var elements = document.querySelectorAll('[data-toggle="button"],[data-toggle="buttons"]');
- for(var i = 0; i < elements.length; i++) {
- callback(new Button(elements[i]));
- }
- };
- // BUTTON DATA API
- // =================
- document.on("click", '.btn-group[data-toggle="buttons"]', function(e) {
- new Button(this).toggle(e.target);
- });
- // CAROUSEL DEFINITION
- // ===================
- function Carousel(el) {
- this.element = el;
- var self = this;
- this.init = function() {
- var interval = self.interval();
- if(interval) {
- self.cycle(interval);
- if(self.element.getAttribute("data-pause") != "false") {
- self.element.addEventListener("mouseenter", Carousel.pauseHandler, false);
- self.element.addEventListener("mouseleave", Carousel.resumeHandler, false);
- self.element.addEventListener("touchstart", Carousel.pauseHandler, false);
- self.element.addEventListener("touchend", Carousel.resumeHandler, false);
- } else {
- self.element.removeEventListener("mouseenter", Carousel.pauseHandler, false);
- self.element.removeEventListener("mouseleave", Carousel.resumeHandler, false);
- self.element.removeEventListener("touchstart", Carousel.pauseHandler, false);
- self.element.removeEventListener("touchend", Carousel.resumeHandler, false);
- }
- }
- };
- this._clearInterval = function(removeAttribute) {
- clearTimeout(self.element.getAttribute("data-timer"));
- var timer = self.element.getAttribute("data-timer");
- if(timer) {
- clearTimeout(timer);
- if(removeAttribute !== false) {
- self.element.removeAttribute("data-timer");
- }
- }
- };
- this.cycle = function(interval) {
- self._clearInterval(false);
- if(!interval) {
- interval = self.interval();
- }
- self.element.setAttribute("data-timer", setTimeout(function() {
- self.slideTo(self.getActiveIndex() + 1);
- }, interval));
- };
- this.slideTo = function(next, slides) {
- var event = new CustomEvent("slide.bs.carousel", { "cancelable": true });
- self.element.dispatchEvent(event);
- if(!event.defaultPrevented) {
- slides = slides || self.element.querySelectorAll(".item");
- var indicators = self.element.querySelectorAll(".carousel-indicators li");
- var active = self.getActiveIndex();
- self._clearInterval();
- var nextNorm = ((next % slides.length) + slides.length) % slides.length;
- indicators[active].removeClass("active");
- indicators[nextNorm].addClass("active");
- if(self.element.hasClass("slide")) {
- var direction;
- var dr;
- if(next > active) {
- direction = "left";
- dr = "next";
- } else {
- direction = "right";
- dr = "prev";
- }
- slides[nextNorm].addClass(dr);
- slides[nextNorm].offsetWidth;
- slides[nextNorm].addClass(direction);
- slides[active].addClass(direction);
- event = new CustomEvent("slid.bs.carousel");
- setTimeout(function() {
- slides[active].removeClass("active");
- slides[nextNorm].addClass("active");
- slides[nextNorm].removeClass(dr);
- slides[nextNorm].removeClass(direction);
- slides[active].removeClass(direction);
- if(self.interval() && !self.element.hasClass("paused")) {
- self.cycle();
- }
- self.element.dispatchEvent(event);
- }, self.duration() + 100);
- } else {
- for(var i = 0; i < slides.length; i++) {
- if(i == nextNorm) {
- slides[i].addClass("active");
- } else {
- slides[i].removeClass("active");
- }
- }
- setTimeout(function() {
- if(self.interval() && !self.element.hasClass("paused")) {
- self.cycle();
- }
- self.element.dispatchEvent(event);
- }, self.duration() + 100);
- }
- }
- };
- this.getActiveIndex = function() {
- var slides = self.element.querySelectorAll(".item");
- var retVal = -1;
- var i = 0;
- while(retVal == -1 && i < slides.length) {
- if(slides[i].hasClass("active")) {
- retVal = i;
- }
- i++;
- }
- return retVal;
- };
- this.interval = function(interval) {
- if(interval === undefined) {
- if(typeof self.element.getAttribute("data-interval") == "string" && self.element.getAttribute("data-interval") != "false") {
- return parseInt(self.element.getAttribute("data-interval")) || 5000;
- } else {
- return false;
- }
- }
- if(interval) {
- self.element.setAttribute("data-interval", interval);
- } else {
- self.element.removeAttribute("data-interval");
- }
- };
- this.duration = function(duration) {
- if(duration === undefined) {
- return parseInt(self.element.getAttribute("data-duration")) || 600;
- }
- if(duration) {
- self.element.setAttribute("data-duration", duration);
- } else {
- self.element.removeAttribute("data-duration");
- }
- };
- this.slideRight = function() {
- self.slideTo(self.getActiveIndex() + 1);
- };
- this.slideLeft = function() {
- self.slideTo(self.getActiveIndex() - 1);
- };
- this.on = function(par1, par2, par3) {
- this.element.addEventListener(par1, par2, par3);
- };
- }
- Carousel.all = function(callback) {
- var elements = document.querySelectorAll('[data-ride="carousel"]');
- for(var i = 0; i < elements.length; i++) {
- callback(new Carousel(elements[i]));
- }
- };
- // CAROUSEL DATA API
- // =================
- Carousel.pauseHandler = function(e) {
- if(this.matches('[data-ride="carousel"]')) {
- var carousel = new Carousel(this);
- if(carousel.interval() && !this.hasClass("paused")) {
- carousel._clearInterval();
- this.addClass("paused");
- }
- }
- };
- Carousel.resumeHandler = function(e) {
- if(this.matches('[data-ride="carousel"]')) {
- var carousel = new Carousel(this);
- if(carousel.interval() && this.hasClass("paused")) {
- this.removeClass("paused");
- carousel.cycle();
- }
- }
- };
- document.on("click", '.carousel-control', function(e) {
- var carousel = this;
- while(carousel != document && !carousel.matches('[data-ride="carousel"]')) {
- carousel = carousel.parentNode;
- }
- if(carousel.matches('[data-ride="carousel"]') && !carousel.hasClass("sliding")) {
- carousel = new Carousel(carousel);
- if(this.getAttribute("data-slide") == "prev") {
- carousel.slideLeft();
- } else {
- carousel.slideRight();
- }
- e.preventDefault();
- }
- });
- document.on("click", '[data-slide-to]', function(e) {
- var carousel = this;
- while(carousel != document && !carousel.matches('[data-ride="carousel"]')) {
- carousel = carousel.parentNode;
- }
- if(carousel.matches('[data-ride="carousel"]') && !carousel.hasClass("sliding")) {
- new Carousel(carousel).slideTo(parseInt(this.getAttribute("data-slide-to")) || 0);
- e.preventDefault();
- }
- });
- // COLLAPSE DEFINITION
- // ===================
- function Collapse(el) {
- this.element = el;
- var self = this;
- this.toggle = function() {
- var collapse = self.getTarget();
- if(!collapse.hasClass("collapsing")) {
- if(collapse.hasClass("in")) {
- self.close(collapse);
- } else {
- self.open(collapse);
- }
- }
- };
- this.close = function(collapse) {
- if(!collapse) {
- collapse = self.getTarget();
- }
- if(collapse.hasClass("in")) {
- self._close(collapse);
- self.element.removeClass("collapsed");
- }
- };
- this.open = function(collapse) {
- if(!collapse) {
- collapse = self.getTarget();
- }
- if(!collapse.hasClass("in")) {
- var event = new CustomEvent("show.bs.dropdown", { "cancelable": true });
- self.element.dispatchEvent(event);
- if(!event.defaultPrevented) {
- self._open(collapse);
- self.element.addClass("collapsed");
- var accordionSelector = self.element.getAttribute("data-parent");
- if(accordionSelector) {
- var accordion = self.element;
- while(accordion != document && !accordion.matches(accordionSelector)) {
- accordion = accordion.parentNode;
- }
- if(accordion.matches(accordionSelector)) {
- var active = accordion.querySelectorAll(".collapse.in");
- for(var i = 0; i < active.length; i++) {
- if(active[i] !== collapse) {
- event = new CustomEvent("hide.bs.collapse");
- self.element.dispatchEvent(event);
- self._close(active[i]);
- }
- }
- }
- }
- }
- }
- };
- this._open = function(c) {
- c.addClass("in");
- c.setAttribute("aria-expanded", true);
- c.addClass("collapsing");
- setTimeout(function() {
- c.style.height = self.getMaxHeight(c) + "px";
- c.style.overflowY = "hidden";
- }, 0);
- setTimeout(function() {
- c.style.height = "";
- c.style.overflowY = "";
- c.removeClass("collapsing");
- var event = new CustomEvent("shown.bs.dropdown");
- c.dispatchEvent(event);
- }, self.duration());
- };
- this._close = function(c) {
- c.setAttribute("aria-expanded", false);
- c.style.height = self.getMaxHeight(c) + "px";
- setTimeout(function() {
- c.style.height = "0px";
- c.style.overflowY = "hidden";
- c.addClass("collapsing");
- },0);
- setTimeout(function() {
- c.removeClass("collapsing");
- c.removeClass("in");
- c.style.overflowY = "";
- c.style.height = "";
- var event = new CustomEvent("hidden.bs.dropdown");
- c.dispatchEvent(event);
- }, self.duration());
- };
- this.getMaxHeight = function(l) {
- var retVal = 0;
- for(var i = 0; i < l.children.length; i++) {
- var el = l.children[i];
- var s = el && el.currentStyle || window.getComputedStyle(el);
- var btp = /px/.test(s.borderTopWidth) ? Math.round(s.borderTopWidth.replace("px", "")) : "0";
- var mtp = /px/.test(s.marginTop) ? Math.round(s.marginTop.replace("px", "")) : "0";
- var mbp = /px/.test(s.marginBottom) ? Math.round(s.marginBottom.replace("px", "")) : "0";
- var bbp = /px/.test(s.borderBottomWidth) ? Math.round(s.borderBottomWidth.replace("px", "")) : "0";
- var mte = /em/.test(s.marginTop) ? Math.round(s.marginTop.replace("em", "") * parseInt(s.fontSize)) : "0";
- var mbe = /em/.test(s.marginBottom) ? Math.round(s.marginBottom.replace("em", "") * parseInt(s.fontSize)) : "0";
- retVal += el.clientHeight + parseInt(btp) + parseInt(mtp) + parseInt(mbp) + parseInt(bbp) + parseInt(mte) + parseInt(mbe);
- }
- return retVal + 1;
- };
- this.getTarget = function() {
- var t = self.element;
- var h = t.href && t.getAttribute("href").replace("#", "");
- var d = t.getAttribute("data-target") && (t.getAttribute("data-target"));
- var id = h || (d && /#/.test(d)) && d.replace("#", "");
- var cl = (d && d.charAt(0) === ".") && d;
- return id && document.getElementById(id) || cl && document.querySelector(cl);
- };
- this.duration = function(duration) {
- if(duration === undefined) {
- return parseInt(self.element.getAttribute("data-duration")) || 300;
- }
- self.element.setAttribute("data-duration", duration);
- };
- this.on = function(par1, par2, par3) {
- this.element.addEventListener(par1, par2, par3);
- };
- }
- Collapse.all = function(callback) {
- var elements = document.querySelectorAll('[data-toggle="collapse"]');
- for(var i = 0; i < elements.length; i++) {
- callback(new Collapse(elements[i]));
- }
- }
- // COLLAPSE DATA API
- // =================
- document.on("click", '[data-toggle="collapse"]', function(e) {
- new Collapse(this).toggle();
- e.preventDefault();
- });
- // DROPDOWN DEFINITION
- // ===================
- function Dropdown(el) {
- this.element = el;
- var self = this;
- this.toggle = function() {
- if(self.element.parentNode.hasClass("open")) {
- self.close();
- } else {
- self.open();
- }
- };
- this.open = function() {
- if(!self.element.parentNode.hasClass("open")) {
- var event = new CustomEvent("show.bs.dropdown", { "cancelable": true });
- self.element.parentNode.dispatchEvent(event);
- if(!event.defaultPrevented) {
- if(!Dropdown.active) {
- document.addEventListener("keydown", Dropdown.keydownHandler, false);
- }
- Dropdown.active = self;
- self.element.parentNode.addClass("open");
- self.element.setAttribute("aria-expanded", true);
- vent = new CustomEvent("shown.bs.dropdown");
- self.element.parentNode.dispatchEvent(event);
- }
- }
- };
- this.close = function() {
- if(self.element.parentNode.hasClass("open")) {
- var event = new CustomEvent("hide.bs.dropdown");
- self.element.parentNode.dispatchEvent(event);
- if(self.element.parentNode.hasClass("open")) {
- if(Dropdown.active.element == self.element) {
- Dropdown.active = null;
- document.removeEventListener("keydown", Dropdown.keydownHandler, false);
- }
- self.element.parentNode.removeClass("open");
- self.element.setAttribute("aria-expanded", false);
- event = new CustomEvent("hidden.bs.dropdown");
- self.element.parentNode.dispatchEvent(event);
- }
- }
- };
- this.on = function(par1, par2, par3) {
- this.element.addEventListener(par1, par2, par3);
- };
- }
- Dropdown.all = function(callback) {
- var elements = document.querySelectorAll('[data-toggle="dropdown"]');
- for(var i = 0; i < elements.length; i++) {
- callback(new Dropdown(elements[i]));
- }
- };
- // DROPDOWN DATA API
- // =================
- Dropdown.keydownHandler = function(e) {
- if(Dropdown.active && e.which == 27) {
- Dropdown.active.close();
- }
- };
- document.on("click", '[data-toggle="dropdown"]', function(e) {
- new Dropdown(this).toggle();
- e.preventDefault();
- });
- document.on("click", function(e) {
- Dropdown.all(function(dropdown) {
- if(!dropdown.element.contains(e.target)) {
- dropdown.close();
- }
- });
- });
- // MODAL DEFINITION
- // ===================
- function Modal(el) {
- this.element = el;
- var self = this;
- this.open = function() {
- if(!self.element.hasClass("in")) {
- var event = new CustomEvent("show.bs.modal", { "cancelable": true });
- self.element.dispatchEvent(event);
- if(!event.defaultPrevented) {
- if(!Modal.active) {
- document.addEventListener("keydown", Modal.keydownHandler, false);
- window.addEventListener("resize", Modal.resizeHandler, false);
- }
- Modal.active = self;
- var currentOpen = document.querySelector(".modal.in");
- var duration = self.element.getAttribute("data-duration") || 300;
- if(currentOpen){
- clearTimeout(currentOpen.getAttribute("data-timer"));
- currentOpen.removeClass("in");
- setTimeout(function() {
- currentOpen.setAttribute("aria-hidden", true);
- currentOpen.style.display = "";
- }, duration / 2);
- }
- if(self.element.getAttribute("data-backdrop") != "false") {
- var overlay = self.createOverlay();
- setTimeout(function() {
- overlay.addClass("in");
- }, 0);
- }
- clearTimeout(self.element.getAttribute("data-timer"));
- self.element.setAttribute("data-timer", setTimeout(function() {
- self.element.style.display = "block";
- self.adjustDialog();
- self.setScrollbar();
- document.body.addClass("modal-open");
- self.element.addClass("in");
- self.element.setAttribute("aria-hidden", false);
- event = new CustomEvent("shown.bs.modal");
- self.element.dispatchEvent(event);
- }, duration / 2));
- }
- }
- };
- this.createOverlay = function() {
- var retVal = document.querySelector(".modal-backdrop");
- if(!retVal) {
- retVal = document.createElement("div");
- retVal.addClass("modal-backdrop");
- retVal.addClass("fade");
- document.body.appendChild(retVal);
- }
- return retVal;
- };
- this.close = function() {
- if(self.element.hasClass("in")) {
- var event = new CustomEvent("hide.bs.modal", { "cancelable": true });
- self.element.dispatchEvent(event);
- if(!event.defaultPrevented) {
- if(self.element.hasClass("in")) {
- if(Modal.active.element == self.element) {
- Modal.active = null;
- document.removeEventListener("keydown", Modal.keydownHandler, false);
- window.removeEventListener("resize", Modal.resizeHandler, false);
- }
- var overlay = document.querySelector(".modal-backdrop");
- if(overlay) {
- overlay.removeClass("in");
- }
- self.element.removeClass("in");
- self.element.setAttribute("aria-hidden", true);
- clearTimeout(self.element.getAttribute("data-timer"));
- var duration = self.element.getAttribute("data-duration") || 300;
- self.element.setAttribute("data-timer", setTimeout(function() {
- document.body.removeClass("modal-open");
- self.resetAdjustments();
- self.resetScrollbar();
- self.element.style.display = "";
- }, duration / 2));
- setTimeout(function() {
- if(!document.querySelector(".modal.in")) {
- self.removeOverlay(overlay);
- }
- event = new CustomEvent("hidden.bs.modal");
- self.element.dispatchEvent(event);
- }, duration);
- }
- }
- }
- };
- this.removeOverlay = function(overlay) {
- if(!overlay) {
- overlay = document.querySelector(".modal-backdrop");
- }
- if(overlay) {
- document.body.removeChild(overlay);
- }
- };
- this.content = function(content) {
- if(typeof content == "string") {
- return self.element.querySelector(".modal-content").innerHTML = content;
- } else {
- return self.element.querySelector(".modal-content").innerHTML;
- }
- };
- this.adjustDialog = function() {
- var htmlRect = document.documentElement.getBoundingClientRect();
- var bodyIsOverflowing = document.body.clientWidth < (window.innerWidth || (htmlRect.right - Math.abs(htmlRect.left)));
- var modalIsOverflowing = self.element.scrollHeight > document.documentElement.clientHeight;
- var scrollbarWidth = self.measureScrollbar();
- self.element.style.paddingLeft = !bodyIsOverflowing && modalIsOverflowing ? scrollbarWidth + 'px' : '';
- self.element.style.paddingRight = bodyIsOverflowing && !modalIsOverflowing ? scrollbarWidth + 'px' : '';
- };
- this.resetAdjustments = function() {
- self.element.style.paddingLeft = "";
- self.element.style.paddingRight = "";
- };
- this.setScrollbar = function() {
- var bodyStyle = document.body.currentStyle || window.getComputedStyle(document.body);
- var bodyPad = parseInt((bodyStyle.paddingRight), 10);
- var htmlRect = document.documentElement.getBoundingClientRect();
- if(document.body.clientWidth < (window.innerWidth || (htmlRect.right - Math.abs(htmlRect.left)))) {
- document.body.style.paddingRight = (bodyPad + self.measureScrollbar()) + "px";
- }
- };
- this.resetScrollbar = function() {
- document.body.style.paddingRight = "";
- };
- this.measureScrollbar = function() {
- var scrollDiv = document.createElement("div");
- scrollDiv.className = "modal-scrollbar-measure";
- document.body.appendChild(scrollDiv);
- var retVal = scrollDiv.offsetWidth - scrollDiv.clientWidth;
- document.body.removeChild(scrollDiv);
- return retVal;
- };
- this.on = function(par1, par2, par3) {
- this.element.addEventListener(par1, par2, par3);
- };
- }
- Modal.all = function(callback) {
- var elements = document.querySelectorAll('.modal');
- for(var i = 0; i < elements.length; i++) {
- callback(new Modal(elements[i]));
- }
- };
- // MODAL DATA API
- // =================
- Modal.keydownHandler = function(e) {
- if(Modal.active && e.which == 27 && Modal.active.element.getAttribute("data-keyboard") != "false") {
- Modal.active.close();
- }
- };
- Modal.resizeHandler = function(e) {
- if(Modal.active) {
- var overlay = document.querySelector(".modal-backdrop");
- if(overlay && overlay.hasClass("in")) {
- dim = {
- w: document.documentElement.clientWidth + "px",
- h: document.documentElement.clientHeight + "px"
- };
- overlay.style.height = dim.h;
- overlay.style.width = dim.w;
- Modal.active.adjustDialog();
- }
- }
- };
- document.on("click", '[data-toggle="modal"]', function(e) {
- new Modal(document.getElementById(this.getAttribute("data-target") && this.getAttribute("data-target").replace("#", "") || this.getAttribute("href") && this.getAttribute("href").replace("#", ""))).open();
- e.preventDefault();
- });
- document.on("click", '.modal', function(e) {
- if(e.target.parentNode.getAttribute("data-dismiss") === "modal" || e.target.getAttribute("data-dismiss") === "modal" || e.target === this) {
- new Modal(this).close();
- e.preventDefault();
- }
- });
- (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.Popover = factory();
- }
- })(function(){
- // POPOVER DEFINITION
- // ===================
- var Popover = function( element,options ) {
- options = options || {};
- this.isIE = (new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})").exec(navigator.userAgent) != null) ? parseFloat( RegExp.$1 ) : false;
- this.link = typeof element === 'object' ? element : document.querySelector(element);
- this.title = this.link.getAttribute('data-title') || null;
- this.content = this.link.getAttribute('data-content') || null;
- this.popover = null;
- this.options = {};
- this.options.template = options.template ? options.template : null;
- this.options.trigger = options.trigger ? options.trigger : 'hover';
- this.options.animation = options.animation && options.animation !== 'true' ? options.animation : 'true';
- this.options.placement = options.placement ? options.placement : 'top';
- this.options.delay = parseInt(options.delay) || 100;
- this.options.dismiss = options.dismiss && options.dismiss === 'true' ? true : false;
- this.duration = 150;
- this.options.duration = (this.isIE && this.isIE < 10) ? 0 : (options.duration || this.duration);
- this.options.container = document.body;
- if ( this.content || this.options.template ) this.init();
- this.timer = 0 // the link own event timer
- this.rect = null;
- }
- // POPOVER METHODS
- // ================
- Popover.prototype = {
- init : function() {
- this.actions();
- var events = ('onmouseleave' in this.link) ? [ 'mouseenter', 'mouseleave'] : [ 'mouseover', 'mouseout' ];
- if (this.options.trigger === 'hover') {
- this.link.addEventListener(events[0], this.open, false);
- if (!this.options.dismiss) { this.link.addEventListener(events[1], this.close, false); }
- } else if (this.options.trigger === 'click') {
- this.link.addEventListener('click', this.toggle, false);
- if (!this.options.dismiss) { this.link.addEventListener('blur', this.close, false); }
- } else if (this.options.trigger === 'focus') {
- this.link.addEventListener('focus', this.toggle, false);
- if (!this.options.dismiss) { this.link.addEventListener('blur', this.close, false); }
- }
- if (this.options.dismiss) { document.addEventListener('click', this.dismiss, false); }
- if (!(this.isIE && this.isIE < 9) ) { // dismiss on window resize
- window.addEventListener('resize', this.close, false );
- }
- },
- actions : function() {
- var self = this;
- this.toggle = function(e) {
- if (self.popover === null) {
- self.open()
- } else {
- self.close()
- }
- },
- this.open = function(e) {
- clearTimeout(self.link.getAttribute('data-timer'));
- self.timer = setTimeout( function() {
- if (self.popover === null) {
- self.createPopover();
- self.stylePopover();
- self.updatePopover()
- }
- }, self.options.duration );
- self.link.setAttribute('data-timer',self.timer);
- },
- this.dismiss = function(e) {
- if (self.popover && e.target === self.popover.querySelector('.close')) {
- self.close();
- }
- },
- this.close = function(e) {
- clearTimeout(self.link.getAttribute('data-timer'));
- self.timer = setTimeout( function() {
- if (self.popover && self.popover !== null && /in/.test(self.popover.className)) {
- self.popover.className = self.popover.className.replace(' in','');
- setTimeout(function() {
- self.removePopover(); // for performance/testing reasons we can keep the popovers if we want
- }, self.options.duration);
- }
- }, self.options.delay + self.options.duration);
- self.link.setAttribute('data-timer',self.timer);
- },
- //remove the popover
- this.removePopover = function() {
- this.popover && this.options.container.removeChild(this.popover);
- this.popover = null;
- this.timer = null
- },
- this.createPopover = function() {
- this.popover = document.createElement('div');
- if ( this.content !== null && this.options.template === null ) { //create the popover from data attributes
- this.popover.setAttribute('role','tooltip');
- var popoverArrow = document.createElement('div');
- popoverArrow.setAttribute('class','arrow');
- if (this.title !== null) {
- var popoverTitle = document.createElement('h3');
- popoverTitle.setAttribute('class','popover-title');
- if (this.options.dismiss) {
- popoverTitle.innerHTML = this.title + '<button type="button" class="close">×</button>';
- } else {
- popoverTitle.innerHTML = this.title;
- }
- this.popover.appendChild(popoverTitle);
- }
- var popoverContent = document.createElement('div');
- popoverContent.setAttribute('class','popover-content');
- this.popover.appendChild(popoverArrow);
- this.popover.appendChild(popoverContent);
- //set popover content
- if (this.options.dismiss && this.title === null) {
- popoverContent.innerHTML = this.content + '<button type="button" class="close">×</button>';
- } else {
- popoverContent.innerHTML = this.content;
- }
- } else { // or create the popover from template
- var template = document.createElement('div');
- template.innerHTML = this.options.template;
- this.popover.innerHTML = template.firstChild.innerHTML;
- }
- //append to the container
- this.options.container.appendChild(this.popover);
- this.popover.style.display = 'block';
- },
- this.stylePopover = function(pos) {
- this.rect = this.getRect();
- var placement = pos || this.options.placement;
- var animation = this.options.animation === 'true' ? 'fade' : '';
- this.popover.setAttribute('class','popover '+placement+' '+animation);
- var linkDim = { w: this.link.offsetWidth, h: this.link.offsetHeight }; //link real dimensions
- // all popover dimensions
- var pd = this.popoverDimensions(this.popover);
- var toolDim = { w : pd.w, h: pd.h }; //popover real dimensions
- //window vertical and horizontal scroll
- var scrollYOffset = this.getScroll().y;
- var scrollXOffset = this.getScroll().x;
- //apply styling
- if ( /top/.test(placement) ) { //TOP
- this.popover.style.top = this.rect.top + scrollYOffset - toolDim.h + 'px';
- this.popover.style.left = this.rect.left + scrollXOffset - toolDim.w/2 + linkDim.w/2 + 'px'
- } else if ( /bottom/.test(placement) ) { //BOTTOM
- this.popover.style.top = this.rect.top + scrollYOffset + linkDim.h + 'px';
- this.popover.style.left = this.rect.left + scrollXOffset - toolDim.w/2 + linkDim.w/2 + 'px';
- } else if ( /left/.test(placement) ) { //LEFT
- this.popover.style.top = this.rect.top + scrollYOffset - toolDim.h/2 + linkDim.h/2 + 'px';
- this.popover.style.left = this.rect.left + scrollXOffset - toolDim.w + 'px';
- } else if ( /right/.test(placement) ) { //RIGHT
- this.popover.style.top = this.rect.top + scrollYOffset - toolDim.h/2 + linkDim.h/2 + 'px';
- this.popover.style.left = this.rect.left + scrollXOffset + linkDim.w + 'px';
- }
- },
- this.updatePopover = function() {
- var placement = null;
- if ( !self.isElementInViewport(self.popover) ) {
- placement = self.updatePlacement();
- } else {
- placement = self.options.placement;
- }
- self.stylePopover(placement);
- self.popover.className += ' in';
- },
- this.updatePlacement = function() {
- var pos = this.options.placement;
- if ( /top/.test(pos) ) { //TOP
- return 'bottom';
- } else if ( /bottom/.test(pos) ) { //BOTTOM
- return 'top';
- } else if ( /left/.test(pos) ) { //LEFT
- return 'right';
- } else if ( /right/.test(pos) ) { //RIGHT
- return 'left';
- }
- },
- this.getRect = function() {
- return this.link.getBoundingClientRect()
- },
- this.getScroll = function() {
- return {
- y : window.pageYOffset || document.documentElement.scrollTop,
- x : window.pageXOffset || document.documentElement.scrollLeft
- }
- },
- this.popoverDimensions = function(p) {//check popover width and height
- return {
- w : p.offsetWidth,
- h : p.offsetHeight
- }
- },
- this.isElementInViewport = function(t) { // check if this.popover is in viewport
- var r = t.getBoundingClientRect();
- return (
- r.top >= 0 &&
- r.left >= 0 &&
- r.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
- r.right <= (window.innerWidth || document.documentElement.clientWidth)
- )
- }
- }
- }
- // POPOVER DATA API
- // =================
- var Popovers = document.querySelectorAll('[data-toggle=popover]'), i = 0, ppl = Popovers.length;
- for (i;i<ppl;i++){
- var item = Popovers[i], options = {};
- options.trigger = item.getAttribute('data-trigger'); // click / hover / focus
- options.animation = item.getAttribute('data-animation'); // true / false
- options.duration = item.getAttribute('data-duration');
- options.placement = item.getAttribute('data-placement');
- options.dismiss = item.getAttribute('data-dismiss');
- options.delay = item.getAttribute('data-delay');
- new Popover(item,options);
- }
- return Popover;
- });
- // PROGRESS DEFINITION
- // ===================
- function Progress(el) {
- this.element = el;
- var self = this;
- this._bar = function() {
- return self.element.querySelector(".progress-bar");
- };
- this.value = function(value, text) {
- var bar = self._bar();
- if(value === undefined) {
- return parseInt(bar.getAttribute("aria-valuenow") || bar.style.slice(0, -1));
- } else {
- bar.setAttribute("aria-valuenow", value);
- bar.style.width = value + "%";
- if(text) {
- bar.innerText = text;
- }
- }
- };
- this.on = function(par1, par2, par3) {
- this.element.addEventListener(par1, par2, par3);
- };
- }
- Progress.all = function(callback) {
- var elements = document.querySelectorAll('.progress');
- for(var i = 0; i < elements.length; i++) {
- callback(new Progress(elements[i]));
- }
- };
- // PROGRESS DATA API
- // =================
- // SCROLLSPY DEFINITION
- // ===================
- function ScrollSpy(el) {
- this.element = el;
- var self = this;
- this.init = function () {
- if(self.element.getAttribute("href") && self.element.getAttribute("href").indexOf("#") > -1 ) {
- this.refresh();
- this.scrollEvent();
- window.addEventListener("scroll", ScrollSpy.scrollHandler, false);
- window.addEventListener("resize", ScrollSpy.resizeHandler, false);
- }
- };
- this.topLimit = function () { // the target offset
- if ( this.scrollTarget === window ) {
- return this.tg.getBoundingClientRect().top + this.scrollOffset() - 5
- } else {
- return this.tg.offsetTop;
- }
- };
- this.bottomLimit = function () {
- return this.topLimit() + this.tg.clientHeight
- };
- this.scrollOffset = function () {
- if ( this.scrollTarget === window ) {
- return window.pageYOffset || document.documentElement.scrollTop
- } else {
- return this.element.scrollTop
- }
- };
- this.activate = function () {
- if ( this.parent && this.parent.tagName === 'LI' && !/active/.test(this.parent.className) ) {
- this.parent.addClass('active');
- if ( this.parentParent && this.parentParent.tagName === 'LI' // activate the dropdown as well
- && /dropdown/.test(this.parentParent.className)
- && !/active/.test(this.parentParent.className) ) {this.parentParent.addClass("active"); }
- this.active = true
- }
- };
- this.deactivate = function () {
- if ( this.parent && this.parent.tagName === 'LI' && /active/.test(this.parent.className) ) {
- this.parent.removeClass("active");
- if ( this.parentParent && this.parentParent.tagName === 'LI' // deactivate the dropdown as well
- && /dropdown/.test(this.parentParent.className)
- && /active/.test(this.parentParent.className) ) { this.parentParent.removeClass("active"); }
- this.active = false
- }
- };
- this.toggle = function () {
- if ( this.active === false
- && ( this.this.bottomLimit() > this.scrollOffset() && this.scrollOffset() >= this.topLimit() )) { //regular use, scroll just entered the element's topLimit or bottomLimit
- this.activate();
- } else if (this.active === true && (this.bottomLimit() <= this.scrollOffset() && this.scrollOffset() < this.topEdge )) {
- this.deactivate()
- }
- };
- this.refresh = function () { // check edges again
- this.deactivate();
- this.toggle() // If any case update values again
- };
- this.scollEvent = function(){
- var self = this;
- this.scrollTarget.addEventListener('scroll', onSpyScroll, false);
- function onSpyScroll() {
- self.refresh();
- }
- };
- this.resizeEvent = function(){
- var self = this;
- window.addEventListener('resize', onSpyResize, false);
- function onSpyResize() {
- self.refresh()
- }
- };
- this.scrollHeight = function() {
- if ( this.scrollTarget === window ) {
- return Math.max( document.body.scrollHeight, document.body.offsetHeight,
- document.documentElement.clientHeight, document.documentElement.scrollHeight, document.documentElement.offsetHeight );
- } else {
- return this.element.scrollHeight
- }
- };
- this.on = function(par1, par2, par3) {
- this.element.addEventListener(par1, par2, par3);
- }
- }
- ScrollSpy.all = function(callback) {
- var elements = document.querySelectorAll('[data-spy="scroll"]');
- for(var i = 0; i < elements.length; i++) {
- callback(new Alert(elements[i]));
- }
- };
- // SCROLLSPY DATA API
- // =================
- ScrollSpy.scrollHandler = function() {
- ScrollSypy.all(function(spy) {
- spy.refresh();
- });
- };
- ScrollSpy.resizeHandler = function() {
- ScrollSypy.all(function(spy) {
- spy.refresh();
- });
- };
- // TAB DEFINITION
- // ===================
- function Tab(el) {
- this.element = el;
- var self = this;
- this.action = function() {
- var tabs = self.element.parentNode.parentNode;
- var event = new CustomEvent("show.bs.tab", { "cancelable": true });
- self.element.parentNode.dispatchEvent(event);
- if(!event.defaultPrevented) {
- var activeTab = self.getActiveTab();
- event = new CustomEvent("hide.bs.tab");
- var newContent = document.getElementById(self.element.getAttribute("href").replace("#", ""));
- var activeContent = self.getActiveContent();
- var duration = self.element.getAttribute("data-duration") || 150;
- var dropdown;
- if(self.element.parentNode.parentNode.hasClass("dropdown-menu")) {
- tabs = tabs.parentNode.parentNode;
- dropdown = tabs.parentNode;
- } else {
- dropdown = tabs.querySelector(".dropdown");
- }
- if(!self.element.parentNode.hasClass("active")) {
- activeTab.removeClass("active");
- self.element.parentNode.addClass("active");
- if(dropdown) {
- if(!self.element.parentNode.parentNode.hasClass("dropdown-menu")) {
- dropdown.removeClass("active");
- } else {
- dropdown.addClass("active");
- }
- }
- activeContent.removeClass("in");
- setTimeout(function() {
- activeContent.removeClass("active");
- newContent.addClass("active");
- event = new CustomEvent("hidden.bs.tab");
- activeTab.dispatchEvent(event);
- }, duration);
- setTimeout(function() {
- newContent.addClass("in");
- event = new CustomEvent("shown.bs.tab");
- self.element.parentNode.dispatchEvent(event);
- }, duration * 2);
- }
- }
- };
- this.getActiveTab = function(tabs) {
- if(!tabs) {
- tabs = self.element.parentNode.parentNode;
- if(self.element.parentNode.parentNode.hasClass("dropdown-menu")) {
- tabs = tabs.parentNode.parentNode;
- }
- }
- var activeTabs = tabs.querySelectorAll(".active");
- if(activeTabs.length === 1 && !activeTabs[0].hasClass("dropdown")) {
- return activeTabs[0];
- } else if ( activeTabs.length > 1 ) {
- return activeTabs[activeTabs.length-1]
- }
- };
- this.getActiveContent = function() {
- var a = self.getActiveTab().getElementsByTagName("A")[0].getAttribute("href").replace("#", "");
- return a && document.getElementById(a)
- };
- this.on = function(par1, par2, par3) {
- this.element.addEventListener(par1, par2, par3);
- };
- }
- Tab.all = function(callback) {
- var elements = document.querySelectorAll('[data-toggle="tab"],[data-toggle="pill"]');
- for(var i = 0; i < elements.length; i++) {
- callback(new Tab(elements[i]));
- }
- };
- // TAB DATA API
- // =================
- document.on("click", "[data-toggle='tab'], [data-toggle='pill']", function(e) {
- new Tab(this).action();
- e.preventDefault();
- });
- window.addEventListener("load", function() {
- Carousel.all(function(carousel) {
- carousel.init();
- });
- Affix.all(function(affix) {
- affix.init();
- });
- /*Scrollspy.all(function(scrollspy) {
- scrollspy.init();
- });*/
- }, false);
Advertisement
Add Comment
Please, Sign In to add comment