This repository has been archived by the owner on Oct 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rotator.js
1 lines (1 loc) · 7.51 KB
/
rotator.js
1
var $j=jQuery.noConflict();function ChangeImage(id,direction){var selector,active,next;if(direction===undefined){direction="next"}selector="#"+id;if(rotatorSettings[id]["intransition"]){debug(selector+" ChangeImage() called during transition period -> ignoring request");return}active=$j(selector+" img.active");if(direction=="next"){next=$j(active).next("img")}else if(direction=="previous"){next=$j(active).prev("img")}if(next.length){}else{if(direction=="next"){next=$j(selector+" img:first");rotatorSettings[id]["imagenumber"]=0}else{next=$j(selector+" img:last");rotatorSettings[id]["imagenumber"]=rotatorSettings[id]["totalnumimages"]+1}debug(selector+" imagenumber reset to "+rotatorSettings[id]["imagenumber"]);rotatorSettings[id]["cyclecount"]+=1;debug(selector+" completed cycle #"+rotatorSettings[id]["cyclecount"]+" of "+rotatorSettings[id]["cycles"]);if(rotatorSettings[id]["cycles"]>0&&rotatorSettings[id]["cycles"]==rotatorSettings[id]["cyclecount"]){StopRotator(id);return}}StartImageTransition(id);$j(next).addClass("next").fadeTo(rotatorSettings[id]["transition"],1,function(){$j(this).addClass("active");if(direction=="next"){rotatorSettings[id]["imagenumber"]+=1}else if(direction=="previous"){rotatorSettings[id]["imagenumber"]-=1}debug(selector+" imagenumber "+rotatorSettings[id]["imagenumber"]+": src="+$j(this).attr("src"));$j(selector+" .navigation .imagenumber").html(rotatorSettings[id]["imagenumber"]);EndImageTransition(id)});$j(active).removeClass("next").fadeTo(rotatorSettings[id]["transition"],0,function(){$j(this).removeClass("active")})}jQuery(document).ready(function($){var i,rotators=$j("div.simplerotator"),numRotators=rotators.size(),id,parent,rotatorid,self,imgRatio,windowWidth,windowHeight,imgWidth,imgHeight,delay;for(i=0;i<numRotators;i++){id=$j(rotators[i]).attr("id");rotatorSettings[id]["imagenumber"]=1;rotatorSettings[id]["intransition"]=false;rotatorSettings[id]["loadeventfired"]=false;$j("#"+id+" img.first").on("load",function(){if(rotatorSettings[id]["loadeventfired"]==true){return}rotatorSettings[id]["loadeventfired"]=true;parent=$j(this).parents("div.simplerotator")[0];rotatorid=$j(parent).attr("id");debug("#"+rotatorid+": running img.load() event for "+$j(this).attr("src"));if(rotatorSettings[rotatorid]["fullscreen"]){debug("#"+rotatorid+": initialising full screen rotator with offsets = T:"+rotatorSettings[rotatorid]["topoffset"]+" R:"+rotatorSettings[rotatorid]["rightoffset"]+" B:"+rotatorSettings[rotatorid]["bottomoffset"]+" L:"+rotatorSettings[rotatorid]["leftoffset"]+", losingside = "+rotatorSettings[rotatorid]["losingside"]+" and ensurefullscreen = "+rotatorSettings[rotatorid]["ensurefullscreen"]);$j("#"+rotatorid).css({position:"fixed",left:rotatorSettings[rotatorid]["leftoffset"],top:rotatorSettings[rotatorid]["topoffset"],"z-index":"-1"});self=$j(this);imgRatio=self.width()/self.height();function ResizeImage(){switch(rotatorSettings[rotatorid]["losingside"]){case"bottom":rotatorSettings[rotatorid]["bottomoffset"]=0;break;case"right":rotatorSettings[rotatorid]["rightoffset"]=0;break}windowWidth=$j(window).width()-rotatorSettings[rotatorid]["leftoffset"]-rotatorSettings[rotatorid]["rightoffset"];windowHeight=$j(window).height()-rotatorSettings[rotatorid]["topoffset"]-rotatorSettings[rotatorid]["bottomoffset"];switch(rotatorSettings[rotatorid]["losingside"]){case"bottom":imgWidth=windowWidth;imgHeight=imgWidth/imgRatio;if(rotatorSettings[rotatorid]["ensurefullscreen"]&&imgHeight<windowHeight){debug("#"+rotatorid+": White space detected between the bottom of the image and the bottom of the browser window -> increasing image height (potentially chopping off the right hand side of the image)");imgHeight=windowHeight;imgWidth=imgHeight*imgRatio}break;case"right":imgHeight=windowHeight;imgWidth=imgHeight*imgRatio;if(rotatorSettings[rotatorid]["ensurefullscreen"]&&imgWidth<windowWidth){debug("#"+rotatorid+": White space detected between the right hand side of the image and the right hand side of the browser window -> increasing image width (potentially chopping off the bottom side of the image)");imgWidth=windowWidth;imgHeight=imgWidth/imgRatio}break}debug("#"+rotatorid+": browser window dimensions: "+$j(window).width()+" x "+$j(window).height());debug("#"+rotatorid+": adjusted window dimensions: "+windowWidth+" x "+windowHeight);debug("#"+rotatorid+": imgHeight:"+imgHeight+", windowHeight:"+windowHeight);$j("#"+rotatorid+" img").width(imgWidth).height(imgHeight)}ResizeImage();$j(window).resize(ResizeImage)}$j(parent).css("height",$j(this).outerHeight(true)).css("width",$j(this).outerWidth(true));$j("#"+rotatorid+" img").removeClass("hidden first")});if(rotatorSettings[id]["loadeventfired"]==false&&$j("#"+id+" img.first").width()>0){$j("#"+id+" img.first").trigger("load")}if(rotatorSettings[id]["totalnumimages"]==1){continue}if(rotatorSettings[id]["shownavigation"]=="true"||rotatorSettings[id]["shownavigation"]=="onhover"){debug("#"+id+": navigation intialised");$j("#"+id+" .navigation").append("<ul>");$j("#"+id+" .navigation ul").append('<li class="nav prev enabled"><a href="#" title="Previous"><span>←</span></a></li>').append('<li class="imagenumbers"><span class="imagenumber">1</span> / <span class="totalimages">'+rotatorSettings[id]["totalnumimages"]+"</span></li>").append('<li class="nav next enabled"><a href="#" title="Next"><span>→</span></a></li>').append("</ul>");if(rotatorSettings[id]["shownavigation"]=="true"){$j("#"+id+" .navigation").show();debug("#"+id+": navigation always shown")}else if(rotatorSettings[id]["shownavigation"]=="onhover"){debug("#"+id+": navigation shown on hover only");$j("#"+id).hover(function(){debug("#"+id+": showing navigation");$j("#"+id+" .navigation").fadeIn()},function(){debug("#"+id+": hiding navigation");$j("#"+id+" .navigation").fadeOut()})}$j("div.simplerotator .navigation li.nav").click(function(e){e.preventDefault();if(!$j(this).hasClass("disabled")){id=$j(this).closest("div.simplerotator").attr("id");if(rotatorSettings[id]["stoponnavigationclick"])StopRotator(id);if($j(this).hasClass("prev"))ShowPrevious(id);else if($j(this).hasClass("next"))ShowNext(id)}})}delay=rotatorSettings[id]["startdelay"]-rotatorSettings[id]["interval"];if(delay>0){setTimeout("SetupRotator('"+id+"')",delay);debug("#"+id+": delaying the setup of this rotator for "+delay+"ms")}else{SetupRotator(id)}}});function SetupRotator(id){debug("#"+id+": set up rotator to run with interval = "+rotatorSettings[id]["interval"]+"ms transition = "+rotatorSettings[id]["transition"]+"ms");rotatorSettings[id]["intervalid"]=setInterval("ChangeImage('"+id+"')",rotatorSettings[id]["interval"]);rotatorSettings[id]["cyclecount"]=0}function StopRotator(id){if(rotatorSettings[id]["intervalid"]==0)return;clearInterval(rotatorSettings[id]["intervalid"]);rotatorSettings[id]["intervalid"]=0;debug("#"+id+" stopped after "+rotatorSettings[id]["cyclecount"]+" cycles")}function ShowNext(id){debug("#"+id+" ShowNext("+id+")");ChangeImage(id)}function ShowPrevious(id){debug("#"+id+" ShowPrevious("+id+")");ChangeImage(id,"previous")}function StartImageTransition(id){rotatorSettings[id]["intransition"]=true;if(rotatorSettings[id]["hidenavigationduringtransition"]){$j("#"+id+" .navigation ul li.nav").addClass("disabled").removeClass("enabled");debug("#"+id+": Hiding next/prev navigation buttons")}}function EndImageTransition(id){rotatorSettings[id]["intransition"]=false;if(rotatorSettings[id]["hidenavigationduringtransition"]){$j("#"+id+" .navigation ul li.nav").addClass("enabled").removeClass("disabled");debug("#"+id+": Showing next/prev navigation buttons")}}function debug(message){if(window.console){console.log(message)}}