PageSourceSearch

https://acdic.net/modules/mod_featured_youtube_slider/library/contentslider.js

js acdic.net collected 2026-10-07 03:11:04 UTC 11,198 bytes, 248 lines download raw bytes

1//** Featured Content Slider script- (c) Dynamic Drive DHTML code library: http://www.dynamicdrive.com.
2//** May 2nd, 08'- Script rewritten and updated to 2.0.
3//** June 12th, 08'- Script updated to v 2.3, which adds the following features:
4			//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.
5			//2) Added setting to reveal a content either via "click" or "mouseover" of pagination links (default is former).
6			//3) Added public function for jumping to a particular slide within a Featured Content instance using an arbitrary link, for example.
7
8//** July 11th, 08'- Script updated to v 2.4:
9			//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")
10			//2) Fixed bug where the first slide disappears when the mouse clicks or mouses over it when page first loads.
11
12//** Dec 20th, 12'- v 2.41: Fixed bug with slider failing to load if the same script is used on different pages with different # of contents
13
14//** Jan 23rd, 13'- v2.5: Modified onChange event handler behaviour for more robustness , plus added section on embedding YouTube videos inside the Slider.
15				//Important: onChange(previndex, curindex, contentdivs) now uses a 0 based index system, where 0=1st slide, 1=2nd slide etc. Previously the count started at 1. 
16
17var featuredcontentslider={
18
19//3 variables below you can customize if desired:
20ajaxloadingmsg: '<div style="margin: 20px 0 0 20px"><img src="loading.gif" /> Fetching slider Contents. Please wait...</div>',
21bustajaxcache: true, //bust caching of external ajax page after 1st request?
22enablepersist: true, //persist to last content viewed when returning to page?
23
24settingcaches: {}, //object to cache "setting" object of each script instance
25
26jumpTo:function(fcsid, pagenumber){ //public function to go to a slide manually.
27	this.turnpage(this.settingcaches[fcsid], pagenumber)
28},
29
30ajaxconnect:function(setting){
31	var page_request = false
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 pageurl=setting.contentsource[1]
48	page_request.onreadystatechange=function(){
49		featuredcontentslider.ajaxpopulate(page_request, setting)
50	}
51	document.getElementById(setting.id).innerHTML=this.ajaxloadingmsg
52	var bustcache=(!this.bustajaxcache)? "" : (pageurl.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
53	page_request.open('GET', pageurl+bustcache, true)
54	page_request.send(null)
55},
56
57ajaxpopulate:function(page_request, setting){
58	if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)){
59		document.getElementById(setting.id).innerHTML=page_request.responseText
60		this.buildpaginate(setting)
61	}
62},
63
64buildcontentdivs:function(setting){
65	var alldivs=document.getElementById(setting.id).getElementsByTagName("div")
66	for (var i=0; i<alldivs.length; i++){
67		if (this.css(alldivs[i], "contentdiv", "check")){ //check for DIVs with class "contentdiv"
68			setting.contentdivs.push(alldivs[i])
69				alldivs[i].style.display="none" //collapse all content DIVs to begin with
70		}
71	}
72	if (setting.currentpage > setting.contentdivs.length){
73		setting.currentpage=1
74		setting.prevpage=1
75	}
76},
77
78buildpaginate:function(setting){
79	this.buildcontentdivs(setting)
80	var sliderdiv=document.getElementById(setting.id)
81	var pdiv=document.getElementById("paginate-"+setting.id)
82	var phtml=""
83	var toc=setting.toc
84	var nextprev=setting.nextprev
85	if (typeof toc=="string" && toc!="markup" || typeof toc=="object"){
86		for (var i=1; i<=setting.contentdivs.length; i++){
87			phtml+='<a href="#'+i+'" class="toc">'+(typeof toc=="string"? toc.replace(/#increment/, i) : toc[i-1])+'</a> '
88		}
89		phtml=(nextprev[0]!=''? '<a href="#prev" class="prev">'+nextprev[0]+'</a> ' : '') + phtml + (nextprev[1]!=''? '<a href="#next" class="next">'+nextprev[1]+'</a>' : '')
90		pdiv.innerHTML=phtml
91	}
92	var pdivlinks=pdiv.getElementsByTagName("a")
93	var toclinkscount=0 //var to keep track of actual # of toc links
94	for (var i=0; i<pdivlinks.length; i++){
95		if (this.css(pdivlinks[i], "toc", "check")){
96			if (toclinkscount>setting.contentdivs.length-1){ //if this toc link is out of range (user defined more toc links then there are contents)
97				pdivlinks[i].style.display="none" //hide this toc link
98				continue
99			}
100			pdivlinks[i].setAttribute("rel", ++toclinkscount) //store page number inside toc link
101			pdivlinks[i][setting.revealtype]=function(){
102				featuredcontentslider.turnpage(setting, this.getAttribute("rel"))
103				return false
104			}
105			setting.toclinks.push(pdivlinks[i])
106		}
107		else if (this.css(pdivlinks[i], "prev", "check") || this.css(pdivlinks[i], "next", "check")){ //check for links with class "prev" or "next"
108			pdivlinks[i].onclick=function(){
109				featuredcontentslider.turnpage(setting, this.className)
110				return false
111			}
112		}
113	}
114	this.turnpage(setting, setting.currentpage, true)
115	if (setting.autorotate[0]){ //if auto rotate enabled
116		pdiv[setting.revealtype]=function(){
117			featuredcontentslider.cleartimer(setting, window["fcsautorun"+sett
117ing.id])
118		}
119		sliderdiv["onclick"]=function(){ //stop content slider when slides themselves are clicked on
120			featuredcontentslider.cleartimer(setting, window["fcsautorun"+setting.id])
121		}
122		setting.autorotate[1]=setting.autorotate[1]+(1/setting.enablefade[1]*50) //add time to run fade animation (roughly) to delay between rotation
123	 this.autorotate(setting)
124	}
125},
126
127urlparamselect:function(fcsid){
128	var result=window.location.search.match(new RegExp(fcsid+"=(\\d+)", "i")) //check for "?featuredcontentsliderid=2" in URL
129	return (result==null)? null : parseInt(RegExp.$1) //returns null or index, where index (int) is the selected tab's index
130},
131
132turnpage:function(setting, thepage, autocall){
133	var currentpage=setting.currentpage //current page # before change
134	var totalpages=setting.contentdivs.length
135	var turntopage=(/prev/i.test(thepage))? currentpage-1 : (/next/i.test(thepage))? currentpage+1 : parseInt(thepage)
136	turntopage=(turntopage<1)? totalpages : (turntopage>totalpages)? 1 : turntopage //test for out of bound and adjust
137	if (turntopage==setting.currentpage && typeof autocall=="undefined") //if a pagination link is clicked on repeatedly
138		return
139	setting.currentpage=turntopage
140	setting.contentdivs[turntopage-1].style.zIndex=++setting.topzindex
141	this.cleartimer(setting, window["fcsfade"+setting.id])
142	setting.cacheprevpage=setting.prevpage
143	if (setting.enablefade[0]==true){
144		setting.curopacity=0
145		this.fadeup(setting)
146	}
147	if (setting.enablefade[0]==false){ //if fade is disabled, fire onChange event immediately (verus after fade is complete)
148		setting.contentdivs[setting.prevpage-1].style.display="none" //collapse last content div shown (it was set to "block")
149		try{
150		setting.onChange(setting.prevpage-1, setting.currentpage-1, setting.contentdivs)
151		} catch(e){console.log(e.message)}
152	}
153	setting.contentdivs[turntopage-1].style.visibility="visible"
154	setting.contentdivs[turntopage-1].style.display="block"
155	if (setting.prevpage<=setting.toclinks.length) //make sure pagination link exists (may not if manually defined via "markup", and user omitted)
156		this.css(setting.toclinks[setting.prevpage-1], "selected", "remove")
157	if (turntopage<=setting.toclinks.length) //make sure pagination link exists (may not if manually defined via "markup", and user omitted)
158		this.css(setting.toclinks[turntopage-1], "selected", "add")
159	setting.prevpage=turntopage
160	if (this.enablepersist)
161		this.setCookie("fcspersist"+setting.id, turntopage)
162},
163
164setopacity:function(setting, value){ //Sets the opacity of targetobject based on the passed in value setting (0 to 1 and in between)
165	var targetobject=setting.contentdivs[setting.currentpage-1]
166	if (targetobject.filters && targetobject.filters[0]){ //IE syntax
167		if (typeof targetobject.filters[0].opacity=="number") //IE6
168			targetobject.filters[0].opacity=value*100
169		else //IE 5.5
170			targetobject.style.filter="alpha(opacity="+value*100+")"
171	}
172	else if (typeof targetobject.style.MozOpacity!="undefined") //Old Mozilla syntax
173		targetobject.style.MozOpacity=value
174	else if (typeof targetobject.style.opacity!="undefined") //Standard opacity syntax
175		targetobject.style.opacity=value
176	setting.curopacity=value
177},
178
179fadeup:function(setting){
180	if (setting.curopacity<1){
181		this.setopacity(setting, setting.curopacity+setting.enablefade[1])
182		window["fcsfade"+setting.id]=setTimeout(function(){featuredcontentslider.fadeup(setting)}, 50)
183	}
184	else{ //when fade is complete
185		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)
186			setting.contentdivs[setting.cacheprevpage-1].style.display="none" //collapse last content div shown (it was set to "block")
187		try{
188			setting.onChange(setting.cacheprevpage-1, setting.currentpage-1, setting.contentdivs)
189		} catch(e){console.log(e.message)}
190	}
191},
192
193cleartimer:function(setting, timervar){
194	if (typeof timervar!="undefined"){
195		clearTimeout(timervar)
196		clearInterval(timervar)
197		if (setting.cacheprevpage!=setting.currentpage){ //if previous content isn't the same as the current shown div
198			setting.contentdivs[setting.cacheprevpage-1].style.display="none"
199		}
200	}
201},
202
203css:function(el, targetclass, action){
204	var needle=new RegExp("(^|\\s+)"+targetclass+"($|\\s+)", "ig")
205	if (action=="check")
206		return needle.test(el.className)
207	else if (action=="remove")
208		el.className=el.className.replace(needle, "")
209	else if (action=="add")
210		el.className+=" "+targetclass
211},
212
213autorotate:function(setting){
214 window["fcsautorun"+setting.id]=setInterval(function(){featuredcontentslider.turnpage(setting, "next")}, setting.autorotate[1])
215},
216
217getCookie:function(Name){ 
218	var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
219	if (document.cookie.match(re)) //if cookie found
220		return document.cookie.match(re)[0].split("=")[1] //return its value
221	return null
222},
223
224setCookie:function(name, value){
225	document.cookie = name+"="+value
226
227},
228
229
230init:function(setting){
231	var persistedpage=this.getCookie("fcspersist"+setting.id) || 1
232	var urlselectedpage=this.urlparamselect(setting.id) //returns null or index from: mypage.htm?featuredcontentsliderid=index
233	this.settingcaches[setting.id]=setting //cache "setting" object
234	setting.contentdivs=[]
235	setting.toclinks=[]
236	setting.topzindex=0
237	setting.currentpage=urlselectedpage || ((this.enablepersist)? persistedpage : 1)
238	setting.prevpage=setting.currentpage
239	setting.revealtype="on"+(setting.revealtype || "click")
240	setting.curopacity=0
241	setting.onChange=setting.onChange || function(){}
242	if (setting.contentsource[0]=="inline")
243		this.buildpaginate(setting)
244	if (setting.contentsource[0]=="ajax")
245		this.ajaxconnect(setting)
246}
247
248}

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.