-
Notifications
You must be signed in to change notification settings - Fork 0
/
SipuSlider.min.js
1 lines (1 loc) · 3.77 KB
/
SipuSlider.min.js
1
var SIPUSlider=function(t,e,a){"use strict";var n,i,o=[],s={Index:-1,SetAttrVal:"",SetFadeTime:.5,SetRangeMax:255,SetCanvasHeight:600,SetCanvasWidth:800,SetPlayInterval:50,SetImages:"",CanvasNode:"",ImageListNode:"",PlayButtonNode:"",StopButtonNode:"",RangeNode:"",OnPlaying:!1,OnPlayInterval:"",SetNode:function(){!function t(e){if(o[e].SetAttrVal.length>0)for(var a=0;a<n.length;a++)n[a].getAttribute("data-sipu-canvas")===o[e].SetAttrVal&&(o[e].CanvasNode=n[a]),n[a].getAttribute("data-sipu-images")===o[e].SetAttrVal&&(o[e].ImageListNode=n[a]),n[a].getAttribute("data-sipu-playbutton")===o[e].SetAttrVal&&(o[e].PlayButtonNode=n[a]),n[a].getAttribute("data-sipu-stopbutton")===o[e].SetAttrVal&&(o[e].StopButtonNode=n[a]),n[a].getAttribute("data-sipu-range")===o[e].SetAttrVal&&(o[e].RangeNode=n[a])}(this.Index)},ValidCheck:function(){if("object"==typeof this.CanvasNode&&"object"==typeof this.ImageListNode&&"object"==typeof this.PlayButtonNode&&"object"==typeof this.StopButtonNode&&"object"==typeof this.RangeNode)return!0},init:function(){if(this.SetNode(),this.ValidCheck()){this.ImageListNode.style.display="none";var t,a,n,i,s,d=function(t){var a,n,i;o[a=t].CanvasNode.style.width=o[a].SetCanvasWidth||640,o[a].CanvasNode.style.height=o[a].SetCanvasHeight||480,e(o[n=t].CanvasNode).css("-webkit-transition","all "+o[n].SetFadeTime+"s ease-in-out"),e(o[n].CanvasNode).css("-moz-transition","all "+o[n].SetFadeTime+"s ease-in-out"),e(o[n].CanvasNode).css("-o-transition","all "+o[n].SetFadeTime+"s ease-in-out"),e(o[n].CanvasNode).css("transition","all "+o[n].SetFadeTime+"s ease-in-out"),o[i=t].RangeNode.value=1,o[i].RangeNode.setAttribute("min",1),o[i].RangeNode.setAttribute("max",o[i].SetRangeMax),e(o[i].RangeNode).on("change mousemove input",function(){l(o[i].CanvasNode,1,o[i].SetRangeMax,this.value,o[i].SetImages,o[i].SetCanvasHeight,o[i].SetCanvasWidth)}),function t(a){e(o[a].PlayButtonNode).click(function(){if(!1===o[a].OnPlaying){var t=o[a].RangeNode.value;o[a].OnPlaying=!0,o[a].SetPlayInterval=setInterval(function(){o[a].RangeNode.value=t,t++,l(o[a].CanvasNode,1,o[a].SetRangeMax,t,o[a].SetImages,o[a].SetCanvasHeight,o[a].SetCanvasWidth),t===parseInt(o[a].RangeNode.getAttribute("max"))&&(t=o[a].RangeNode.value,clearInterval(o[a].SetPlayInterval),o[a].OnPlaying=!1)},o[a].OnPlayInterval||20)}})}(t),function t(a){e(o[a].StopButtonNode).click(function(){o[a].OnPlaying=!1,clearInterval(o[a].SetPlayInterval)})}(t),l(o[t].CanvasNode,1,o[t].SetRangeMax,1,o[t].SetImages,o[t].SetCanvasHeight,o[t].SetCanvasWidth)};this.SetImages=(t=this.Index,a=d,n=e(o[t].ImageListNode).find("img"),i=0,s=Array(n.length),void e.each(n,function(e){var l=new Image;l.onload=function(){if(s[e]=l,++i===n.length)return o[t].SetImages=s,a(t)},l.src=n[e].src}))}else console.log("Failed Build "+this.SetAttrVal)}};function l(t,e,a,n,i,o,s){var l=t.getContext("2d");l.canvas.height=o,l.canvas.width=s,l.imageSmoothingEnabled=!1,l.mozImageSmoothingEnabled=!1;var d=Math.ceil(n/(a/(i.length-1))),g=Math.ceil(n/(a/(i.length-1)))-n/(a/(i.length-1));l.drawImage(i[d-1],0,0,i[d-1].width,i[d-1].height,0,0,s,o),l.globalAlpha=1-g,l.drawImage(i[d],0,0,i[d].width,i[d].height,0,0,s,o),l.globalAlpha=g}return t.run=function(){n=function t(){for(var e=[],a=document.getElementsByTagName("*"),n=0;n<a.length;n++)if(a[n].attributes.length>0)for(var i=a[n].attributes,o=0;o<i.length;o++){var s=i[o].name.split("-");"data"===s[0]&&"sipu"===s[1]&&e.push(a[n])}return e}(),i=function t(){for(var e=[],a=n,i=0;i<a.length;i++)if(a[i].attributes.length>0)for(var o=a[i].attributes,s=0;s<o.length;s++){var l=o[s].name.split("-");if("data"===l[0]&&"sipu"===l[1]){var d=o[s].nodeValue;-1===e.indexOf(d)&&e.push(d)}}return e}(),function t(){for(var e=0;e<i.length;e++)o.push(s),o[e].SetAttrVal=i[e],o[e].Index=e,o[e].init()}()},t}(window.SIPUSlider||{},jQuery);SIPUSlider.run();