UNPKG

spin-js-lite

Version:

Super lite Node Module containing the excellent spin.js and little more on top!

1 lines 4.09 kB
(function(e,t){if(typeof exports=="object")window.Spinner=t()})(this,function(){"use strict";function r(e,t){var n=document.createElement(e||"div"),r;for(r in t)n[r]=t[r];return n}function i(e){for(var t=1,n=arguments.length;t<n;t++)e.appendChild(arguments[t]);return e}function o(e,r,i,o){var u=["opacity",r,~~(e*100),i,o].join("-"),a=.01+i/o*100,f=Math.max(1-(1-e)/r*(100-a),e),l=n.substring(0,n.indexOf("Animation")).toLowerCase(),c=l&&"-"+l+"-"||"";if(!t[u]){s.insertRule("@"+c+"keyframes "+u+"{"+"0%{opacity:"+f+"}"+a+"%{opacity:"+e+"}"+(a+.01)+"%{opacity:1}"+(a+r)%100+"%{opacity:"+e+"}"+"100%{opacity:"+f+"}"+"}",s.cssRules.length);t[u]=1}return u}function u(t,n){var r=t.style,i,s;n=n.charAt(0).toUpperCase()+n.slice(1);for(s=0;s<e.length;s++){i=e[s]+n;if(r[i]!==undefined)return i}if(r[n]!==undefined)return n}function a(e,t){for(var n in t)e.style[u(e,n)||n]=t[n];return e}function f(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)if(e[r]===undefined)e[r]=n[r]}return e}function l(e,t){return typeof e=="string"?e:e[t%e.length]}function h(e){this.opts=f(e||{},h.defaults,c)}function p(){function e(e,t){return r("<"+e+' xmlns="urn:schemas-microsoft.com:vml" class="spin-vml">',t)}s.addRule(".spin-vml","behavior:url(#default#VML)");h.prototype.lines=function(t,n){function o(){return a(e("group",{coordsize:s+" "+s,coordorigin:-r+" "+ -r}),{width:s,height:s})}function h(t,s,u){i(f,i(a(o(),{rotation:360/n.lines*t+"deg",left:~~s}),i(a(e("roundrect",{arcsize:n.corners}),{width:r,height:n.width,left:n.radius,top:-n.width>>1,filter:u}),e("fill",{color:l(n.color,t),opacity:n.opacity}),e("stroke",{opacity:0}))))}var r=n.length+n.width,s=2*r;var u=-(n.width+n.length)*2+"px",f=a(o(),{position:"absolute",top:u,left:u}),c;if(n.shadow)for(c=1;c<=n.lines;c++)h(c,-2,"progid:DXImageTransform.Microsoft.Blur(pixelradius=2,makeshadow=1,shadowopacity=.3)");for(c=1;c<=n.lines;c++)h(c);return i(t,f)};h.prototype.opacity=function(e,t,n,r){var i=e.firstChild;r=r.shadow&&r.lines||0;if(i&&t+r<i.childNodes.length){i=i.childNodes[t+r];i=i&&i.firstChild;i=i&&i.firstChild;if(i)i.opacity=n}}}var e=["webkit","Moz","ms","O"],t={},n;var s=function(){var e=r("style",{type:"text/css"});i(document.getElementsByTagName("head")[0],e);return e.sheet||e.styleSheet}();var c={lines:12,length:7,width:5,radius:10,rotate:0,corners:1,color:"#000",direction:1,speed:1,trail:100,opacity:1/4,fps:20,zIndex:2e9,className:"spinner",top:"50%",left:"50%",position:"absolute"};h.defaults={};f(h.prototype,{spin:function(e){this.stop();var t=this,i=t.opts,s=t.el=a(r(0,{className:i.className}),{position:i.position,width:0,zIndex:i.zIndex});a(s,{left:i.left,top:i.top});if(e){e.insertBefore(s,e.firstChild||null)}s.setAttribute("role","progressbar");t.lines(s,t.opts);if(!n){var o=0,u=(i.lines-1)*(1-i.direction)/2,f,l=i.fps,c=l/i.speed,h=(1-i.opacity)/(c*i.trail/100),p=c/i.lines;(function d(){o++;for(var e=0;e<i.lines;e++){f=Math.max(1-(o+(i.lines-e)*p)%c*h,i.opacity);t.opacity(s,e*i.direction+u,f,i)}t.timeout=t.el&&setTimeout(d,~~(1e3/l))})()}return t},stop:function(){var e=this.el;if(e){clearTimeout(this.timeout);if(e.parentNode)e.parentNode.removeChild(e);this.el=undefined}return this},lines:function(e,t){function c(e,n){return a(r(),{position:"absolute",width:t.length+t.width+"px",height:t.width+"px",background:e,boxShadow:n,transformOrigin:"left",transform:"rotate("+~~(360/t.lines*s+t.rotate)+"deg) translate("+t.radius+"px"+",0)",borderRadius:(t.corners*t.width>>1)+"px"})}var s=0,u=(t.lines-1)*(1-t.direction)/2,f;for(;s<t.lines;s++){f=a(r(),{position:"absolute",top:1+~(t.width/2)+"px",transform:t.hwaccel?"translate3d(0,0,0)":"",opacity:t.opacity,animation:n&&o(t.opacity,t.trail,u+s*t.direction,t.lines)+" "+1/t.speed+"s linear infinite"});if(t.shadow)i(f,a(c("#000","0 0 4px "+"#000"),{top:2+"px"}));i(e,i(f,c(l(t.color,s),"0 0 1px rgba(0,0,0,.1)")))}return e},opacity:function(e,t,n){if(t<e.childNodes.length)e.childNodes[t].style.opacity=n}});var d=a(r("group"),{behavior:"url(#default#VML)"});if(!u(d,"transform")&&d.adj)p();else n=u(d,"animation");return h})