-
Notifications
You must be signed in to change notification settings - Fork 1
/
flippy-framey.min.js
1 lines (1 loc) · 2.97 KB
/
flippy-framey.min.js
1
function flippyFramey(e){function n(){var n=window.setInterval(function(){if("undefined"==typeof l.images[l.index]){var i=l.scheme(l.index);console.log(i),l.images[l.index]=r(i)}l.index++,l.index>=e.frames&&(window.clearInterval(n),s.invoke.fetchCompletion())},e.rate||50)}function i(e){u.drawImage(e.image,0,0,e.width,e.height,0,0,s.canvasElement.width,s.canvasElement.height),s.invoke.draw()}function a(e){if(s.pendingUpgrade&&window.clearTimeout(s.pendingUpgrade),!e in l.images){var n=l.scheme(e),a=s.upgradeTries;l.images[e]=r(n),s.pendingUpgrade=window.setInterval(function(){d(n)?(i({image:l.images[e],width:l.width,height:l.height}),window.clearInterval(s.pendingUpgrade)):(a--,a||window.clearInterval(s.pendingUpgrade))},s.upgradeDelay)}else i({image:l.images[e],width:l.width,height:l.height});s.canUpgrade&&(s.pendingUpgrade&&window.clearTimeout(s.pendingUpgrade),s.pendingUpgrade=window.setTimeout(function(){var n=h.scheme(e);if(d(n))t(e);else{h.images[e]=r(n);var i=s.upgradeTries;window.clearTimeout(s.pendingUpgrade),s.pendingUpgrade=window.setInterval(function(){return d(n)?(t(e),s.invoke.upgradeSuccess(),void window.clearInterval(s.pendingUpgrade)):(i--,i?void 0:(window.clearInterval(s.pendingUpgrade),void s.invoke.upgradeFailure()))},s.upgradeDelay)}},s.upgradeDelay))}function t(e){s.canUpgrade&&i({image:h.images[e],width:h.width,height:h.height})}function r(e){var n=new Image;return n.src=e,n}function d(e){return r(e).complete}function o(e){e.forEach(function(e){e(s)})}function g(e){var n={};return"number"==typeof e.width&&e.width>0||(n.width="width should be a positive integer"),"number"==typeof e.height&&e.height>0||(n.height="height should be a positive integer"),("function"!=typeof e.scheme||"string"!=typeof e.scheme(1))&&(n.scheme="scheme should be a function which takes an integer and returns a string"),"number"!=typeof e.index&&(n.index="index should be an integer"),n}e=e||{};var s={on:{},stacks:{},invoke:{}};["upgradeSuccess","upgradeFailure","fetchCompletion","draw"].forEach(function(e){s.stacks[e]=[],s.on[e]=function(n){return"function"==typeof n&&s.stacks[e].push(n),s},s.invoke[e]=function(){o(s.stacks[e])}}),s.canvasId=e.canvas=e.canvas||"canvas";var c=s.canvasElement=document.getElementById(e.canvas),u=s.ctx=c.getContext("2d");if(!e.thumbs)return console.error("flippyFramey expects an object which specifies details regarding your thumbnail image set. See https://github.com/WilliamsNY/flippy-framey for more details"),void console.log("There are no sensible defaults we can assume. \nTerminating flippyFramey execution NOW.");var l=s.thumbs=e.thumbs;if(l.images=e.images||{},l.validated=g(l),Object.keys(l.validated).length&&console.error(l.validated),e.full){s.canUpgrade=!0;var h=s.full=e.full;h.images={},h.validated=g(h),Object.keys(h.validated).length&&console.error(h.validated),s.upgradeDelay=e.upgradeDelay||50,s.upgradeTries=e.upgradeTries||10}else s.canUpgrade=!1;return"function"==typeof e.callback&&e.callback(s),s.fetchThumbs=e.fetchThumbs||n,s.drawThumb=a,s}