* Copyright (C) 2015 Hakim El Hattab, http://hakim.se
*/
(function(t,e){"object"==typeofexports?module.exports=e(require("spin.js")):"function"==typeofdefine&&define.amd?define(["spin"],e):t.Ladda=e(t.Spinner)})(this,function(t){"use strict";functione(t){if(t===void0)returnconsole.warn("Ladda button target must be defined."),void0;t.querySelector(".ladda-label")||(t.innerHTML='<span class="ladda-label">'+t.innerHTML+"</span>");vare,n=t.querySelector(".ladda-spinner");n||(n=document.createElement("span"),n.className="ladda-spinner"),t.appendChild(n);varr,a={start:function(){returne||(e=o(t)),t.setAttribute("disabled",""),t.setAttribute("data-loading",""),clearTimeout(r),e.spin(n),this.setProgress(0),this},startAfter:function(t){returnclearTimeout(r),r=setTimeout(function(){a.start()},t),this},stop:function(){returnt.removeAttribute("disabled"),t.removeAttribute("data-loading"),clearTimeout(r),e&&(r=setTimeout(function(){e.stop()},1e3)),this},toggle:function(){returnthis.isLoading()?this.stop():this.start(),this},setProgress:function(e){e=Math.max(Math.min(e,1),0);varn=t.querySelector(".ladda-progress");0===e&&n&&n.parentNode?n.parentNode.removeChild(n):(n||(n=document.createElement("div"),n.className="ladda-progress",t.appendChild(n)),n.style.width=(e||0)*t.offsetWidth+"px")},enable:function(){returnthis.stop(),this},disable:function(){returnthis.stop(),t.setAttribute("disabled",""),this},isLoading:function(){returnt.hasAttribute("data-loading")},remove:function(){clearTimeout(r),t.removeAttribute("disabled",""),t.removeAttribute("data-loading",""),e&&(e.stop(),e=null);for(varn=0,i=u.length;i>n;n++)if(a===u[n]){u.splice(n,1);break}}};returnu.push(a),a}functionn(t,e){for(;t.parentNode&&t.tagName!==e;)t=t.parentNode;returne===t.tagName?t:void0}functionr(t){for(vare=["input","textarea","select"],n=[],r=0;e.length>r;r++)for(vara=t.getElementsByTagName(e[r]),i=0;a.length>i;i++)a[i].hasAttribute("required")&&n.push(a[i]);returnn}functiona(t,a){a=a||{};vari=[];"string"==typeoft?i=s(document.querySelectorAll(t)):"object"==typeoft&&"string"==typeoft.nodeName&&(i=[t]);for(varo=0,u=i.length;u>o;o++)(function(){vart=i[o];if("function"==typeoft.addEventListener){vars=e(t),u=-1;t.addEventListener("click",function(){vare=!0,i=n(t,"FORM");if(i!==void0)for(varo=r(i),d=0;o.length>d;d++)""===o[d].value.replace(/^\s+|\s+$/g,"")&&(e=!1),"checkbox"!==o[d].type&&"radio"!==o[d].type||o[d].checked||(e=!1);e&&(s.startAfter(1),"number"==typeofa.timeout&&(clearTimeout(u),u=setTimeout(s.stop,a.timeout)),"function"==typeofa.callback&&a.callback.apply(null,[s]))},!1)}})()}functioni(){for(vart=0,e=u.length;e>t;t++)u[t].stop()}functiono(e){varn,r=e.offsetHeight;0===r&&(r=parseFloat(window.getComputedStyle(e).height)),r>32&&(r*=.8),e.hasAttribute("data-spinner-size")&&(r=parseInt(e.getAttribute("data-spinner-size"),10)),e.hasAttribute("data-spinner-color")&&(n=e.getAttribute("data-spinner-color"));vara=12,i=.2*r,o=.6*i,s=7>i?2:3;returnnewt({color:n||"#fff",lines:a,radius:i,length:o,width:s,zIndex:"auto",top:"auto",left:"auto",className:""})}functions(t){for(vare=[],n=0;t.length>n;n++)e.push(t[n]);returne}varu=[];return{bind:a,create:e,stopAll:i}});