1//** Ajax Tabs Content script v2.0- Dynamic Drive DHTML code library (http://www.dynamicdrive.com) 2//** Updated Oct 21st, 07 to version 2.0. Contains numerous improvements 3//** Updated Feb 18th, 08 to version 2.1: Adds a public "tabinstance.cycleit(dir)" method to cycle forward or backward between tabs dynamically. Only .js file changed from v2.0. 4//** Updated April 8th, 08 to version 2.2: 5// -Adds support for expanding a tab using a URL parameter (ie: http://mysite.com/tabcontent.htm?tabinterfaceid=0) 6// -Modified Ajax routine so testing the script out locally in IE7 now works 7 8var ddajaxtabssettings={} 9ddajaxtabssettings.bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no) 10ddajaxtabssettings.loadstatustext="<div class='loading_now_box'><img src='http://nk5.netdreamers/news/style/netkeiba.ja/image/loading.gif' /><p>Now Loading...</p></div>" 11 12 13////NO NEED TO EDIT BELOW//////////////////////// 14 15function ddajaxtabs(tabinterfaceid, contentdivid){ 16 this.tabinterfaceid=tabinterfaceid //ID of Tab Menu main container 17 this.tabs=document.getElementById(tabinterfaceid).getElementsByTagName("a") //Get all tab links within container 18 this.enabletabpersistence=true 19 this.hottabspositions=[] //Array to store position of tabs that have a "rel" attr defined, relative to all tab links, within container 20 this.currentTabIndex=0 //Index of currently selected hot tab (tab with sub content) within hottabspositions[] array 21 this.contentdivid=contentdivid 22 this.defaultHTML="" 23 this.defaultIframe='<iframe src="about:blank" marginwidth="0" marginheight="0" frameborder="0" vspace="0" hspace="0" class="tabcontentiframe" style="width:500; height:auto; min-height: 100px"></iframe>' 24 this.defaultIframe=this.defaultIframe.replace(/<iframe/i, '<iframe name="'+"_ddajaxtabsiframe-"+contentdivid+'" ') 25this.revcontentids=[] //Array to store ids of arbitrary contents to expand/contact as well ("rev" attr values) 26 this.selectedClassTarget="link" //keyword to indicate which target element to assign "selected" CSS class ("linkparent" or "link") 27} 28 29ddajaxtabs.connect=function(pageurl, tabinstance){ 30 var page_request = false 31 var bustcacheparameter="" 32 if (window.ActiveXObject){ //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken) 33 try { 34 page_request = new ActiveXObject("Msxml2.XMLHTTP") 35 } 36 catch (e){ 37 try{ 38 page_request = new ActiveXObject("Microsoft.XMLHTTP") 39 } 40 catch (e){} 41 } 42 } 43 else if (window.XMLHttpRequest) // if Mozilla, Safari etc 44 page_request = new XMLHttpRequest() 45 else 46 return false 47 var ajaxfriendlyurl=pageurl.replace(/^http:\/\/[^\/]+\//i, "http://"+window.location.hostname+"/") 48 page_request.onreadystatechange=function(){ddajaxtabs.loadpage(page_request, pageurl, tabinstance)} 49 if (ddajaxtabssettings.bustcachevar) //if bust caching of external page 50 bustcacheparameter=(ajaxfriendlyurl.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime() 51 page_request.open('GET', ajaxfriendlyurl+bustcacheparameter, true) 52 page_request.send(null) 53} 54 55ddajaxtabs.loadpage=function(page_request, pageurl, tabinstance){ 56 var divId=tabinstance.contentdivid 57 if (page_request.readyState == 4 && (page_request.status==200 || window.location.page.indexOf("http")==-1)){ 58 document.getElementById(divId).innerHTML=page_request.responseText 59 ddajaxtabs.ajaxpageloadaction(pageurl, tabinstance) 60 } 61} 62 63ddajaxtabs.ajaxpageloadaction=function(pageurl, tabinstance){ 64 tabinstance.onajaxpageload(pageurl) //call user customized onajaxpageload() function when an ajax page is fetched/ loaded 65} 66 67ddajaxtabs.getCookie=function(Name){ 68 var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair 69 if (document.cookie.match(re)) //if cookie found 70 return document.cookie.match(re)[0].split("=")[1] //return its value 71 return "" 72} 73 74ddajaxtabs.setCookie=function(name, value){ 75 document.cookie = name+"="+value+";path=/" //cookie value is domain wide (path=/) 76} 77 78ddajaxtabs.prototype={ 79 80 expandit:function(tabid_or_position){ //PUBLIC function to select a tab either by its ID or position(int) within its peers 81 this.cancelautorun() //stop auto cycling of tabs (if running) 82 var tabref="" 83 try{
84 if (typeof tabid_or_position=="string" && document.getElementById(tabid_or_position).getAttribute("rel")) //if specified tab contains "rel" attr 85 tabref=document.getElementById(tabid_or_position) 86 else if (parseInt(tabid_or_position)!=NaN && this.tabs[tabid_or_position].getAttribute("rel")) //if specified tab contains "rel" attr 87 tabref=this.tabs[tabid_or_position] 88 } 89 catch(err){alert("Invalid Tab ID or position entered!")} 90 if (tabref!="") //if a valid tab is found based on function parameter 91 this.expandtab(tabref) //expand this tab 92 }, 93 94 cycleit:function(dir, autorun){ //PUBLIC function to move foward or backwards through each hot tab (tabinstance.cycleit('foward/back') ) 95 if (dir=="next"){ 96 var currentTabIndex=(this.currentTabIndex<this.hottabspositions.length-1)? this.currentTabIndex+1 : 0 97 } 98 else if (dir=="prev"){ 99 var currentTabIndex=(this.currentTabIndex>0)? this.currentTabIndex-1 : this.hottabspositions.length-1 100 } 101 if (typeof autorun=="undefined") //if cycleit() is being called by user, versus autorun() function 102 this.cancelautorun() //stop auto cycling of tabs (if running) 103 this.expandtab(this.tabs[this.hottabspositions[currentTabIndex]]) 104 }, 105 106 setpersist:function(bool){ //PUBLIC function to toggle persistence feature 107 this.enabletabpersistence=bool 108 }, 109 110 loadajaxpage:function(pageurl){ //PUBLIC function to fetch a page via Ajax and display it within the Tab Content instance's container 111 ddajaxtabs.connect(pageurl, this) 112 }, 113 114 loadiframepage:function(pageurl){ //PUBLIC function to fetch a page and load it into the IFRAME of the Tab Content instance's container 115 this.iframedisplay(pageurl, this.contentdivid) 116 }, 117 118 setselectedClassTarget:function(objstr){ //PUBLIC function to set which target element to assign "selected" CSS class ("linkparent" or "link") 119 this.selectedClassTarget=objstr || "link" 120 }, 121 122 getselectedClassTarget:function(tabref){ //Returns target element to assign "selected" CSS class to 123 return (this.selectedClassTarget==("linkparent".toLowerCase()))? tabref.parentNode : tabref 124 }, 125 126 urlparamselect:function(tabinterfaceid){ 127 var result=window.location.search.match(new RegExp(tabinterfaceid+"=(\\d+)", "i")) //check for "?tabinterfaceid=2" in URL 128 return (result==null)? null : parseInt(RegExp.$1) //returns null or index, where index (int) is the selected tab's index 129 }, 130 131 onajaxpageload:function(pageurl){ //PUBLIC Event handler that can invoke custom code whenever an Ajax page has been fetched and displayed 132 //do nothing by default 133 }, 134 135 expandtab:function(tabref){ 136 var relattrvalue=tabref.getAttribute("rel") 137 //Get "rev" attr as a string of IDs in the format ",john,george,trey,etc," to easy searching through 138 var associatedrevids=(tabref.getAttribute("rev"))? ","+tabref.getAttribute("rev").replace(/\s+/, "")+"," : "" 139 if (relattrvalue=="#default") 140 document.getElementById(this.contentdivid).innerHTML=this.defaultHTML 141 else if (relattrvalue=="#iframe") 142 this.iframedisplay(tabref.getAttribute("page"), this.contentdivid) 143 else 144 ddajaxtabs.connect(tabref.getAttribute("page"), this) 145 this.expandrevcontent(associatedrevids) 146 for (var i=0; i<this.tabs.length; i++){ //Loop through all tabs, and assign only the selected tab the CSS class "selected" 147 //this.getselectedClassTarget(this.tabs[i]).className=(this.tabs[i].getAttribute("page")==tabref.getAttribute("page"))? "selected" : "" 148 this.getselectedClassTarget(this.tabs[i]).className=(this.tabs[i].getAttribute("page")==tabref.getAttribute("page"))? "active" : "" 149 } 150 if (this.enabletabpersistence) //if persistence enabled, save selected tab position(int) relative to its peers 151 ddajaxtabs.setCookie(this.tabinterfaceid, tabref.tabposition) 152 this.setcurrenttabindex(tabref.tabposition) //remember position of selected tab within hottabspositions[] array 153 }, 154 155 iframedisplay:function(pageurl, contentdivid){ 156 if (typeof window.frames["_ddajaxtabsiframe-"+contentdivid]!="undefined"){ 157 try{delete window.frames["_ddajaxtabsiframe-"+contentdivid]} //delete iframe within Tab content container if it exists (due to bug in Firefox) 158 catch(err){} 159 } 160 document.getElementById(contentdivid).innerHTML=this.defaultIframe 161 window.frames["_ddajaxtabsiframe-"+contentdivid].location.replace(pageurl) //load desired page into iframe 162 }, 163 164 165 expandrevcontent:function(associatedrevids){
166 var allrevids=this.revcontentids 167 for (var i=0; i<allrevids.length; i++){ //Loop through rev attributes for all tabs in this tab interface 168 //if any values stored within associatedrevids matches one within allrevids, expand that DIV, otherwise, contract it 169 document.getElementById(allrevids[i]).style.display=(associatedrevids.indexOf(","+allrevids[i]+",")!=-1)? "block" : "none" 170 } 171 }, 172 173 setcurrenttabindex:function(tabposition){ //store current position of tab (within hottabspositions[] array) 174 for (var i=0; i<this.hottabspositions.length; i++){ 175 if (tabposition==this.hottabspositions[i]){ 176 this.currentTabIndex=i 177 break 178 } 179 } 180 }, 181 182 autorun:function(){ //function to auto cycle through and select tabs based on a set interval 183 this.cycleit('next', true) 184 }, 185 186 cancelautorun:function(){ 187 if (typeof this.autoruntimer!="undefined") 188 clearInterval(this.autoruntimer) 189 }, 190 191 init:function(automodeperiod){ 192 var persistedtab=ddajaxtabs.getCookie(this.tabinterfaceid) //get position of persisted tab (applicable if persistence is enabled) 193 var selectedtab=-1 //Currently selected tab index (-1 meaning none) 194 var selectedtabfromurl=this.urlparamselect(this.tabinterfaceid) //returns null or index from: tabcontent.htm?tabinterfaceid=index 195 this.automodeperiod=automodeperiod || 0 196 this.defaultHTML=document.getElementById(this.contentdivid).innerHTML 197 for (var i=0; i<this.tabs.length; i++){ 198 this.tabs[i].tabposition=i //remember position of tab relative to its peers 199 if (this.tabs[i].getAttribute("rel")){ 200 var tabinstance=this 201 this.hottabspositions[this.hottabspositions.length]=i //store position of "hot" tab ("rel" attr defined) relative to its peers 202 this.tabs[i].onclick=function(){ 203 tabinstance.expandtab(this) 204 tabinstance.cancelautorun() //stop auto cycling of tabs (if running) 205 return false 206 } 207 if (this.tabs[i].getAttribute("rev")){ //if "rev" attr defined, store each value within "rev" as an array element 208 this.revcontentids=this.revcontentids.concat(this.tabs[i].getAttribute("rev").split(/\s*,\s*/)) 209 } 210 if (selectedtabfromurl==i || this.enabletabpersistence && selectedtab==-1 && parseInt(persistedtab)==i || !this.enabletabpersistence && selectedtab==-1 && this.getselectedClassTarget(this.tabs[i]).className=="selected"){ 211 selectedtab=i //Selected tab index, if found 212 } 213 } 214 } //END for loop 215 if (selectedtab!=-1) //if a valid default selected tab index is found 216 this.expandtab(this.tabs[selectedtab]) //expand selected tab (either from URL parameter, persistent feature, or class="selected" class) 217 else //if no valid default selected index found 218 this.expandtab(this.tabs[this.hottabspositions[0]]) //Just select first tab that contains a "rel" attr 219 if (parseInt(this.automodeperiod)>500 && this.hottabspositions.length>1){ 220 this.autoruntimer=setInterval(function(){tabinstance.autorun()}, this.automodeperiod) 221 } 222 } //END int() function 223 224 225 226} //END Prototype assignment 227 228jQuery(function($) { 229 230 231 232});
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.