Initial dev repository
[kcls-web.git] / opac / skin / kcls / js / contentslider.js
diff --git a/opac/skin/kcls/js/contentslider.js b/opac/skin/kcls/js/contentslider.js
new file mode 100644 (file)
index 0000000..f583697
--- /dev/null
@@ -0,0 +1,235 @@
+//** Featured Content Slider script- (c) Dynamic Drive DHTML code library: http://www.dynamicdrive.com.\r
+//** May 2nd, 08'- Script rewritten and updated to 2.0.\r
+//** June 12th, 08'- Script updated to v 2.3, which adds the following features:\r
+                       //1) Changed behavior of script to actually collapse the previous content when the active one is shown, instead of just tucking it underneath the later.\r
+                       //2) Added setting to reveal a content either via "click" or "mouseover" of pagination links (default is former).\r
+                       //3) Added public function for jumping to a particular slide within a Featured Content instance using an arbitrary link, for example.\r
+\r
+//** July 11th, 08'- Script updated to v 2.4:\r
+                       //1) Added ability to select a particular slide when the page first loads using a URL parameter (ie: mypage.htm?myslider=4 to select 4th slide in "myslider")\r
+                       //2) Fixed bug where the first slide disappears when the mouse clicks or mouses over it when page first loads.\r
+\r
+var featuredcontentslider={\r
+\r
+//3 variables below you can customize if desired:\r
+ajaxloadingmsg: '',\r
+bustajaxcache: true, //bust caching of external ajax page after 1st request?\r
+enablepersist: true, //persist to last content viewed when returning to page?\r
+\r
+settingcaches: {}, //object to cache "setting" object of each script instance\r
+\r
+jumpTo:function(fcsid, pagenumber){ //public function to go to a slide manually.\r
+       this.turnpage(this.settingcaches[fcsid], pagenumber)\r
+},\r
+\r
+ajaxconnect:function(setting){\r
+       var page_request = false\r
+       if (window.ActiveXObject){ //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken)\r
+               try {\r
+               page_request = new ActiveXObject("Msxml2.XMLHTTP")\r
+               } \r
+               catch (e){\r
+                       try{\r
+                       page_request = new ActiveXObject("Microsoft.XMLHTTP")\r
+                       }\r
+                       catch (e){}\r
+               }\r
+       }\r
+       else if (window.XMLHttpRequest) // if Mozilla, Safari etc\r
+               page_request = new XMLHttpRequest()\r
+       else\r
+               return false\r
+       var pageurl=setting.contentsource[1]\r
+       page_request.onreadystatechange=function(){\r
+               featuredcontentslider.ajaxpopulate(page_request, setting)\r
+       }\r
+       document.getElementById(setting.id).innerHTML=this.ajaxloadingmsg\r
+       var bustcache=(!this.bustajaxcache)? "" : (pageurl.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()\r
+       page_request.open('GET', pageurl+bustcache, true)\r
+       page_request.send(null)\r
+},\r
+\r
+ajaxpopulate:function(page_request, setting){\r
+       if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)){\r
+               document.getElementById(setting.id).innerHTML=page_request.responseText\r
+               this.buildpaginate(setting)\r
+       }\r
+},\r
+\r
+buildcontentdivs:function(setting){\r
+       var alldivs=document.getElementById(setting.id).getElementsByTagName("div")\r
+       for (var i=0; i<alldivs.length; i++){\r
+               if (this.css(alldivs[i], "contentdiv", "check")){ //check for DIVs with class "contentdiv"\r
+                       setting.contentdivs.push(alldivs[i])\r
+                               alldivs[i].style.display="none" //collapse all content DIVs to begin with\r
+               }\r
+       }\r
+},\r
+\r
+buildpaginate:function(setting){\r
+       this.buildcontentdivs(setting)\r
+       var sliderdiv=document.getElementById(setting.id)\r
+       var pdiv=document.getElementById("paginate-"+setting.id)\r
+       var phtml=""\r
+       var toc=setting.toc\r
+       var nextprev=setting.nextprev\r
+       if (typeof toc=="string" && toc!="markup" || typeof toc=="object"){\r
+               for (var i=1; i<=setting.contentdivs.length; i++){\r
+                       phtml+='<a href="#'+i+'" class="toc">'+(typeof toc=="string"? toc.replace(/#increment/, i) : toc[i-1])+'</a> '\r
+               }\r
+               phtml=(nextprev[0]!=''? '<a href="#prev" class="prev">'+nextprev[0]+'</a> ' : '') + phtml + (nextprev[1]!=''? '<a href="#next" class="next">'+nextprev[1]+'</a>' : '')\r
+               pdiv.innerHTML=phtml\r
+       }\r
+       var pdivlinks=pdiv.getElementsByTagName("a")\r
+       var toclinkscount=0 //var to keep track of actual # of toc links\r
+       for (var i=0; i<pdivlinks.length; i++){\r
+               if (this.css(pdivlinks[i], "toc", "check")){\r
+                       if (toclinkscount>setting.contentdivs.length-1){ //if this toc link is out of range (user defined more toc links then there are contents)\r
+                               pdivlinks[i].style.display="none" //hide this toc link\r
+                               continue\r
+                       }\r
+                       pdivlinks[i].setAttribute("rel", ++toclinkscount) //store page number inside toc link\r
+                       pdivlinks[i][setting.revealtype]=function(){\r
+                               featuredcontentslider.turnpage(setting, this.getAttribute("rel"))\r
+                               return false\r
+                       }\r
+                       setting.toclinks.push(pdivlinks[i])\r
+               }\r
+               else if (this.css(pdivlinks[i], "prev", "check") || this.css(pdivlinks[i], "next", "check")){ //check for links with class "prev" or "next"\r
+                       pdivlinks[i].onclick=function(){\r
+                               featuredcontentslider.turnpage(setting, this.className)\r
+                               return false\r
+                       }\r
+               }\r
+       }\r
+       this.turnpage(setting, setting.currentpage, true)\r
+       if (setting.autorotate[0]){ //if auto rotate enabled\r
+               pdiv[setting.revealtype]=function(){\r
+                       featuredcontentslider.cleartimer(setting, window["fcsautorun"+setting.id])\r
+               }\r
+               sliderdiv["onclick"]=function(){ //stop content slider when slides themselves are clicked on\r
+                       featuredcontentslider.cleartimer(setting, window["fcsautorun"+setting.id])\r
+               }\r
+               setting.autorotate[1]=setting.autorotate[1]+(1/setting.enablefade[1]*50) //add time to run fade animation (roughly) to delay between rotation\r
+        this.autorotate(setting)\r
+       }\r
+},\r
+\r
+urlparamselect:function(fcsid){\r
+       var result=window.location.search.match(new RegExp(fcsid+"=(\\d+)", "i")) //check for "?featuredcontentsliderid=2" in URL\r
+       return (result==null)? null : parseInt(RegExp.$1) //returns null or index, where index (int) is the selected tab's index\r
+},\r
+\r
+turnpage:function(setting, thepage, autocall){\r
+       var currentpage=setting.currentpage //current page # before change\r
+       var totalpages=setting.contentdivs.length\r
+       var turntopage=(/prev/i.test(thepage))? currentpage-1 : (/next/i.test(thepage))? currentpage+1 : parseInt(thepage)\r
+       turntopage=(turntopage<1)? totalpages : (turntopage>totalpages)? 1 : turntopage //test for out of bound and adjust\r
+       if (turntopage==setting.currentpage && typeof autocall=="undefined") //if a pagination link is clicked on repeatedly\r
+               return\r
+       setting.currentpage=turntopage\r
+       setting.contentdivs[turntopage-1].style.zIndex=++setting.topzindex\r
+       this.cleartimer(setting, window["fcsfade"+setting.id])\r
+       setting.cacheprevpage=setting.prevpage\r
+       if (setting.enablefade[0]==true){\r
+               setting.curopacity=0\r
+               this.fadeup(setting)\r
+       }\r
+       if (setting.enablefade[0]==false){ //if fade is disabled, fire onChange event immediately (verus after fade is complete)\r
+               setting.contentdivs[setting.prevpage-1].style.display="none" //collapse last content div shown (it was set to "block")\r
+               setting.onChange(setting.prevpage, setting.currentpage)\r
+       }\r
+       setting.contentdivs[turntopage-1].style.visibility="visible"\r
+       setting.contentdivs[turntopage-1].style.display="block"\r
+       if (setting.prevpage<=setting.toclinks.length) //make sure pagination link exists (may not if manually defined via "markup", and user omitted)\r
+               this.css(setting.toclinks[setting.prevpage-1], "selected", "remove")\r
+       if (turntopage<=setting.toclinks.length) //make sure pagination link exists (may not if manually defined via "markup", and user omitted)\r
+               this.css(setting.toclinks[turntopage-1], "selected", "add")\r
+       setting.prevpage=turntopage\r
+       if (this.enablepersist)\r
+               this.setCookie("fcspersist"+setting.id, turntopage)\r
+},\r
+\r
+setopacity:function(setting, value){ //Sets the opacity of targetobject based on the passed in value setting (0 to 1 and in between)\r
+       var targetobject=setting.contentdivs[setting.currentpage-1]\r
+       if (targetobject.filters && targetobject.filters[0]){ //IE syntax\r
+               if (typeof targetobject.filters[0].opacity=="number") //IE6\r
+                       targetobject.filters[0].opacity=value*100\r
+               else //IE 5.5\r
+                       targetobject.style.filter="alpha(opacity="+value*100+")"\r
+       }\r
+       else if (typeof targetobject.style.MozOpacity!="undefined") //Old Mozilla syntax\r
+               targetobject.style.MozOpacity=value\r
+       else if (typeof targetobject.style.opacity!="undefined") //Standard opacity syntax\r
+               targetobject.style.opacity=value\r
+       setting.curopacity=value\r
+},\r
+\r
+fadeup:function(setting){\r
+       if (setting.curopacity<1){\r
+               this.setopacity(setting, setting.curopacity+setting.enablefade[1])\r
+               window["fcsfade"+setting.id]=setTimeout(function(){featuredcontentslider.fadeup(setting)}, 10)\r
+       }\r
+       else{ //when fade is complete\r
+               if (setting.cacheprevpage!=setting.currentpage) //if previous content isn't the same as the current shown div (happens the first time the page loads/ script is run)\r
+                       setting.contentdivs[setting.cacheprevpage-1].style.display="none" //collapse last content div shown (it was set to "block")\r
+               setting.onChange(setting.cacheprevpage, setting.currentpage)\r
+       }\r
+},\r
+\r
+cleartimer:function(setting, timervar){\r
+       if (typeof timervar!="undefined"){\r
+               clearTimeout(timervar)\r
+               clearInterval(timervar)\r
+               if (setting.cacheprevpage!=setting.currentpage){ //if previous content isn't the same as the current shown div\r
+                       setting.contentdivs[setting.cacheprevpage-1].style.display="none"\r
+               }\r
+       }\r
+},\r
+\r
+css:function(el, targetclass, action){\r
+       var needle=new RegExp("(^|\\s+)"+targetclass+"($|\\s+)", "ig")\r
+       if (action=="check")\r
+               return needle.test(el.className)\r
+       else if (action=="remove")\r
+               el.className=el.className.replace(needle, "")\r
+       else if (action=="add")\r
+               el.className+=" "+targetclass\r
+},\r
+\r
+autorotate:function(setting){\r
+ window["fcsautorun"+setting.id]=setInterval(function(){featuredcontentslider.turnpage(setting, "next")}, setting.autorotate[1])\r
+},\r
+\r
+getCookie:function(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 null\r
+},\r
+\r
+setCookie:function(name, value){\r
+       document.cookie = name+"="+value\r
+\r
+},\r
+\r
+\r
+init:function(setting){\r
+       var persistedpage=this.getCookie("fcspersist"+setting.id) || 1\r
+       var urlselectedpage=this.urlparamselect(setting.id) //returns null or index from: mypage.htm?featuredcontentsliderid=index\r
+       this.settingcaches[setting.id]=setting //cache "setting" object\r
+       setting.contentdivs=[]\r
+       setting.toclinks=[]\r
+       setting.topzindex=0\r
+       setting.currentpage=urlselectedpage || ((this.enablepersist)? persistedpage : 1)\r
+       setting.prevpage=setting.currentpage\r
+       setting.revealtype="on"+(setting.revealtype || "click")\r
+       setting.curopacity=0\r
+       setting.onChange=setting.onChange || function(){}\r
+       if (setting.contentsource[0]=="inline")\r
+               this.buildpaginate(setting)\r
+       if (setting.contentsource[0]=="ajax")\r
+               this.ajaxconnect(setting)\r
+}\r
+\r
+}
\ No newline at end of file