#Post 2 of 2.
Code:
loadiframepage:function(pageurl){ //PUBLIC function to fetch a page and load it into the IFRAME of the Tab Content instance's container
this.iframedisplay(pageurl, this.contentdivid)
},
setselectedClassTarget:function(objstr){ //PUBLIC function to set which target element to assign "selected" CSS class ("linkparent" or "link")
this.selectedClassTarget=objstr || "link"
},
getselectedClassTarget:function(tabref){ //Returns target element to assign "selected" CSS class to
return (this.selectedClassTarget==("linkparent".toLowerCase()))? tabref.parentNode : tabref
},
urlparamselect:function(tabinterfaceid){
var result=window.location.search.match(new RegExp(tabinterfaceid+"=(\\d+)", "i")) //check for "?tabinterfaceid=2" in URL
return (result==null)? null : parseInt(RegExp.$1) //returns null or index, where index (int) is the selected tab's index
},
onajaxpageload:function(pageurl){ //PUBLIC Event handler that can invoke custom code whenever an Ajax page has been fetched and displayed
//do nothing by default
},
expandtab:function(tabref){
var relattrvalue=tabref.getAttribute("rel")
//Get "rev" attr as a string of IDs in the format ",john,george,trey,etc," to easy searching through
var associatedrevids=(tabref.getAttribute("rev"))? ","+tabref.getAttribute("rev").replace(/\s+/, "")+"," : ""
if (relattrvalue=="#default")
document.getElementById(this.contentdivid).innerHTML=this.defaultHTML
else if (relattrvalue=="#iframe")
this.iframedisplay(tabref.getAttribute("type"), this.contentdivid)
else
ddajaxtabs.connect(tabref.getAttribute("type"), this)
this.expandrevcontent(associatedrevids)
for (var i=0; i<this.tabs.length; i++){ //Loop through all tabs, and assign only the selected tab the CSS class "selected"
this.getselectedClassTarget(this.tabs[i]).className=(this.tabs[i].getAttribute("type")==tabref.getAttribute("type"))? "selected" : ""
}
if (this.enabletabpersistence) //if persistence enabled, save selected tab position(int) relative to its peers
ddajaxtabs.setCookie(this.tabinterfaceid, tabref.tabposition)
this.setcurrenttabindex(tabref.tabposition) //remember position of selected tab within hottabspositions[] array
},
iframedisplay:function(pageurl, contentdivid){
if (typeof window.frames["_ddajaxtabsiframe-"+contentdivid]!="undefined"){
try{delete window.frames["_ddajaxtabsiframe-"+contentdivid]} //delete iframe within Tab content container if it exists (due to bug in Firefox)
catch(err){}
}
document.getElementById(contentdivid).innerHTML=this.defaultIframe
window.frames["_ddajaxtabsiframe-"+contentdivid].location.replace(pageurl) //load desired page into iframe
},
expandrevcontent:function(associatedrevids){
var allrevids=this.revcontentids
for (var i=0; i<allrevids.length; i++){ //Loop through rev attributes for all tabs in this tab interface
//if any values stored within associatedrevids matches one within allrevids, expand that DIV, otherwise, contract it
document.getElementById(allrevids[i]).style.display=(associatedrevids.indexOf(","+allrevids[i]+",")!=-1)? "block" : "none"
}
},
setcurrenttabindex:function(tabposition){ //store current position of tab (within hottabspositions[] array)
for (var i=0; i<this.hottabspositions.length; i++){
if (tabposition==this.hottabspositions[i]){
this.currentTabIndex=i
break
}
}
},
autorun:function(){ //function to auto cycle through and select tabs based on a set interval
this.cycleit('next', true)
},
cancelautorun:function(){
if (typeof this.autoruntimer!="undefined")
clearInterval(this.autoruntimer)
},
init:function(automodeperiod){
var persistedtab=ddajaxtabs.getCookie(this.tabinterfaceid) //get position of persisted tab (applicable if persistence is enabled)
var selectedtab=-1 //Currently selected tab index (-1 meaning none)
var selectedtabfromurl=this.urlparamselect(this.tabinterfaceid) //returns null or index from: tabcontent.htm?tabinterfaceid=index
this.automodeperiod=automodeperiod || 0
this.defaultHTML=document.getElementById(this.contentdivid).innerHTML
for (var i=0; i<this.tabs.length; i++){
this.tabs[i].tabposition=i //remember position of tab relative to its peers
if (this.tabs[i].getAttribute("rel")){
var tabinstance=this
this.hottabspositions[this.hottabspositions.length]=i //store position of "hot" tab ("rel" attr defined) relative to its peers
this.tabs[i].onclick=function(){
tabinstance.expandtab(this)
tabinstance.cancelautorun() //stop auto cycling of tabs (if running)
return false
}
if (this.tabs[i].getAttribute("rev")){ //if "rev" attr defined, store each value within "rev" as an array element
this.revcontentids=this.revcontentids.concat(this.tabs[i].getAttribute("rev").split(/\s*,\s*/))
}
if (selectedtabfromurl==i || this.enabletabpersistence && selectedtab==-1 && parseInt(persistedtab)==i || !this.enabletabpersistence && selectedtab==-1 && this.getselectedClassTarget(this.tabs[i]).className=="selected"){
selectedtab=i //Selected tab index, if found
}
}
} //END for loop
if (selectedtab!=-1) //if a valid default selected tab index is found
this.expandtab(this.tabs[selectedtab]) //expand selected tab (either from URL parameter, persistent feature, or class="selected" class)
else //if no valid default selected index found
this.expandtab(this.tabs[this.hottabspositions[0]]) //Just select first tab that contains a "rel" attr
if (parseInt(this.automodeperiod)>500 && this.hottabspositions.length>1){
this.autoruntimer=setInterval(function(){tabinstance.autorun()}, this.automodeperiod)
}
} //END int() function
} //END Prototype assignment
//----code end
in the web site PHP code where ajaxpage must be displayed on <DIV ID="tmbtabs">..</DIV>
PHP Code:
//index.php
//--Cookies for tmbtabs
if($subportfolio=true){
//--------Send a cookie for id=tmbtabs------------
empty($_COOKIE['tmbtabs']);
$setCookie = array();
$file_storeportfolio = 'data.dat'; //Include file for Porfolio store
if(!$file=@file($file_storeportfolio)){}else{
$count_lines = count($file);
foreach($file as $row){
list($a,$b,$a_href) = explode('|', $row);
$setCookie[] = array('a_href'=>$a_href);
}
foreach($setCookie as $key => $set){
$cookienum=$count_lines-($key+1); //line by $info
if($set['a_href'] == $info){
//echo $cookienum;
setcookie('tmbtabs',$cookienum,time()+3600,'/'); //Send a cookie
}
}
}
//--------------------
}
$loadajaxpage = <<<JS
tmb.loadajaxpage("$language/$id:$id2/ajax:imgmax")
JS;
}else{
list($a,$b,$c,$d,$e,$f,$g,$h)=explode('|', $file[$line_num]);
$loadajaxpage = <<<JS
tmb.loadajaxpage("$language/$id:$c/ajax:imgmax")
JS;
}
//here in id2.php you can include file where by $id2 request will be print'ed the same information like is http://tag.oo.lv/en/design:a_href23/ajax:imgmax for ajaxtabs.js displayed on <DIV ID="tmbtabs">..</DIV>
include('id2.php'); /* in my page is some differences like if($_GET['ajax']=="imgmax"){ include('ajax_echo.php'); } etc */
echo <<<HTML
<noscript>You need to anable the JavaScript usebility.<br /><br />This is some default tab content, embedded directly inside this space and not via Ajax. It can be shown when no tabs are automatically selected, or associated with a certain tab, in this case, the first tab.</noscript><br />
<br />
<br /></div>
<script type="text/javascript">
var tmb=new ddajaxtabs("tmbtabs", "tmbdivcontainer")
tmb.setpersist(true)
tmb.setselectedClassTarget("link") //"link" or "linkparent"
tmb.init()
$loadajaxpage
tmb.onajaxpageload=function(pageurl){
jQuery(document).ready(function($){ $('a[rel*=facebox]').facebox() })
}
</script>
HTML;
I would like to set cookies not by count (number) but like by ID value. For sample, cookie on clicking on <a href="/en/design:a_href23" type="/en/design:a_href23/ajax:imgmax" rel="tmbcontainer" id="a_href23">..</a> must be 'a_href23'.
And even better could be in place of using Cookies to use PHP SESSION's.
Bookmarks