1//Featured Content Glider: By http://www.dynamicdrive.com 2//Created: Dec 22nd, 07' 3//Updated (Jan 29th, 08): Added four possible slide directions: "updown", "downup", "leftright", or "rightleft" 4//Updated (Feb 1st, 08): Changed glide behavior to reverse direction when previous button is clicked 5//Updated (Feb 12th, 08): Added ability to retrieve gliding contents from an external file using Ajax ("remotecontent" variable added to configuration) 6 7var featuredcontentglider={ 8 csszindex: 100, 9 ajaxloadingmsg: '<b>Fetching Content. Please wait...</b>', 10 glide:function(config, showpage, isprev){ 11 var selected=parseInt(showpage) 12 if (selected>=config.$contentdivs.length){ //if no content exists at this index position 13 alert("No content exists at page "+(selected+1)+"! Loading 1st page instead.") 14 selected=0 15 } 16 var $target=config.$contentdivs.eq(selected) 17 //Test for toggler not being initialized yet, or user clicks on the currently selected page): 18 if (config.$togglerdiv.attr('lastselected')==null || parseInt(config.$togglerdiv.attr('lastselected'))!=selected){ 19 var $selectedlink=config.$toc.eq(selected) 20 config.$next.attr('loadpage', (selected<config.$contentdivs.length-1)? selected+1+'pg' : 0+'pg') 21 config.$prev.attr('loadpage', (selected==0)? config.$contentdivs.length-1+'pg' : selected-1+'pg') 22 var startpoint=(isprev=="previous")? -config.startpoint : config.startpoint 23 $target.css(config.leftortop, startpoint).css("zIndex", this.csszindex++) //hide content so it's just out of view before animating it 24 var endpoint=(config.leftortop=="left")? {left:0} : {top:0} //animate it into view 25 $target.animate(endpoint, config.speed) 26 config.$toc.removeClass('selected') 27 $selectedlink.addClass('selected') 28 config.$togglerdiv.attr('lastselected', selected+'pg') 29 } 30 }, 31 32 getremotecontent:function(config){ 33 config.$glider.html(this.ajaxloadingmsg) 34 $.ajax({ 35 url: config.remotecontent, 36 error:function(ajaxrequest){ 37 config.$glider.html('Error fetching content.<br />Server Response: '+ajaxrequest.responseText) 38 }, 39 success:function(content){ 40 config.$glider.html(content) 41 featuredcontentglider.setuptoggler(config) 42 } 43 }) 44 }, 45 46 aligncontents:function(config){ 47 config.$contentdivs=$("#"+config.gliderid+" ."+config.contentclass) 48 config.$contentdivs.css(config.leftortop, config.startpoint).css({height: config.$glider.height(), visibility: 'visible'}) //position content divs so they're out of view: 49 }, 50 51 setuptoggler:function(config){ 52 this.aligncontents(config) 53 config.$togglerdiv.hide() 54 config.$toc.each(function(index){ 55 $(this).attr('pagenumber', index+'pg') 56 if (index > (config.$contentdivs.length-1)) 57 $(this).css({display: 'none'}) //hide redundant "toc" links 58 }) 59 var $nextandprev=$("#"+config.togglerid+" .next, #"+config.togglerid+" .prev") 60 $nextandprev.click(function(event){ //Assign click behavior to 'next' and 'prev' links 61 featuredcontentglider.glide(config, this.getAttribute('loadpage'), this.getAttribute('buttontype')) 62 event.preventDefault() //cancel default link action 63 }) 64 config.$toc.click(function(event){ //Assign click behavior to 'toc' links 65 featuredcontentglider.glide(config, this.getAttribute('pagenumber')) 66 event.preventDefault() 67 }) 68 config.$togglerdiv.fadeIn(1000, function(){ 69 featuredcontentglider.glide(config, config.selected) 70 if (config.autorotate==true){ //auto rotate contents? 71 config.stepcount=0 //set steps taken 72 config.totalsteps=config.$contentdivs.length*config.autorotateconfig[1] //Total steps limit: num of contents x num of user specified cycles) 73 featuredcontentglider.autorotate(config) 74 } 75 }) 76 config.$togglerdiv.click(function(){ 77 featuredcontentglider.cancelautorotate(config.togglerid) 78 }) 79 }, 80 81 autorotate:function(config){ 82 var rotatespeed=config.speed+config.autorotateconfig[0] 83 window[config.togglerid+"timer"]=setInterval(function(){ 84 if (config.totalsteps>0 && config.stepcount>=config.totalsteps){
85 clearInterval(window[config.togglerid+"timer"]) 86 } 87 else{ 88 config.$next.click() 89 config.stepcount++ 90 } 91 }, rotatespeed) 92 }, 93 94 cancelautorotate:function(togglerid){ 95 if (window[togglerid+"timer"]) 96 clearInterval(window[togglerid+"timer"]) 97 }, 98 99 getCookie:function(Name){ 100 var re=new RegExp(Name+"=[^;]+", "i") //construct RE to search for target name/value pair 101 if (document.cookie.match(re)) //if cookie found 102 return document.cookie.match(re)[0].split("=")[1] //return its value 103 return null 104 }, 105 106 setCookie:function(name, value){ 107 document.cookie = name+"="+value 108 }, 109 110 init:function(config){ 111 $(document).ready(function(){ 112 config.$glider=$("#"+config.gliderid) 113 config.$togglerdiv=$("#"+config.togglerid) 114 config.$toc=config.$togglerdiv.find('.toc') 115 config.$next=config.$togglerdiv.find('.next') 116 config.$prev=config.$togglerdiv.find('.prev') 117 config.$prev.attr('buttontype', 'previous') 118 var selected=(config.persiststate)? featuredcontentglider.getCookie(config.gliderid) : config.selected 119 config.selected=(isNaN(parseInt(selected))) ? config.selected : selected //test for cookie value containing null (1st page load) or "undefined" string 120 config.leftortop=(/up/i.test(config.direction))? "top" : "left" //set which CSS property to manipulate based on "direction" 121 config.heightorwidth=(/up/i.test(config.direction))? config.$glider.height() : config.$glider.width() //Get glider height or width based on "direction" 122 config.startpoint=(/^(left|up)/i.test(config.direction))? -config.heightorwidth : config.heightorwidth //set initial position of contents based on "direction" 123 if (typeof config.remotecontent!="undefined" && config.remotecontent.length>0) 124 featuredcontentglider.getremotecontent(config) 125 else 126 featuredcontentglider.setuptoggler(config) 127 $(window).bind('unload', function(){ //clean up and persist 128 config.$togglerdiv.unbind('click') 129 config.$toc.unbind('click') 130 config.$next.unbind('click') 131 config.$prev.unbind('click') 132 if (config.persiststate) 133 featuredcontentglider.setCookie(config.gliderid, config.$togglerdiv.attr('lastselected')) 134 config=null 135 136 }) 137 }) 138 } 139}
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.