1//** Step Carousel Viewer- (c) Dynamic Drive DHTML code library: http://www.dynamicdrive.com 2//** Script Download/ http://www.dynamicdrive.com/dynamicindex4/stepcarousel.htm 3//** Usage Terms: http://www.dynamicdrive.com/notice.htm 4//** Current version (Sept 29th, 09'): 1.8 See http://www.dynamicdrive.com/dynamicindex4/stepcarouselchangelog.txt for details 5 6 7//jQuery.noConflict() 8 9var stepcarousel={ 10 ajaxloadingmsg: '<div style="margin: 1em; font-weight: bold"><img src="ajaxloadr.gif" style="vertical-align: middle" /> Fetching Content. Please wait...</div>', //customize HTML to show while fetching Ajax content 11 defaultbuttonsfade: 0.4, //Fade degree for disabled nav buttons (0=completely transparent, 1=completely opaque) 12 configholder: {}, 13 14 getCSSValue:function(val){ //Returns either 0 (if val contains 'auto') or val as an integer 15 return (val=="auto")? 0 : parseInt(val) 16 }, 17 18 getremotepanels:function($, config){ //function to fetch external page containing the panel DIVs 19 config.$belt.html(this.ajaxloadingmsg) 20 $.ajax({ 21 url: config.contenttype[1], //path to external content 22 async: true, 23 error:function(ajaxrequest){ 24 config.$belt.html('Error fetching content.<br />Server Response: '+ajaxrequest.responseText) 25 }, 26 success:function(content){ 27 config.$belt.html(content) 28 config.$panels=config.$gallery.find('.'+config.panelclass) 29 stepcarousel.alignpanels($, config) 30 } 31 }) 32 }, 33 34 getoffset:function(what, offsettype){ 35 return (what.offsetParent)? what[offsettype]+this.getoffset(what.offsetParent, offsettype) : what[offsettype] 36 }, 37 38 getCookie:function(Name){ 39 var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair 40 if (document.cookie.match(re)) //if cookie found 41 return document.cookie.match(re)[0].split("=")[1] //return its value 42 return null 43 }, 44 45 setCookie:function(name, value){ 46 document.cookie = name+"="+value 47 }, 48 49 fadebuttons:function(config, currentpanel){ 50 config.$leftnavbutton.fadeTo('fast', currentpanel==0? this.defaultbuttonsfade : 1) 51 config.$rightnavbutton.fadeTo('fast', currentpanel==config.lastvisiblepanel? this.defaultbuttonsfade : 1) 52 if (currentpanel==config.lastvisiblepanel){ 53 stepcarousel.stopautostep(config) 54 } 55 56 }, 57 58 addnavbuttons:function($, config, currentpanel){ 59 config.$leftnavbutton=$('<img src="'+config.defaultbuttons.leftnav[0]+'">').css({zIndex:50, position:'absolute', left:config.offsets.left+config.defaultbuttons.leftnav[1]+'px', top:config.offsets.top+config.defaultbuttons.leftnav[2]+'px', cursor:'hand', cursor:'pointer'}).attr({title:'Back '+config.defaultbuttons.moveby+' panels'}).appendTo('body') 60 config.$rightnavbutton=$('<img src="'+config.defaultbuttons.rightnav[0]+'">').css({zIndex:50, position:'absolute', left:config.offsets.left+config.$gallery.get(0).offsetWidth+config.defaultbuttons.rightnav[1]+'px', top:config.offsets.top+config.defaultbuttons.rightnav[2]+'px', cursor:'hand', cursor:'pointer'}).attr({title:'Forward '+config.defaultbuttons.moveby+' panels'}).appendTo('body') 61 config.$leftnavbutton.bind('click', function(){ //assign nav button event handlers 62 stepcarousel.stepBy(config.galleryid, -config.defaultbuttons.moveby) 63 }) 64 config.$rightnavbutton.bind('click', function(){ //assign nav button event handlers 65 stepcarousel.stepBy(config.galleryid, config.defaultbuttons.moveby) 66 }) 67 if (config.panelbehavior.wraparound==false){ //if carousel viewer should stop at first or last panel (instead of wrap back or forth) 68 this.fadebuttons(config, currentpanel) 69 } 70 return config.$leftnavbutton.add(config.$rightnavbutton) 71 }, 72 73 alignpanels:function($, config){ 74 var paneloffset=0 75 config.paneloffsets=[paneloffset] //array to store upper left offset of each panel (1st element=0) 76 config.panelwidths=[] //array to store widths of each panel 77 config.$panels.each(function(index){ //loop through panels 78 var $currentpanel=$(this) 79 $currentpanel.css({float: 'none', position: 'absolute', left: paneloffset+'px'}) //position panel 80 $currentpanel.bind('click', function(e){return config.onpanelclick(e.target)}) //bind onpanelclick() to onclick event 81 paneloffset+=stepcarousel.getCSSValue($currentpanel.css('marginRight')) + parseInt($currentpanel.get(0).offsetWidth || $currentpanel.css('width')) //calculate next panel offset
82 config.paneloffsets.push(paneloffset) //remember this offset 83 config.panelwidths.push(paneloffset-config.paneloffsets[config.paneloffsets.length-2]) //remember panel width 84 }) 85 config.paneloffsets.pop() //delete last offset (redundant) 86 var addpanelwidths=0 87 var lastpanelindex=config.$panels.length-1 88 config.lastvisiblepanel=lastpanelindex 89 for (var i=config.$panels.length-1; i>=0; i--){ 90 addpanelwidths+=(i==lastpanelindex? config.panelwidths[lastpanelindex] : config.paneloffsets[i+1]-config.paneloffsets[i]) 91 if (config.gallerywidth>addpanelwidths){ 92 config.lastvisiblepanel=i //calculate index of panel that when in 1st position reveals the very last panel all at once based on gallery width 93 } 94 } 95 config.$belt.css({width: paneloffset+'px'}) //Set Belt DIV to total panels' widths 96 config.currentpanel=(config.panelbehavior.persist)? parseInt(this.getCookie(config.galleryid+"persist")) : 0 //determine 1st panel to show by default 97 config.currentpanel=(typeof config.currentpanel=="number" && config.currentpanel<config.$panels.length)? config.currentpanel : 0 98 var endpoint=config.paneloffsets[config.currentpanel]+(config.currentpanel==0? 0 : config.beltoffset) 99 config.$belt.css({left: -endpoint+'px'}) 100 if (config.defaultbuttons.enable==true){ //if enable default back/forth nav buttons 101 var $navbuttons=this.addnavbuttons($, config, config.currentpanel) 102 $(window).bind("load resize", function(){ //refresh position of nav buttons when page loads/resizes, in case offsets weren't available document.oncontentload 103 config.offsets={left:stepcarousel.getoffset(config.$gallery.get(0), "offsetLeft"), top:stepcarousel.getoffset(config.$gallery.get(0), "offsetTop")} 104 config.$leftnavbutton.css({left:config.offsets.left+config.defaultbuttons.leftnav[1]+'px', top:config.offsets.top+config.defaultbuttons.leftnav[2]+'px'}) 105 config.$rightnavbutton.css({left:config.offsets.left+config.$gallery.get(0).offsetWidth+config.defaultbuttons.rightnav[1]+'px', top:config.offsets.top+config.defaultbuttons.rightnav[2]+'px'}) 106 }) 107 } 108 if (config.autostep && config.autostep.enable){ //enable auto stepping of Carousel? 109 var $carouselparts=config.$gallery.add(typeof $navbuttons!="undefined"? $navbuttons : null) 110 $carouselparts.bind('click', function(){ 111 config.autostep.status="stopped" 112 stepcarousel.stopautostep(config) 113 }) 114 $carouselparts.hover(function(){ //onMouseover 115 stepcarousel.stopautostep(config) 116 config.autostep.hoverstate="over" 117 }, function(){ //onMouseout 118 if (config.steptimer && config.autostep.hoverstate=="over" && config.autostep.status!="stopped"){ 119 config.steptimer=setInterval(function(){stepcarousel.autorotate(config.galleryid)}, config.autostep.pause) 120 config.autostep.hoverstate="out" 121 } 122 }) 123 config.steptimer=setInterval(function(){stepcarousel.autorotate(config.galleryid)}, config.autostep.pause) //automatically rotate Carousel Viewer 124 } //end enable auto stepping check 125 this.createpaginate($, config) 126 this.statusreport(config.galleryid) 127 config.oninit() 128 config.onslideaction(this) 129 }, 130 131 stepTo:function(galleryid, pindex){ /*User entered pindex starts at 1 for intuitiveness. Internally pindex still starts at 0 */ 132 var config=stepcarousel.configholder[galleryid] 133 if (typeof config=="undefined"){ 134 //alert("There's an error with your set up of Carousel Viewer \""+galleryid+ "\"!") 135 return 136 } 137 stepcarousel.stopautostep(config) 138 var pindex=Math.min(pindex-1, config.paneloffsets.length-1) 139 var endpoint=config.paneloffsets[pindex]+(pindex==0? 0 : config.beltoffset) 140 if (config.panelbehavior.wraparound==false && config.defaultbuttons.enable==true){ //if carousel viewer should stop at first or last panel (instead of wrap back or forth) 141 this.fadebuttons(config, pindex) 142 } 143 config.$belt.animate({left: -endpoint+'px'}, config.panelbehavior.speed, function(){config.onslideaction(this)}) 144 config.currentpanel=pindex 145 this.statusreport(galleryid) 146 }, 147 148 stepBy:function(galleryid, steps, isauto){ 149 var config=stepcarousel.configholder[galleryid] 150 if (typeof config=="undefined"){ 151 //alert("There's an error with your set up of Carousel Viewer \""+galleryid+ "\"!") 152 return 153 } 154 if (!isauto) //if stepBy() function isn't called by autorotate() function 155 stepcarousel.stopautostep(config) 156 var direction=(steps>0)? 'forward' : 'back' //If "steps" is negative, that means backwards 157 var pindex=config.currentpanel+steps //index of panel to stop at 158 if (config.panelbehavior.wraparound==false){ //if carousel viewer should stop at first or last panel (instead of wrap back or forth) 159 pindex=(direction=="back" && pindex<=0)? 0 : (direction=="forward")? Math.min(pindex, config.lastvisiblepanel) : pindex 160 if (config.defaultbuttons.enable==true){ //if default nav buttons are enabled, fade them in and out depending on if at start or end of carousel 161 stepcarousel.fadebuttons(config, pindex) 162 } 163 } 164 else{ //else, for normal stepBy behavior 165 if (pindex>config.lastvisiblepanel && direction=="forward"){ 166 //if destination pindex is greater than last visible panel, yet we're currently not at the end of the carousel yet 167 pindex=(config.currentpanel<config.lastvisiblepanel)? config.lastvisiblepanel : 0 168 } 169 else if (pindex<0 && direction=="back"){ 170 //if destination pindex is less than 0, yet we're currently not at the beginning of the carousel yet 171 pindex=(config.currentpanel>0)? 0 : config.lastvisiblepanel /*wrap around left*/ 172 } 173 } 174 var endpoint=config.paneloffsets[pindex]+(pindex==0? 0 : config.beltoffset) //left distance for Belt DIV to travel to 175 if (pindex==0 && direction=='forward' || config.currentpanel==0 && direction=='back' && config.panelbehavior.wraparound==true){ //decide whether to apply "push pull" effect 176 config.$belt.animate({left: -config.paneloffsets[config.currentpanel]-(direction=='forward'? 100 : -30)+'px'}, 'normal', function(){ 177 config.$belt.animate({left: -endpoint+'px'}, config.panelbehavior.speed, function(){config.onslideaction(this)}) 178 }) 179 } 180 else 181 config.$belt.animate({left: -endpoint+'px'}, config.panelbehavior.speed, function(){config.onslideaction(this)}) 182 config.currentpanel=pindex 183 this.statusreport(galleryid) 184 }, 185 186 autorotate:function(galleryid){ 187 var config=stepcarousel.configholder[galleryid] 188 this.stepBy(galleryid, config.autostep.moveby, true) 189 }, 190 191 stopautostep:function(config){ 192 clearTimeout(config.steptimer) 193 }, 194 195 statusreport:function(galleryid){ 196 var config=stepcarousel.configholder[galleryid] 197 if (config.statusvars.length==3){ //if 3 status vars defined 198 var startpoint=config.currentpanel //index of first visible panel 199 var visiblewidth=0 200 for (var endpoint=startpoint; endpoint<config.paneloffsets.length; endpoint++){ //index (endpoint) of last visible panel 201 visiblewidth+=config.panelwidths[endpoint] 202 if (visiblewidth>config.gallerywidth){ 203 break 204 } 205 } 206 startpoint+=1 //format startpoint for user friendiness 207 endpoint=(endpoint+1==startpoint)? startpoint : endpoint //If only one image visible on the screen and partially hidden, set endpoint to startpoint 208 var valuearray=[startpoint, endpoint, config.panelwidths.length] 209 for (var i=0; i<config.statusvars.length; i++){ 210 window[config.statusvars[i]]=valuearray[i] //Define variable (with user specified name) and set to one of the status values 211 config.$statusobjs[i].text(valuearray[i]+" ") //Populate element on page with ID="user specified name" with one of the status values 212 } 213 } 214 stepcarousel.selectpaginate($, galleryid) 215 }, 216 217 createpaginate:function($, config){ 218 if (config.$paginatediv.length==1){ 219 var $templateimg=config.$paginatediv.find('img["data-over"]:eq(0)') //reference first matching image on page
220 var controlpoints=[], controlsrc=[], imgarray=[], moveby=$templateimg.attr("data-moveby") || 1 221 var asize=(moveby==1? 0:1) + Math.floor((config.lastvisiblepanel+1) / moveby) //calculate # of pagination links to create 222 var imghtml=$('<div>').append($templateimg.clone()).html() //get HTML of first matching image 223 srcs=[$templateimg.attr('src'), $templateimg.attr('data-over'), $templateimg.attr('data-select')] //remember control's over and out, and selected image src 224 for (var i=0; i<asize; i++){ 225 var moveto=Math.min(i*moveby, config.lastvisiblepanel) 226 imgarray.push(imghtml.replace(/>$/, ' data-index="'+i+'" data-moveto="'+moveto+'" title="Move to Panel '+(moveto+1)+'">') +'\n') 227 controlpoints.push(moveto) //store panel index each control goes to when clicked on 228 } 229 var $controls=$('<span></span>').replaceAll($templateimg).append(imgarray.join('')).find('img') //replace template link with links and return them 230 $controls.css({cursor:'pointer'}) 231 config.$paginatediv.bind('click', function(e){ 232 var $target=$(e.target) 233 if ($target.is('img') && $target.attr('data-over')){ 234 stepcarousel.stepTo(config.galleryid, parseInt($target.attr('data-moveto'))+1) 235 } 236 }) 237 config.$paginatediv.bind('mouseover mouseout', function(e){ 238 var $target=$(e.target) 239 if ($target.is('img') && $target.attr('data-over')){ 240 if (parseInt($target.attr('data-index')) != config.pageinfo.curselected) //if this isn't the selected link 241 $target.attr('src', srcs[(e.type=="mouseover")? 1 : 0]) 242 } 243 }) 244 config.pageinfo={controlpoints:controlpoints, $controls:$controls, srcs:srcs, prevselected:null, curselected:null} 245 } 246 }, 247 248 249 selectpaginate:function($, galleryid){ 250 var config=stepcarousel.configholder[galleryid] 251 if (config.$paginatediv.length==1){ 252 for (var i=0; i<config.pageinfo.controlpoints.length; i++){ 253 if (config.pageinfo.controlpoints[i] <= config.currentpanel) //find largest control point that's less than or equal to current panel shown 254 config.pageinfo.curselected=i 255 } 256 if (typeof config.pageinfo.prevselected!=null) //deselect previously selected link (if found) 257 config.pageinfo.$controls.eq(config.pageinfo.prevselected).attr('src', config.pageinfo.srcs[0]) 258 config.pageinfo.$controls.eq(config.pageinfo.curselected).attr('src', config.pageinfo.srcs[2]) //select current paginate link 259 config.pageinfo.prevselected=config.pageinfo.curselected //set current selected link to previous 260 } 261 }, 262 263 264 loadcontent:function(galleryid, url){ 265 var config=stepcarousel.configholder[galleryid] 266 config.contenttype=['ajax', url] 267 stepcarousel.stopautostep(config) 268 stepcarousel.resetsettings($, config) 269 stepcarousel.init($, config) 270 271 }, 272 273 init:function($, config){ 274 config.gallerywidth=config.$gallery.width() 275 config.offsets={left:stepcarousel.getoffset(config.$gallery.get(0), "offsetLeft"), top:stepcarousel.getoffset(config.$gallery.get(0), "offsetTop")} 276 config.$belt=config.$gallery.find('.'+config.beltclass) //Find Belt DIV that contains all the panels 277 config.$panels=config.$gallery.find('.'+config.panelclass) //Find Panel DIVs that each contain a slide 278 config.$paginatediv=$('#'+config.galleryid+'-paginate') //get pagination DIV (if defined) 279 if (config.autostep) 280 config.autostep.pause+=config.panelbehavior.speed 281 config.onpanelclick=(typeof config.onpanelclick=="undefined")? function(target){} : config.onpanelclick //attach custom "onpanelclick" event handler 282 config.onslideaction=(typeof config.onslide=="undefined")? function(){} : function(beltobj){$(beltobj).stop(); config.onslide()} //attach custom "onslide" event handler 283 config.oninit=(typeof config.oninit=="undefined")? function(){} : config.oninit //attach custom "oninit" event handler 284 config.beltoffset=stepcarousel.getCSSValue(config.$belt.css('marginLeft')) //Find length of Belt DIV's left margin 285 config.statusvars=config.statusvars || [] //get variable names that will hold "start", "end", and "total" slides info 286 config.$statusobjs=[$('#'+config.statusvars[0]), $('#'+config.statusvars[1]), $('#'+config.statusvars[2])] 287 config.currentpanel=0 288 stepcarousel.configholder[config.galleryid]=config //store config parameter as a variable 289 if (config.contenttype[0]=="ajax" && typeof config.contenttype[1]!="undefined") //fetch ajax content? 290 stepcarousel.getremotepanels($, config) 291 else 292 stepcarousel.alignpanels($, config) //align panels and initialize gallery 293 }, 294 295 resetsettings:function($, config){ 296 config.$gallery.unbind() 297 config.$belt.stop() 298 config.$panels.remove() 299 if (config.$leftnavbutton){
300 config.$leftnavbutton.remove() 301 config.$rightnavbutton.remove() 302 } 303 if (config.$paginatediv.length==1){ 304 config.$paginatediv.unbind() 305 config.pageinfo.$controls.eq(0).attr('src', config.pageinfo.srcs[0]).removeAttr('data-index').removeAttr('data-moveto').removeAttr('title') //reset first pagination link so it acts as template again 306 .end().slice(1).remove() //then remove all but first pagination link 307 } 308 if (config.autostep) 309 config.autostep.status=null 310 if (config.panelbehavior.persist){ 311 stepcarousel.setCookie(window[config.galleryid+"persist"], 0) //set initial panel to 0, overridden w/ current panel if window.unload is invoked 312 } 313 }, 314 315 setup:function(config){ 316 //Disable Step Gallery scrollbars ASAP dynamically (enabled for sake of users with JS disabled) 317 document.write('<style type="text/css">\n#'+config.galleryid+'{overflow: hidden;}\n</style>') 318 $(document).ready(function($){ 319 config.$gallery=$('#'+config.galleryid) 320 stepcarousel.init($, config) 321 }) //end document.ready 322 $(window).bind('unload', function(){ //clean up on page unload 323 stepcarousel.resetsettings($, config) 324 if (config.panelbehavior.persist) 325 stepcarousel.setCookie(config.galleryid+"persist", config.currentpanel) 326 $.each(config, function(ai, oi){ 327 oi=null 328 }) 329 config=null 330 }) 331 } 332} 333 334
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.