1//** Featured Content Slider script- ?Dynamic Drive DHTML code library (http://www.dynamicdrive.com) 2//** Last updated: Nov 3rd- 07- Added optional fade transition effect. 3 4////Ajax related settings 5var csbustcachevar = 0; 6//bust potential caching of external pages after initial Ajax request? (1=yes, 0=no) 7var enabletransition = 1; 8//enable fade into view transition effect? (1=yes, 0=no) 9var csloadstatustext = "<img src='loading.gif' /> Requesting content..."; 10//HTML to indicate Ajax page is being fetched 11var csexternalfiles = []; 12//External .css or .js files to load to style the external content(s), if any. Separate multiple files with comma ie: ["cat.css", dog.js"] 13 14////NO NEED TO EDIT BELOW//////////////////////// 15var enablepersist = true; 16var slidernodes = new Object(); 17//Object array to store references to each content slider's DIV containers (<div class="contentdiv">) 18var csloadedobjects = ""; 19//Variable to store file names of .js/.css files already loaded (if Ajax is used) 20 21function ContentSlider(sliderid, autorun, customPaginateText, customNextText) { 22 var slider = document.getElementById(sliderid); 23 if (typeof customPaginateText != "undefined" && customPaginateText != "") //Custom array of pagination links text defined? 24 slider.paginateText = customPaginateText; 25 if (typeof customNextText != "undefined" && customNextText != "") //Custom HTML for "Next" link defined? 26 slider.nextText = customNextText; 27 slidernodes[sliderid] = []; //Array to store references to this content slider's DIV containers (<div class="contentdiv">) 28 ContentSlider.loadobjects(csexternalfiles); //Load external .js and .css files, if any 29 var alldivs = slider.getElementsByTagName("div"); 30 for (var i = 0; i < alldivs.length; i++) { 31 if (alldivs[i].className == "opacitylayer") 32 slider.opacitylayer = alldivs[i]; 33 else if (alldivs[i].className == "contentdiv") { 34 slidernodes[sliderid].push(alldivs[i]); //add this DIV reference to array 35 if (typeof alldivs[i].getAttribute("rel") == "string") //If get this DIV's content via Ajax (rel attr contains path to external page) 36 ContentSlider.ajaxpage(alldivs[i].getAttribute("rel"), alldivs[i]); 37 } 38 } 39 ContentSlider.buildpagination(sliderid); 40 var loadfirstcontent = true; 41 if (enablepersist && getCookie(sliderid) != "") { //if enablepersist is true and cookie contains corresponding value for slider 42 var cookieval = getCookie(sliderid).split(":"); //process cookie value ([sliderid, int_pagenumber (div content to jump to)] 43 if (document.getElementById(cookieval[0]) != null && typeof slidernodes[sliderid][cookieval[1]] != "undefined") { //check cookie value for validity 44 ContentSlider.turnpage(cookieval[0], parseInt(cookieval[1])); //restore content slider's last shown DIV 45 loadfirstcontent = false; 46 } 47 } 48 if (loadfirstcontent == true) //if enablepersist is false, or cookie value doesn't contain valid value for some reason (ie: user modified the structure of the HTML) 49 ContentSlider.turnpage(sliderid, 0); //Display first DIV within slider 50 if (typeof autorun == "number" && autorun > 0) //if autorun parameter (int_miliseconds) is defined, fire auto run sequence 51 window[sliderid + "timer"] = setTimeout(function() { ContentSlider.autoturnpage(sliderid, autorun); }, autorun); 52} 53 54ContentSlider.buildpagination = function(sliderid) { 55 var slider = document.getElementById(sliderid); 56 var paginatediv = document.getElementById("paginate-" + sliderid); //reference corresponding pagination DIV for slider 57 var pcontent = ""; 58 for (var i = 0; i < slidernodes[sliderid].length; i++) //For each DIV within slider, generate a pagination link 59 pcontent += '<a href="#" onClick=\"ContentSlider.turnpage(\'' + sliderid + '\', ' + i + '); return false\">' + (slider.paginateText ? slider.paginateText[i] : i + 1) + '</a> '; 60 pcontent += '<a href="#" style="font-weight: bold;" onClick=\"ContentSlider.turnpage(\'' + sliderid + '\', parseInt(this.getAttribute(\'rel\'))); return false\">' + (slider.nextText || "Next") + '</a>'; 61 paginatediv.innerHTML = pcontent; 62 paginatediv.onclick = function() { //cancel auto run sequence (if defined) when user clicks on pagination DIV 63 if (typeof window[sliderid + "timer"] != "undefined") 64 clearTimeout(window[sliderid + "timer"]); 65 }; 66};
67ContentSlider.turnpage = function(sliderid, thepage) { 68 var paginatelinks = document.getElementById("paginate-" + sliderid).getElementsByTagName("a"); //gather pagination links 69 for (var i = 0; i < slidernodes[sliderid].length; i++) { //For each DIV within slider 70 paginatelinks[i].className = ""; //empty corresponding pagination link's class name 71 slidernodes[sliderid][i].style.display = "none"; //hide DIV 72 } 73 paginatelinks[thepage].className = "selected"; //for selected DIV, set corresponding pagination link's class name 74 if (enabletransition) { 75 if (window[sliderid + "fadetimer"]) 76 clearTimeout(window[sliderid + "fadetimer"]); 77 this.setopacity(sliderid, 0.1); 78 } 79 slidernodes[sliderid][thepage].style.display = "block"; //show selected DIV 80 if (enabletransition) 81 this.fadeup(sliderid, thepage); //Set "Next" pagination link's (last link within pagination DIV) "rel" attribute to the next DIV number to show 82 paginatelinks[paginatelinks.length - 1].setAttribute("rel", thenextpage = (thepage < paginatelinks.length - 2) ? thepage + 1 : 0); 83 if (enablepersist) 84 setCookie(sliderid, sliderid + ":" + thepage); 85}; 86ContentSlider.autoturnpage = function(sliderid, autorunperiod) { 87 var paginatelinks = document.getElementById("paginate-" + sliderid).getElementsByTagName("a"); //Get pagination links 88 var nextpagenumber = parseInt(paginatelinks[paginatelinks.length - 1].getAttribute("rel")); //Get page number of next DIV to show 89 ContentSlider.turnpage(sliderid, nextpagenumber); //Show that DIV 90 window[sliderid + "timer"] = setTimeout(function() { ContentSlider.autoturnpage(sliderid, autorunperiod); }, autorunperiod); 91}; 92ContentSlider.setopacity = function(sliderid, value) { //Sets the opacity of targetobject based on the passed in value setting (0 to 1 and in between) 93 var targetobject = document.getElementById(sliderid).opacitylayer || null; //reference slider container itself 94 if (targetobject && targetobject.filters && targetobject.filters[0]) { //IE syntax 95 if (typeof targetobject.filters[0].opacity == "number") //IE6 96 targetobject.filters[0].opacity = value * 100; 97 else //IE 5.5 98 targetobject.style.filter = "alpha(opacity=" + value * 100 + ")"; 99 } else if (targetobject && typeof targetobject.style.MozOpacity != "undefined") //Old Mozilla syntax 100 targetobject.style.MozOpacity = value; 101 else if (targetobject && typeof targetobject.style.opacity != "undefined") //Standard opacity syntax 102 targetobject.style.opacity = value; 103 targetobject.currentopacity = value; 104}; 105ContentSlider.fadeup = function(sliderid) { 106 var targetobject = document.getElementById(sliderid).opacitylayer || null; //reference slider container itself 107 if (targetobject && targetobject.currentopacity < 1) { 108 this.setopacity(sliderid, targetobject.currentopacity + 0.1); 109 window[sliderid + "fadetimer"] = setTimeout(function() { ContentSlider.fadeup(sliderid); }, 100); 110 } 111}; 112 113function getCookie(Name) { 114 var re = new RegExp(Name + "=[^;]+", "i"); //construct RE to search for target name/value pair 115 if (document.cookie.match(re)) //if cookie found 116 return document.cookie.match(re)[0].split("=")[1]; //return its value 117 return ""; 118} 119 120function setCookie(name, value) { 121 document.cookie = name + "=" + value; 122} 123 124////////////////Ajax Related functions ////////////////////////////////// 125 126ContentSlider.ajaxpage = function(url, thediv) { 127 var page_request = false; 128 var bustcacheparameter = ""; 129 if (window.XMLHttpRequest) // if Mozilla, Safari etc 130 page_request = new XMLHttpRequest(); 131 else if (window.ActiveXObject) { // if IE 132 try { 133 page_request = new ActiveXObject("Msxml2.XMLHTTP"); 134 } catch(e) { 135 try { 136 page_request = new ActiveXObject("Microsoft.XMLHTTP"); 137 } catch(e) { 138 } 139 } 140 } else 141 return false; 142 thediv.innerHTML = csloadstatustext; 143 page_request.onreadystatechange = function() { 144 ContentSlider.loadpage(page_request, thediv); 145 }; 146 if (csbustcachevar) //if bust caching of external page 147 bustcacheparameter = (url.indexOf("?") != -1) ? "&" + new Date().getTime() : "?" + new Date().getTime(); 148 page_request.open('GET', url + bustcacheparameter, true); 149 page_request.send(null); 150}; 151ContentSlider.loadpage = function(page_request, thediv) { 152 if (page_request.readyState == 4 && (page_request.status == 200 || window.location.href.indexOf("http") == -1)) 153 thediv.innerHTML = page_request.responseText; 154}; 155ContentSlider.loadobjects = function(externalfiles) { //function to load external .js and .css files. Parameter accepts a list of external files to load (array) 156 for (var i = 0; i < externalfiles.length; i++) { 157 var file = externalfiles[i]; 158 var fileref = ""; 159 if (csloadedobjects.indexOf(file) == -1) { //Check to see if this object has not already been added to page before proceeding 160 if (file.indexOf(".js") != -1) { //If object is a js file 161 fileref = document.createElement('script'); 162 fileref.setAttribute("type", "text/javascript"); 163 fileref.setAttribute("src", file); 164 } else if (file.indexOf(".css") != -1) { //If object is a css file 165 fileref = document.createElement("link"); 166 fileref.setAttribute("rel", "stylesheet"); 167 fileref.setAttribute("type", "text/css"); 168 fileref.setAttribute("href", file); 169 } 170 } 171 if (fileref != "") { 172 document.getElementsByTagName("head").item(0).appendChild(fileref); 173 csloadedobjects += file + " "; //Remember this object as being already added to page 174 } 175 } 176};
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.