This repository was archived by the owner on Jun 1, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsprite.min.js
8 lines (8 loc) · 3.21 KB
/
sprite.min.js
1
2
3
4
5
6
7
8
/*
* Sprite - 1.0.1
* https://github.com/antonjb/Sprite
* Anton Ball
* MIT license
* @license
*/
!function(a){"use strict";var b="1.0.1",c=function(){},d=function(a,b){for(var c=[],d=0;b>d;d+=1)c.push([d*a.width,0,a.width,a.height]);return c},e=function(){var a,b,c,d="object"==typeof arguments[0]?arguments[0]:{},e=arguments.length;for(a=0;e>a;a+=1)if(b=arguments[a],null!==b)for(c in b)d[c]=b[c];return d},f=function(a){return!isNaN(parseFloat(a))&&isFinite(a)},g=function(a){return"[object Array]"===Object.prototype.toString.call(a)};!function(){for(var a=0,b=["ms","moz","webkit","o"],c=0;c<b.length&&!window.requestAnimationFrame;++c)window.requestAnimationFrame=window[b[c]+"RequestAnimationFrame"],window.cancelAnimationFrame=window[b[c]+"CancelAnimationFrame"]||window[b[c]+"CancelRequestAnimationFrame"];window.requestAnimationFrame||(window.requestAnimationFrame=function(b){var c=(new Date).getTime(),d=Math.max(0,16-(c-a)),e=window.setTimeout(function(){b(c+d)},d);return a=c+d,e}),window.cancelAnimationFrame||(window.cancelAnimationFrame=function(a){clearTimeout(a)})}();var h=function(a,b){function c(){e.value=requestAnimationFrame(c);var f=(new Date).getTime(),g=f-d;g>=b&&(a.call(),d=(new Date).getTime())}if(!(window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame&&window.mozCancelRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame))return window.setInterval(a,b);var d=(new Date).getTime(),e={};return e.value=requestAnimationFrame(c),e},i=function(a){window.cancelAnimationFrame?window.cancelAnimationFrame(a.value):window.webkitCancelAnimationFrame?window.webkitCancelAnimationFrame(a.value):window.webkitCancelRequestAnimationFrame?window.webkitCancelRequestAnimationFrame(a.value):window.mozCancelRequestAnimationFrame?window.mozCancelRequestAnimationFrame(a.value):window.oCancelRequestAnimationFrame?window.oCancelRequestAnimationFrame(a.value):window.msCancelRequestAnimationFrame?window.msCancelRequestAnimationFrame(a.value):window.clearInterval(a)},j=function(a,b,k){var l,m,n,o,p=!1,q=0;this.el=a,this.options=e({},j.defaults,k),this.numFrames=b.length?b.length:Math.floor(k.imageWidth/b.width)*Math.floor(k.imageHeight/b.height),m=g(b)?b:d(b,this.numFrames),l=e({},this.options);var r=function(a){this.el.style.backgroundPosition=-a[0]+"px "+-a[1]+"px"};this.isPlaying=function(){return p},this.frame=function(a){return f(a)&&q!==a&&(q=a<this.numFrames?a:q,r.call(this,m[q])),q},this.play=function(a){if(p)return this;var b=e({onComplete:c,onFrame:c},this.options,a),d=this,f=0;o=0,q=this.frame(b.from||q),l=e({},b);var g=function(){q=(b.reverse?d.numFrames+(q-1):q+1)%d.numFrames,r.call(d,m[q]),b.onFrame.call(d,q,f),q===(b.from||0)&&(f+=1,b.loop&&f!==b.loop||(d.stop(),b.onComplete.call(d))),o+=1};return p=!0,n=h(g,1e3/b.fps),this},this.stop=function(a){var b=this;return p?(a=e({onComplete:c,frame:q,animated:!1},a),a.frame=f(a.frame)?a.frame:q,i(n),p=!1,a.animated?this.play({reverse:l.reverse,fps:l.fps,onFrame:function(c){a.frame===c&&b.stop({onComplete:a.onComplete})}}):(this.frame(a.frame),a.onComplete.call(this)),this):this}};j.toString=function(){return"Sprite version "+this.version},j.version=b,j.defaults={fps:12,loop:!0,reverse:!1},a.Sprite=j}(this);