forked from konsultaner/jsMovie
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.jsmovie.1.4.4.min.js
1 lines (1 loc) · 12.6 KB
/
jquery.jsmovie.1.4.4.min.js
1
(function(g){var f={images:[],sequence:"",from:0,to:1,step:1,folder:"pic/",grid:{height:800,width:600,rows:1,columns:1},loader:{path:"img/loader4x4.png",height:40,width:40,rows:4,columns:4},fps:12,width:640,height:480,loadParallel:1,repeat:true,playOnLoad:false,performStop:true,playBackwards:false,showPreLoader:false,verbose:true,clipQueue:[]};var e={init:function(k){var l=g.extend(true,{},f);if(k!=undefined){g.extend(l,k)}return this.each(function(){var q=g(this).data("jsMovie");if(!q){g(this).data("settings",l);g(this).data("jsMovie",g(this));if(g(this).data("settings").sequence!==""){g(this).data("settings").images=[];var s;for(var p=parseInt(g(this).data("settings").from);p<=parseInt(g(this).data("settings").to);p=p+parseInt(g(this).data("settings").step)){var m=1;if(p>0){m=(Math.floor(Math.log(p)/Math.log(10))+1)}s=new RegExp("^(.*?)([#]{1,"+m+"}?)([^#]+)","g");var t=s.exec(g(this).data("settings").sequence);g(this).data("settings").images.push((t[1]+p+t[3]).replace(/#/g,"0"))}}g(this).data("restoreCss",{width:g(this).width(),height:g(this).height(),overflow:g(this).css("overflow")});g(this).css({width:g(this).data("settings").width,height:g(this).data("settings").height,overflow:"hidden"});g(this).data("currentFrame",g(this));var o=0;for(var r=0;r<g(this).data("settings").images.length;r++){for(var v=0;v<g(this).data("settings").grid.rows;v++){for(var n=0;n<g(this).data("settings").grid.columns;n++){g(this).data("frame"+o,g("<div class='jsMovieFrame' />"));g(this).append(g(this).data("frame"+o));g(this).data("currentFrame",g(this).data("frame"+o));g(this).data("currentFrame").hide();g(this).data("frame"+o).css({width:g(this).data("settings").width,height:g(this).data("settings").height,"background-position":(-g(this).data("settings").grid.width*n)+"px "+(-g(this).data("settings").grid.height*v)+"px","background-repeat":"no-repeat"}).data("frame",o+1);o++}}}g(this).data("currentStatus","stopped");g(this).bind("play",d);g(this).bind("stop",c);g(this).bind("pause",b);g(this).data("frame0")&&g(this).data("frame0").show();g(this).data("currentFrame",g(this).data("frame0"));g(this).data("currentFrame").css({"background-image":'url("'+g(this).data("settings").folder+g(this).data("settings").images[0]+'")'});g(this).append("<div id='jsMovie_event_overlay'></div>");g(this).append("<div id='jsMovie_image_preload_container'></div>");var u=g(this);g("#jsMovie_event_overlay").css({width:g(u).data("settings").width,height:g(u).data("settings").height*2,"margin-top":"-"+(g(u).data("settings").height*2)+"px"});a.apply(g(this));i.apply(g(this))}else{e.throwError(1)}})},option:function(k,l){if(l==undefined){return this.data("settings")[k]}else{this.data("settings")[k]=l;return this}},realFps:function(){return g(this).data("realFps")},play:function(k,m,n,o){if(this.data("loadStatus")!="loaded"){var l=this;this.bind("loaded.playDeferrer",function(){e.play.apply(l,[k,m,n,o])});return this}if(k===undefined||k===null){k=1}if(m===undefined||m===null){m=g(this).data("settings").images.length*g(this).data("settings").grid.rows*g(this).data("settings").grid.columns}if(n===undefined||n===null){n=g(this).data("settings").repeat}if(o===undefined){o=g(this).data("settings").performStop}g(this).data("currentStatus","play");g(this).trigger("play",[k,m,n,o]);return this},pause:function(){g(this).data("currentStatus","paused");g(this).trigger("pause");return this},stop:function(){g(this).data("currentStatus","stopped");g(this).trigger("stop");return this},gotoFrame:function(l){var k=this;g(this).find(".jsMovieFrame").each(function(m,n){if(l==g(this).data("frame")&&g(this).data("loaded")!==undefined){g(k).find(".jsMovieFrame").hide();g(k).data("currentFrame",g(this));g(k).data("currentFrame").show()}else{g(k).data("gotoFrameOnLoaded",l)}});return this},nextFrame:function(){if(g(this).data("currentFrame").next(".jsMovieFrame").length==0){g(this).data("frame0").show();g(this).data("currentFrame").hide();g(this).data("currentFrame",g(this).data("frame0"))}else{g(this).data("currentFrame").next().show();g(this).data("currentFrame").hide();g(this).data("currentFrame",g(this).data("currentFrame").next())}return this},previousFrame:function(){if(g(this).data("currentFrame").data("frame")!=1){g(this).data("currentFrame").prev().show();g(this).data("currentFrame").hide();g(this).data("currentFrame",g(this).data("currentFrame").prev())}else{g(this).data("currentFrame").siblings(".jsMovieFrame").last().show();g(this).data("currentFrame").hide();g(this).data("currentFrame",g(this).data("currentFrame").siblings(".jsMovieFrame").last())}return this},playClip:function(k,l,m){if(l===undefined){l=g(this).data("settings").repeat}if(k===undefined){e.play.apply(this)}if(m===undefined){m=true}if(typeof k=="object"){_clip=k}if(typeof k=="string"){_clip=e.getClip.apply(this,[k])}if(typeof k=="function"){_clip=k()}if(typeof k=="number"){if(k<0){k=0}if(k>this.data("settings").clipQueue.length){k=this.data("settings").clipQueue.length-1}_clip=this.data("settings").clipQueue[parseInt(k)]}if(_clip){if(this.data("settings").playBackwards){e.gotoFrame.apply(this,[_clip.end])}else{e.gotoFrame.apply(this,[_clip.start])}e.play.apply(this,[_clip.start,_clip.end,l,m])}else{e.throwError(3)}return this},playClips:function(){var l=this;if(this.data("settings").clipQueue.length<1){e.play.apply(this)}else{if(this.data("currentClip")===undefined){this.data("currentClip",l.data("settings").playBackwards?l.data("settings").clipQueue.length-1:0)}var k=this.data("settings").clipQueue[this.data("currentClip")<=0?this.data("settings").clipQueue.length-1:this.data("currentClip")-1];var m=this.data("settings").clipQueue[this.data("currentClip")];e.playClip.apply(this,[this.data("currentClip"),false]);this.bind("ended.playClips",function(n){g(this).unbind(".playClips");if(!(m.pause>0)){m.pause=0}e.gotoFrame.apply(g(this),[l.data("settings").playBackwards?m.start:m.end]);setTimeout(function(){if(l.data("settings").playBackwards){if(l.data("settings").repeat){l.data("currentClip",l.data("currentClip")<=0?l.data("settings").clipQueue.length-1:l.data("currentClip")-1);e.playClips.apply(l)}else{if(l.data("currentClip")>0){l.data("currentClip",l.data("currentClip")-1);e.playClips.apply(l)}}}else{if(l.data("settings").repeat){l.data("currentClip",l.data("currentClip")==l.data("settings").clipQueue.length-1?0:l.data("currentClip")+1);e.playClips.apply(l)}else{if(l.data("currentClip")<l.data("settings").clipQueue.length-1){l.data("currentClip",l.data("currentClip")+1);e.playClips.apply(l)}}}},g(this).data("settings").playBackwards?k.pause:m.pause)})}},addClip:function(l,o,k,n,m){if(n===undefined){n=0}if(m===undefined){m=g(this).data("settings").clipQueue.length}if(o>=1&&k<=g(this).data("settings").images.length*g(this).data("settings").grid.rows*g(this).data("settings").grid.columns&&m<=g(this).data("settings").clipQueue.length){newClip={name:l,start:o,end:k,pause:n};g(this).data("settings").clipQueue.splice(m,0,newClip)}else{e.throwError(2)}return this},getClip:function(k){for(var l in g(this).data("settings").clipQueue){if(g(this).data("settings").clipQueue[l].name==k){return g(this).data("settings").clipQueue[l]}}return undefined},removeClip:function(l){for(var k in g(this).data("settings").clipQueue){if(g(this).data("settings").clipQueue[k].name==l||g(this).data("settings").clipQueue[k]===l){}}return this},getClipQueue:function(){return g(this).data("settings").clipQueue},destroy:function(){return this.each(function(){g(this).children().remove();g(this).css(g(this).data("restoreCss"));clearInterval(g(this).data("playingInterval"));g(this).removeData()})},throwError:function(l){var k="";if(l!=undefined){if(l==1){k="This Objekt has already been initialized!"}else{if(l==2){k="Clip out of Range!"}else{if(l==3){k="Clip not Found!"}else{if(true){k="Unknown Error"}}}}}else{k="Unknown Error"}if(window.console){console.log(k)}else{alert(k)}return this}};function d(p,k,m,n,o){if(k===undefined||k<1){k=1}if(m===undefined||m>g(this).data("settings").images.length*g(this).data("settings").grid.rows*g(this).data("settings").grid.columns){m=g(this).data("settings").images.length*g(this).data("settings").grid.rows*g(this).data("settings").grid.columns}if(n===undefined){n=g(this).data("settings").repeat}if(o===undefined){o=true}if(g(this).data("currentStatus")=="play"){clearInterval(g(this).data("playingInterval"));g(this).data("currentStatus","playing");var l=this;g(this).data("playingInterval",setInterval(function(){if(g(l).data("realFpsTimeStamp")!=undefined){g(l).data("realFps",1/(((new Date()).getTime()-g(l).data("realFpsTimeStamp"))/1000))}else{g(l).data("realFps",g(l).data("settings").fps)}g(l).data("realFpsTimeStamp",(new Date()).getTime());if(g(l).data("settings").playBackwards){if(g(l).data("currentFrame").data("frame")==k&&!n){if(o){g(l).trigger("stop")}else{g(l).trigger("pause")}g(l).trigger("ended")}else{g(l).trigger("playing");if(g(l).data("currentFrame").data("frame")!=k){e.previousFrame.apply(g(l))}else{e.gotoFrame.apply(g(l),[m])}}}else{if(g(l).data("currentFrame").data("frame")==m&&!n){if(o){g(l).trigger("stop")}else{g(l).trigger("pause")}g(l).trigger("ended")}else{g(l).trigger("playing");if(g(l).data("currentFrame").data("frame")!=m){e.nextFrame.apply(g(l))}else{e.gotoFrame.apply(g(l),[k])}}}},1000/g(this).data("settings").fps))}}function c(k){clearInterval(g(this).data("playingInterval"));g(this).find(".jsMovieFrame").hide();g(this).data("currentFrame",g(this).data("frame0"));g(this).data("currentFrame").show();g(this).data("currentStatus","stop")}function b(k){clearInterval(g(this).data("playingInterval"))}function a(m){if(m==undefined){m=0;this.data("loadStatus","loading");for(loadParralelCount=1;loadParralelCount<=this.data("settings").loadParallel;loadParralelCount++){a.apply(g(this),[loadParralelCount])}return}if(m>this.data("settings").images.length){this.data("loadStatus","loaded");this.trigger("loaded");if(this.data("settings").playOnLoad){e.play.apply(g(this))}return}var l=new Image();var k=this;l.onload=function(){var p=g(k).data("settings").grid.rows*g(k).data("settings").grid.columns;for(var o=0;o<p;o++){g(k).data("frame"+(o+((m-1)*p))).css({"background-image":"url("+g(k).data("settings").folder+g(k).data("settings").images[m-1]+")"});g(k).data("frame"+(o+((m-1)*p))).data("loaded",true)}if(g(k).data("gotoFrameOnLoaded")!=undefined&&Math.ceil(g(k).data("gotoFrameOnLoaded")/p)==m){var n=g(k).data("gotoFrameOnLoaded");g(k).removeData("gotoFrameOnLoaded");e.gotoFrame.apply(g(k),[n])}a.apply(g(k),[m+k.data("settings").loadParallel]);j.apply(k,["Image #"+(m)+" has been loaded"]);h.apply(g(k))};l.src=g(this).data("settings").folder+g(this).data("settings").images[m-1];g("#jsMovie_image_preload_container").append(l);g(l).css({height:"1px",width:"1px"})}function i(){if(this.data("loadStatus")!="loaded"&&g(this).data("settings").showPreLoader){this.append("<div class='loaderOverlay' />").children(".loaderOverlay").css({"background-color":"black",opacity:0.8,height:this.outerHeight(false)+"px",width:this.outerWidth(false)+"px",position:"absolute",top:this.offset().top+"px",left:this.offset().left+"px"});this.append("<div class='loaderAnimation' />").children(".loaderAnimation").css({"background-image":"url("+g(this).data("settings").loader.path+")",height:g(this).data("settings").loader.height+"px",width:g(this).data("settings").loader.width+"px",position:"absolute",top:(this.offset().top+(this.height()/2)-(g(this).data("settings").loader.height/2))+"px",left:(this.offset().left+(this.width()/2)-(g(this).data("settings").loader.width/2))+"px","background-repeat":"no-repeat"});this.children(".loaderAnimation").data("currentFrame",0);var k=this;var l=setInterval(function(){if(k.data("loadStatus")=="loaded"){k.children(".loaderOverlay, .loaderAnimation").remove();clearInterval(l)}var m=k.children(".loaderAnimation").data("currentFrame");k.children(".loaderAnimation").css({"background-position":(-g(k).data("settings").loader.width*(m%g(k).data("settings").loader.columns))+"px "+(-g(k).data("settings").loader.height*Math.floor(m/g(k).data("settings").loader.columns))+"px"});k.children(".loaderAnimation").data("currentFrame",(m+1)%(g(k).data("settings").loader.rows*g(k).data("settings").loader.columns));h.apply(g(k))},100)}}function h(){this.children(".loaderOverlay").css({top:this.offset().top+"px",left:this.offset().left+"px"});this.children(".loaderAnimation").css({top:(this.offset().top+(this.height()/2)-(g(this).data("settings").loader.height/2))+"px",left:(this.offset().left+(this.width()/2)-(g(this).data("settings").loader.width/2))+"px"})}function j(k){this.trigger("verbose",k)}g.fn.jsMovie=function(k){if(e[k]){return e[k].apply(this,Array.prototype.slice.call(arguments,1))}else{if(typeof k==="object"||!k){return e.init.apply(this,arguments)}else{g.error("Method "+k+" does not exist on jQuery.jsMovie")}}}})(jQuery);