1 |
2
|
Manuela
|
(function(a){if(typeof module!=="undefined"&&typeof exports=="object"){if(typeof window!="undefined"){module.exports=a()}else{module.exports=a}}else{window.Button=a()}})(function(){var c=function(h,i){this.btn=typeof h==="object"?h:document.querySelector(h);this.option=typeof i==="string"?i:null;this.init()};c.prototype={init:function(){var h=this;this.actions();if(/btn/.test(this.btn.className)){if(this.option&&this.option!=="reset"){this.state=this.btn.getAttribute("data-"+this.option+"-text")||null;!this.btn.getAttribute("data-original-text")&&this.btn.setAttribute("data-original-text",h.btn.innerHTML.replace(/^\s+|\s+$/g,""));this.setState()}else{if(this.option==="reset"){this.reset()}}}if(/btn-group/.test(this.btn.className)){this.btn.addEventListener("click",this.toggle,false)}},actions:function(){var i=this,h=(("CustomEvent" in window)&&window.dispatchEvent)?new CustomEvent("bs.button.change"):null;function j(k){if(h){k.dispatchEvent(h)}}this.setState=function(){if(this.option==="loading"){this.addClass(this.btn,"disabled");this.btn.setAttribute("disabled","disabled")}this.btn.innerHTML=this.state},this.reset=function(){if(/disabled/.test(i.btn.className)||i.btn.getAttribute("disabled")==="disabled"){this.removeClass(this.btn,"disabled");i.btn.removeAttribute("disabled")}i.btn.innerHTML=i.btn.getAttribute("data-original-text")},this.toggle=function(k){var t=k.target.parentNode,q=k.target.tagName==="LABEL"?k.target:t.tagName==="LABEL"?t:null;if(!q){return}var u=this,r=u.querySelectorAll(".btn"),s=r.length,m=0,o=q.getElementsByTagName("INPUT")[0];if(!o){return}if(o.type==="checkbox"){if(!o.checked){i.addClass(q,"active");o.getAttribute("checked");o.setAttribute("checked","checked");o.checked=true}else{i.removeClass(q,"active");o.getAttribute("checked");o.removeAttribute("checked");o.checked=false}j(o);j(i.btn)}if(o.type==="radio"){if(!o.checked){i.addClass(q,"active");o.setAttribute("checked","checked");o.checked=true;j(i.btn);j(o);for(m;m<s;m++){var p=r[m];if(p!==q&&/active/.test(p.className)){var n=p.getElementsByTagName("INPUT")[0];i.removeClass(p,"active");n.removeAttribute("checked");n.checked=false;j(n)}}}}},this.addClass=function(l,k){if(l.classList){l.classList.add(k)}else{l.className+=" "+k;l.offsetWidth}},this.removeClass=function(l,k){if(l.classList){l.classList.remove(k)}else{l.className=l.className.replace(k,"").replace(/^\s+|\s+$/g,"");l.offsetWidth}}}};var e=document.querySelectorAll("[data-toggle=button]"),f=0,b=e.length;for(f;f<b;f++){new c(e[f])}var d=document.querySelectorAll("[data-toggle=buttons]"),g=0,a=d.length;for(g;g<a;g++){new c(d[g])}return c});
|