/** * SciAnimator - Scientific Image Animator Plugin for jQuery * * Copyright (c) 2010 Brent Ertz * Released under the MIT license. * http://github.com/brentertz/scianimator */ (function(e){var c={CONTROLS_ALL:"all",CONTROLS_NONE:"none",DIRECTION_FORWARD:0,DIRECTION_REVERSE:1,LOOP_MODE_NONE:"none",LOOP_MODE_LOOP:"loop",LOOP_MODE_SWEEP:"sweep",PLAY_MODE_STOPPED:0,PLAY_MODE_PLAYING:1,POSITION_TOP:0,POSITION_BOTTOM:1};e.fn.scianimator=function(g){if(b[g]){return b[g].apply(this,Array.prototype.slice.call(arguments,1))}else{if(typeof g==="object"||!g){return b.init.apply(this,arguments)}else{e.error("Method "+g+" does not exist on jQuery.scianimator")}}};e.fn.scianimator.defaults={autoRefresh:false,keyboard:true,debug:false,images:[],controlContainer:null,controlPosition:c.POSITION_BOTTOM,controls:c.CONTROLS_ALL,defaultFrame:0,delay:250,delayStep:50,delayMin:25,delayMax:5000,dwellMultiplier:2,theme:"light",width:null,utf8:true,loopMode:c.LOOP_MODE_LOOP,labels:{text:{first:"First",previous:"Previous",play:"Play",stop:"Stop",next:"Next",last:"Last",loop:{tip:"Click to toggle loop mode",loop:"Loop",sweep:"Sweep",none:"None"},speed:{speed:"Speed",down:"-",up:"+"},navigator:{tip:"Click to go to frame; <ctrl>+click to enable/disable frame."},status:{preload:"Preloading images...",refresh:"Refreshing images from source..."}},utf8:{first:"|←",previous:"←",play:"►",stop:"■",next:"→",last:"→|"}}};var d={};var b={init:function(g){d=e.extend(true,{},e.fn.scianimator.defaults,g);a("init");return this.each(function(){var i=e(this);var h=i.data("scianimator");e(this).data("scianimator",{id:i[0].id,target:i,image:null,animationTimer:null,autoRefreshTimer:null,playMode:c.PLAY_MODE_STOPPED,frames:[],currentFrame:d.defaultFrame,firstFrame:0,lastFrame:null,disabledFrames:[],direction:c.DIRECTION_FORWARD,dwell:0,settings:d,controls:{}});i.scianimator("loadImages","preload").scianimator("container").scianimator("image").scianimator("controls").scianimator("calculateDwell")})},destroy:function(){a("destroy");return this.each(function(){var h=e(this);var g=h.data("scianimator");e(window).unbind(".scianimator");h.removeData("scianimator");window.clearTimeout(g.animationTimer);h.remove()})},drawImage:function(j){a("drawImage");var i=e(this);var g=i.data("scianimator");j=parseInt(j,10);var h=g.frames[j];e(g.image).load(function(){a("Loaded image for frame #"+j+" : "+h.src)}).error(function(){a("Image failed to load for frame #"+j+" : "+h.src);i.scianimator("enableDisable",{frame:j,state:"disable"})}).attr("src",h.src);return i},container:function(){a("container");var h=e(this);var g=h.data("scianimator");h.addClass("scianimator");if(g.settings.theme!==undefined){h.addClass(g.settings.theme)}if(g.settings.width!==undefined){h.css("width",g.settings.width)}return h},image:function(){a("image");var i=e(this);var h=i.data("scianimator");var g=e("");i.append(g[0]);h.image=g[0];if("number"===typeof h.settings.defaultFrame){i.scianimator("goto",h.settings.defaultFrame)}else{if("last"===h.settings.defaultFrame){i.scianimator("last")}else{i.scianimator("first")}}return i},controls:function(){a("controls");var k=e(this);var j=k.data("scianimator");var h=e('
');if(j.settings.theme!==undefined){h.addClass(j.settings.theme)}var i=e("");var g={first:function(){var l=(j.settings.utf8)?j.settings.labels.utf8.first:j.settings.labels.text.first;return e(''+l+"")},previous:function(){var l=(j.settings.utf8)?j.settings.labels.utf8.previous:j.settings.labels.text.previous;return e(''+l+"")},play:function(){var l=(j.settings.utf8)?j.settings.labels.utf8.play:j.settings.labels.text.play;return e(''+l+"")},next:function(){var l=(j.settings.utf8)?j.settings.labels.utf8.next:j.settings.labels.text.next;return e(''+l+"")},last:function(){var l=(j.settings.utf8)?j.settings.labels.utf8.last:j.settings.labels.text.last;return e(''+l+"")},navigator:function(){var l=e('');var m=j.settings.labels.text.navigator.tip;e.each(j.frames,function(n,o){l.append(' ')});return l},loop:function(){var l=(j.settings.utf8&&j.settings.labels.utf8.loop!==undefined)?j.settings.labels.utf8.loop[j.settings.loopMode]:j.settings.labels.text.loop[j.settings.loopMode];var m=j.settings.labels.text.loop.tip;return e(''+l+"")},speed:function(){var m=(j.settings.utf8&&j.settings.labels.utf8.speed!==undefined)?j.settings.labels.utf8.speed.speed:j.settings.labels.text.speed.speed;var l=(j.settings.utf8&&j.settings.labels.utf8.speed!==undefined)?j.settings.labels.utf8.speed.up:j.settings.labels.text.speed.up;var n=(j.settings.utf8&&j.settings.labels.utf8.speed!==undefined)?j.settings.labels.utf8.speed.down:j.settings.labels.text.speed.down;return e(''+n+" '+l+"")}};h.delegate("form","submit",function(l){l.preventDefault()}).delegate("a","click",function(l){l.preventDefault();switch(l.target.id){case j.id+"-first":k.scianimator("first");break;case j.id+"-previous":k.scianimator("previous");break;case j.id+"-play":k.scianimator("playOrStop");break;case j.id+"-next":k.scianimator("next");break;case j.id+"-last":k.scianimator("last");break;case j.id+"-loop":k.scianimator("loopMode");break;case j.id+"-speed-down":k.scianimator("speedDown");break;case j.id+"-speed-up":k.scianimator("speedUp");break}}).delegate("a.navigator","click",function(l){l.preventDefault();var n=j.id+"-navigator-";if((l.target.id).indexOf(n)!=-1){var m=parseInt((l.target.id).substring(n.length),10);if(l.metaKey){k.scianimator("enableDisable",{frame:m})}else{k.scianimator("goto",m)}}});if(e.isArray(j.settings.controls)&&j.settings.controls.length>0){e.each(j.settings.controls,function(l,m){i.append(g[m]);j.controls[m]=g[m]()[0].id})}else{if(c.CONTROLS_ALL===j.settings.controls){e.each(g,function(l,m){i.append(m);j.controls[l]=m()[0].id})}else{a("Display no controls")}}if(!e(i).is(":empty")){h.append(i);if(j.settings.controlContainer!==null){if(c.POSITION_TOP===j.settings.controlPosition){e(j.settings.controlContainer).prepend(container)}else{e(j.settings.controlContainer).append(container)}}else{if(c.POSITION_TOP===j.settings.controlPosition){k.prepend(h)}else{k.append(h)}}}if(j.settings.keyboard===true){k.scianimator("keyboard")}k.scianimator("onControlsComplete");return k},keyboard:function(){a("keyboard");var h=e(this);var g=h.data("scianimator");e(document).bind("keydown.scianimator.controls",function(i){if(i.target.tagName!="INPUT"&&i.target.tagName!="TEXTAREA"){switch(i.keyCode){case 13:case 32:h.scianimator("playOrStop");break;case 37:if(i.shiftKey){h.scianimator("first")}else{h.scianimator("previous")}break;case 39:if(i.shiftKey){h.scianimator("last")}else{h.scianimator("next")}break}}})},onControlsComplete:function(){a("onControlsComplete");var h=e(this);var g=h.data("scianimator");h.scianimator("hilightCurrent")},playOrStop:function(){a("playOrStop");var h=e(this);var g=h.data("scianimator");if(c.PLAY_MODE_PLAYING===g.playMode){h.scianimator("stop")}else{if(c.PLAY_MODE_STOPPED===g.playMode){h.scianimator("play")}}return h},play:function(){a("play");var j=e(this);var i=j.data("scianimator");i.playMode=c.PLAY_MODE_PLAYING;var h=i.settings.delay;if(c.DIRECTION_FORWARD===i.direction){if(i.currentFrame===i.firstFrame||i.currentFrame===i.lastFrame){h=i.dwell}}a("delay: "+h);i.animationTimer=self.setTimeout(function(){j.scianimator("animate")},h);var g=(i.settings.utf8)?i.settings.labels.utf8.stop:i.settings.labels.text.stop;e("#"+i.controls.play).removeClass("play").addClass("stop").html(g);return j},stop:function(){a("stop");var i=e(this);var h=i.data("scianimator");h.animationTimer=window.clearTimeout(h.animationTimer);h.playMode=c.PLAY_MODE_STOPPED;var g=(h.settings.utf8)?h.settings.labels.utf8.play:h.settings.labels.text.play;e("#"+h.controls.play).removeClass("stop").addClass("play").html(g);return i},animate:function(){a("animate");var h=e(this);var g=h.data("scianimator");if(c.DIRECTION_FORWARD===g.direction){h.scianimator("next")}else{if(c.DIRECTION_REVERSE===g.direction){h.scianimator("previous")}}if(c.PLAY_MODE_PLAYING===g.playMode){h.scianimator("play")}return h},previous:function(){a("previous");var h=e(this);var g=h.data("scianimator");g.currentFrame--;if(e.inArray(g.currentFrame,g.disabledFrames)!=-1){h.scianimator("previous");return h}a(g.firstFrame+":"+g.currentFrame+":"+g.lastFrame);if(g.currentFrame