]> wagnertech.de Git - mfinanz.git/blobdiff - js/tabcontent.js
Uebernahme der kompletten Version, so wie sie Philip als "Demo-Version" gezeigt hat...
[mfinanz.git] / js / tabcontent.js
diff --git a/js/tabcontent.js b/js/tabcontent.js
new file mode 100644 (file)
index 0000000..243be26
--- /dev/null
@@ -0,0 +1,82 @@
+//** Tab Content script- © Dynamic Drive DHTML code library (http://www.dynamicdrive.com)\r
+//** Last updated: June 29th, 06\r
+\r
+var enabletabpersistence=1 //enable tab persistence via session only cookies, so selected tab is remembered?\r
+\r
+////NO NEED TO EDIT BELOW////////////////////////\r
+var tabcontentIDs=new Object()\r
+\r
+function expandcontent(linkobj){\r
+var ulid=linkobj.parentNode.parentNode.id //id of UL element\r
+var ullist=document.getElementById(ulid).getElementsByTagName("li") //get list of LIs corresponding to the tab contents\r
+for (var i=0; i<ullist.length; i++){\r
+ullist[i].className=""  //deselect all tabs\r
+if (typeof tabcontentIDs[ulid][i]!="undefined") //if tab content within this array index exists (exception: More tabs than there are tab contents)\r
+document.getElementById(tabcontentIDs[ulid][i]).style.display="none" //hide all tab contents\r
+}\r
+linkobj.parentNode.className="selected"  //highlight currently clicked on tab\r
+document.getElementById(linkobj.getAttribute("rel")).style.display="block" //expand corresponding tab content\r
+saveselectedtabcontentid(ulid, linkobj.getAttribute("rel"))\r
+}\r
+\r
+function savetabcontentids(ulid, relattribute){// save ids of tab content divs\r
+if (typeof tabcontentIDs[ulid]=="undefined") //if this array doesn't exist yet\r
+tabcontentIDs[ulid]=new Array()\r
+tabcontentIDs[ulid][tabcontentIDs[ulid].length]=relattribute\r
+}\r
+\r
+function saveselectedtabcontentid(ulid, selectedtabid){ //set id of clicked on tab as selected tab id & enter into cookie\r
+if (enabletabpersistence==1) //if persistence feature turned on\r
+setCookie(ulid, selectedtabid)\r
+}\r
+\r
+function getullistlinkbyId(ulid, tabcontentid){ //returns a tab link based on the ID of the associated tab content\r
+var ullist=document.getElementById(ulid).getElementsByTagName("li")\r
+for (var i=0; i<ullist.length; i++){\r
+if (ullist[i].getElementsByTagName("a")[0].getAttribute("rel")==tabcontentid){\r
+return ullist[i].getElementsByTagName("a")[0]\r
+break\r
+}\r
+}\r
+}\r
+\r
+function initializetabcontent(){\r
+for (var i=0; i<arguments.length; i++){ //loop through passed UL ids\r
+if (enabletabpersistence==0 && getCookie(arguments[i])!="") //clean up cookie if persist=off\r
+setCookie(arguments[i], "")\r
+var clickedontab=getCookie(arguments[i]) //retrieve ID of last clicked on tab from cookie, if any\r
+var ulobj=document.getElementById(arguments[i])\r
+var ulist=ulobj.getElementsByTagName("li") //array containing the LI elements within UL\r
+for (var x=0; x<ulist.length; x++){ //loop through each LI element\r
+var ulistlink=ulist[x].getElementsByTagName("a")[0]\r
+if (ulistlink.getAttribute("rel")){\r
+savetabcontentids(arguments[i], ulistlink.getAttribute("rel")) //save id of each tab content as loop runs\r
+ulistlink.onclick=function(){\r
+expandcontent(this)\r
+return false\r
+}\r
+if (ulist[x].className=="selected" && clickedontab=="") //if a tab is set to be selected by default\r
+expandcontent(ulistlink) //auto load currenly selected tab content\r
+}\r
+} //end inner for loop\r
+if (clickedontab!=""){ //if a tab has been previously clicked on per the cookie value\r
+var culistlink=getullistlinkbyId(arguments[i], clickedontab)\r
+if (typeof culistlink!="undefined") //if match found between tabcontent id and rel attribute value\r
+expandcontent(culistlink) //auto load currenly selected tab content\r
+else //else if no match found between tabcontent id and rel attribute value (cookie mis-association)\r
+expandcontent(ulist[0].getElementsByTagName("a")[0]) //just auto load first tab instead\r
+}\r
+} //end outer for loop\r
+}\r
+\r
+\r
+function getCookie(Name){ \r
+var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair\r
+if (document.cookie.match(re)) //if cookie found\r
+return document.cookie.match(re)[0].split("=")[1] //return its value\r
+return ""\r
+}\r
+\r
+function setCookie(name, value){\r
+document.cookie = name+"="+value //cookie value is domain wide (path=/)\r
+}
\ No newline at end of file