PageSourceSearch

http://wretc.in/contentslider.js

js wretc.in collected 2026-10-08 02:44:15 UTC 20,480 bytes, 465 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
12var featuredcontentslider={
13
14//3 variables below you can customize if desired:
15ajaxloadingmsg: '<div style="margin: 20px 0 0 20px"><img src="loading.gif" /> Fetching slider Contents. Please wait...</div>',
16bustajaxcache: true, //bust caching of external ajax page after 1st request?
17enablepersist: true, //persist to last content viewed when returning to page?
18
19settingcaches: {}, //object to cache "setting" object of each script instance
20
21jumpTo:function(fcsid, pagenumber){ //public function to go to a slide manually.
22	this.turnpage(this.settingcaches[fcsid], pagenumber)
23},
24
25ajaxconnect:function(setting){
26	var page_request = false
27	if (window.ActiveXObject){ //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken)
28		try {
29		page_request = new ActiveXObject("Msxml2.XMLHTTP")
30		} 
31		catch (e){
32			try{
33			page_request = new ActiveXObject("Microsoft.XMLHTTP")
34			}
35			catch (e){}
36		}
37	}
38	else if (window.XMLHttpRequest) // if Mozilla, Safari etc
39		page_request = new XMLHttpRequest()
40	else
41		return false
42	var pageurl=setting.contentsource[1]
43	page_request.onreadystatechange=function(){
44		featuredcontentslider.ajaxpopulate(page_request, setting)
45	}
46	document.getElementById(setting.id).innerHTML=this.ajaxloadingmsg
47	var bustcache=(!this.bustajaxcache)? "" : (pageurl.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
48	page_request.open('GET', pageurl+bustcache, true)
49	page_request.send(null)
50},
51
52ajaxpopulate:function(page_request, setting){
53	if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)){
54		document.getElementById(setting.id).innerHTML=page_request.responseText
55		this.buildpaginate(setting)
56	}
57},
58
59buildcontentdivs:function(setting){
60	var alldivs=document.getElementById(setting.id).getElementsByTagName("div")
61	for (var i=0; i<alldivs.length; i++){
62		if (this.css(alldivs[i], "contentdiv", "check")){ //check for DIVs with class "contentdiv"
63			setting.contentdivs.push(alldivs[i])
64				alldivs[i].style.display="none" //collapse all content DIVs to begin with
65		}
66	}
67},
68
69buildpaginate:function(setting){
70	this.buildcontentdivs(setting)
71	var sliderdiv=document.getElementById(setting.id)
72	var pdiv=document.getElementById("paginate-"+setting.id)
73	var phtml=""
74	var toc=setting.toc
75	var nextprev=setting.nextprev
76	if (typeof toc=="string" && toc!="markup" || typeof toc=="object"){
77		for (var i=1; i<=setting.contentdivs.length; i++){
78			phtml+='<a href="#'+i+'" class="toc">'+(typeof toc=="string"? toc.replace(/#increment/, i) : toc[i-1])+'</a> '
79		}
80		phtml=(nextprev[0]!=''? '<a href="#prev" class="prev">'+nextprev[0]+'</a> ' : '') + phtml + (nextprev[1]!=''? '<a href="#next" class="next">'+nextprev[1]+'</a>' : '')
81		pdiv.innerHTML=phtml
82	}
83	var pdivlinks=pdiv.getElementsByTagName("a")
84	var toclinkscount=0 //var to keep track of actual # of toc links
85	for (var i=0; i<pdivlinks.length; i++){
86		if (this.css(pdivlinks[i], "toc", "check")){
87			if (toclinkscount>setting.contentdivs.length-1){ //if this toc link is out of range (user defined more toc links then there are contents)
88				pdivlinks[i].style.display="none" //hide this toc link
89				continue
90			}
91			pdivlinks[i].setAttribute("rel", ++toclinkscount) //store page number inside toc link
92			pdivlinks[i][setting.revealtype]=function(){
93				featuredcontentslider.turnpage(setting, this.getAttribute("rel"))
94				return false
95			}
96			setting.toclinks.push(pdivlinks[i])
97		}
98		else if (this.css(pdivlinks[i], "prev", "check") || this.css(pdivlinks[i], "next", "check")){ //check for links with class "prev" or "next"
99			pdivlinks[i].onclick=function(){
100				featuredcontentslider.turnpage(setting, this.className)
101				return false
102			}
103		}
104	}
105	this.turnpage(setting, setting.currentpage, true)
106	if (setting.autorotate[0]){ //if auto rotate enabled
107		pdiv[setting.revealtype]=function(){
108			featuredcontentslider.cleartimer(setting, window["fcsautorun"+sett
108ing.id])
109		}
110		sliderdiv["onclick"]=function(){ //stop content slider when slides themselves are clicked on
111			featuredcontentslider.cleartimer(setting, window["fcsautorun"+setting.id])
112		}
113		setting.autorotate[1]=setting.autorotate[1]+(1/setting.enablefade[1]*50) //add time to run fade animation (roughly) to delay between rotation
114	 this.autorotate(setting)
115	}
116},
117
118urlparamselect:function(fcsid){
119	var result=window.location.search.match(new RegExp(fcsid+"=(\\d+)", "i")) //check for "?featuredcontentsliderid=2" in URL
120	return (result==null)? null : parseInt(RegExp.$1) //returns null or index, where index (int) is the selected tab's index
121},
122
123turnpage:function(setting, thepage, autocall){
124	var currentpage=setting.currentpage //current page # before change
125	var totalpages=setting.contentdivs.length
126	var turntopage=(/prev/i.test(thepage))? currentpage-1 : (/next/i.test(thepage))? currentpage+1 : parseInt(thepage)
127	turntopage=(turntopage<1)? totalpages : (turntopage>totalpages)? 1 : turntopage //test for out of bound and adjust
128	if (turntopage==setting.currentpage && typeof autocall=="undefined") //if a pagination link is clicked on repeatedly
129		return
130	setting.currentpage=turntopage
131	setting.contentdivs[turntopage-1].style.zIndex=++setting.topzindex
132	this.cleartimer(setting, window["fcsfade"+setting.id])
133	setting.cacheprevpage=setting.prevpage
134	if (setting.enablefade[0]==true){
135		setting.curopacity=0
136		this.fadeup(setting)
137	}
138	if (setting.enablefade[0]==false){ //if fade is disabled, fire onChange event immediately (verus after fade is complete)
139		setting.contentdivs[setting.prevpage-1].style.display="none" //collapse last content div shown (it was set to "block")
140		setting.onChange(setting.prevpage, setting.currentpage)
141	}
142	setting.contentdivs[turntopage-1].style.visibility="visible"
143	setting.contentdivs[turntopage-1].style.display="block"
144	if (setting.prevpage<=setting.toclinks.length) //make sure pagination link exists (may not if manually defined via "markup", and user omitted)
145		this.css(setting.toclinks[setting.prevpage-1], "selected", "remove")
146	if (turntopage<=setting.toclinks.length) //make sure pagination link exists (may not if manually defined via "markup", and user omitted)
147		this.css(setting.toclinks[turntopage-1], "selected", "add")
148	setting.prevpage=turntopage
149	if (this.enablepersist)
150		this.setCookie("fcspersist"+setting.id, turntopage)
151},
152
153setopacity:function(setting, value){ //Sets the opacity of targetobject based on the passed in value setting (0 to 1 and in between)
154	var targetobject=setting.contentdivs[setting.currentpage-1]
155	if (targetobject.filters && targetobject.filters[0]){ //IE syntax
156		if (typeof targetobject.filters[0].opacity=="number") //IE6
157			targetobject.filters[0].opacity=value*100
158		else //IE 5.5
159			targetobject.style.filter="alpha(opacity="+value*100+")"
160	}
161	else if (typeof targetobject.style.MozOpacity!="undefined") //Old Mozilla syntax
162		targetobject.style.MozOpacity=value
163	else if (typeof targetobject.style.opacity!="undefined") //Standard opacity syntax
164		targetobject.style.opacity=value
165	setting.curopacity=value
166},
167
168fadeup:function(setting){
169	if (setting.curopacity<1){
170		this.setopacity(setting, setting.curopacity+setting.enablefade[1])
171		window["fcsfade"+setting.id]=setTimeout(function(){featuredcontentslider.fadeup(setting)}, 50)
172	}
173	else{ //when fade is complete
174		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)
175			setting.contentdivs[setting.cacheprevpage-1].style.display="none" //collapse last content div shown (it was set to "block")
176		setting.onChange(setting.cacheprevpage, setting.currentpage)
177	}
178},
179
180cleartimer:function(setting, timervar){
181	if (typeof timervar!="undefined"){
182		clearTimeout(timervar)
183		clearInterval(timervar)
184		if (setting.cacheprevpage!=setting.currentpage){ //if previous content isn't the same as the current shown div
185			setting.contentdivs[setting.cacheprevpage-1].style.display="none"
186		}
187	}
188},
189
190css:function(el, targetclass, action){
191	var needle=new RegExp("(^|\\s+)"+targetclass+"($|\\s+)", "ig")
192	if (action=="check")
193		return needle.test(el.className)
194	else if (action=="remove")
195		el.className=el.className.replace(needle, "")
196	else if (action=="add")
197		el.className+=" "+targetclass
198},
199
200autorotate:function(setting){
201 window["fcsautorun"+setting.id]=setInterval(function(){featuredcontentslider.turnpage(setting, "next")}, setting.autorotate[1])
202},
203
204getCookie:function(Name){ 
205	var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
206	if (document.cookie.match(re)) //if cookie found
207		return document.cookie.match(re)[0].split("=")[1] //return its value
208	return null
209},
210
211setCookie:function(name, value){
212	document.cookie = name+"="+value
213
214},
215
216
217init:function(setting){
218	var persistedpage=this.getCookie("fcspersist"+setting.id) || 1
219	var urlselectedpage=this.urlparamselect(setting.id) //returns null or index from: mypage.htm?featuredcontentsliderid=index
220	this.settingcaches[setting.id]=setting //cache "setting" object
221	setting.contentdivs=[]
222	setting.toclinks=[]
223	setting.topzindex=0
224	setting.currentpage=urlselectedpage || ((this.enablepersist)? persistedpage : 1)
225	setting.prevpage=setting.currentpage
226	setting.revealtype="on"+(setting.revealtype || "click")
227	setting.curopacity=0
228	setting.onChange=setting.onChange || function(){}
229	if (setting.contentsource[0]=="inline")
230		this.buildpaginate(setting)
231	if (setting.contentsource[0]=="ajax")
232		this.ajaxconnect(setting)
233}
234
235}
236
237
238
239
240
241
242var featuredcontentslider2={
243
244//3 variables below you can customize if desired:
245ajaxloadingmsg: '<div style="margin: 20px 0 0 20px"><img src="loading.gif" /> Fetching slider Contents. Please wait...</div>',
246bustajaxcache: true, //bust caching of external ajax page after 1st request?
247enablepersist: true, //persist to last content viewed when returning to page?
248
249settingcaches: {}, //object to cache "setting" object of each script instance
250
251jumpTo:function(fcsid, pagenumber){ //public function to go to a slide manually.
252	this.turnpage(this.settingcaches[fcsid], pagenumber)
253},
254
255ajaxconnect:function(setting){
256	var page_request = false
257	if (window.ActiveXObject){ //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken)
258		try {
259		page_request = new ActiveXObject("Msxml2.XMLHTTP")
260		} 
261		catch (e){
262			try{
263			page_request = new ActiveXObject("Microsoft.XMLHTTP")
264			}
265			catch (e){}
266		}
267	}
268	else if (window.XMLHttpRequest) // if Mozilla, Safari etc
269		page_request = new XMLHttpRequest()
270	else
271		return false
272	var pageurl=setting.contentsource[1]
273	page_request.onreadystatechange=function(){
274		featuredcontentslider.ajaxpopulate(page_request, setting)
275	}
276	document.getElementById(setting.id).innerHTML=this.ajaxloadingmsg
277	var bustcache=(!this.bustajaxcache)? "" : (pageurl.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
278	page_request.open('GET', pageurl+bustcache, true)
279	page_request.send(null)
280},
281
282ajaxpopulate:function(page_request, setting){
283	if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)){
284		document.getElementById(setting.id).innerHTML=page_request.responseText
285		this.buildpaginate(setting)
286	}
287},
288
289buildcontentdivs:function(setting){
290	var alldivs=document.getElementById(setting.id).getElementsByTagName("div")
291	for (var i=0; i<alldivs.length; i++){
292		if (this.css(alldivs[i], "contentdiv", "check")){ //check for DIVs with class "contentdiv"
293			setting.contentdivs.push(alldivs[i])
294				alldivs[i].style.display="none" //collapse all content DIVs to begin with
295		}
296	}
297},
298
299buildpaginate:function(setting){
300	this.buildcontentdivs(setting)
301	var sliderdiv=document.getElementById(setting.id)
302	var pdiv=document.getElementById("paginate-"+setting.id)
303	var phtml=""
304	var toc=setting.toc
305	var nextprev=setting.nextprev
306	if (typeof toc=="string" && toc!="markup" || typeof toc=="object"){
307		for (var i=1; i<=setting.contentdivs.length; i++){
308			phtml+='<a href="#'+i+'" class="toc">'+(typeof toc=="string"? toc.replace(/#increment/, i) : toc[i-1])+'</a> '
309		}
310		phtml=(nextprev[0]!=''? '<a href="#prev" class="prev">'+nextprev[0]+'</a> ' : '') + phtml + (nextprev[1]!=''? '<a href="#next" class="next">'+nextprev[1]+'</a>' : '')
311		pdiv.innerHTML=phtml
312	}
313	var pdivlinks=pdiv.getElementsByTagName("a")
314	var toclinkscount=0 //var to keep track of actual # of toc links
315	for (var i=0; i<pdivlinks.length; i++){
316		if (this.css(pdivlinks[i], "toc", "check")){
317			if (toclinkscount>setting.contentdivs.length-1){ //if this toc link is out of range (user defined more toc links then there are contents)
318				pdivlinks[i].style.display="none" //hide this toc link
319				continue
320			}
321			pdivlinks[i].setAttribute("rel", ++toclinkscount) //store page number inside toc link
322			pdivlinks[i][setting.revealtype]=function(){
323				featuredcontentslider.turnpage(setting, this.getAttribute("rel"))
324				return false
325			}
326			setting.toclinks.push(pdivlinks[i])
327		}
328		else if (this.css(pdivlinks[i], "prev", "check") || this.css(pdivlinks[i], "next", "check")){ //check for links with class "prev" or "next"
329			pdivlinks[i].onclick=function(){
330				featuredcontentslider.turnpage(setting, this.className)
331				return false
332			}
333		}
334	}
335	this.turnpage(setting, setting.currentpage, true)
336	if (setting.autorotate[0]){ //if auto rotate enabled
337		pdiv[setting.revealtype]=function(){
338			featuredcontentslider.cleartimer(setting, window["fcsautorun"+sett
338ing.id])
339		}
340		sliderdiv["onclick"]=function(){ //stop content slider when slides themselves are clicked on
341			featuredcontentslider.cleartimer(setting, window["fcsautorun"+setting.id])
342		}
343		setting.autorotate[1]=setting.autorotate[1]+(1/setting.enablefade[1]*50) //add time to run fade animation (roughly) to delay between rotation
344	 this.autorotate(setting)
345	}
346},
347
348urlparamselect:function(fcsid){
349	var result=window.location.search.match(new RegExp(fcsid+"=(\\d+)", "i")) //check for "?featuredcontentsliderid=2" in URL
350	return (result==null)? null : parseInt(RegExp.$1) //returns null or index, where index (int) is the selected tab's index
351},
352
353turnpage:function(setting, thepage, autocall){
354	var currentpage=setting.currentpage //current page # before change
355	var totalpages=setting.contentdivs.length
356	var turntopage=(/prev/i.test(thepage))? currentpage-1 : (/next/i.test(thepage))? currentpage+1 : parseInt(thepage)
357	turntopage=(turntopage<1)? totalpages : (turntopage>totalpages)? 1 : turntopage //test for out of bound and adjust
358	if (turntopage==setting.currentpage && typeof autocall=="undefined") //if a pagination link is clicked on repeatedly
359		return
360	setting.currentpage=turntopage
361	setting.contentdivs[turntopage-1].style.zIndex=++setting.topzindex
362	this.cleartimer(setting, window["fcsfade"+setting.id])
363	setting.cacheprevpage=setting.prevpage
364	if (setting.enablefade[0]==true){
365		setting.curopacity=0
366		this.fadeup(setting)
367	}
368	if (setting.enablefade[0]==false){ //if fade is disabled, fire onChange event immediately (verus after fade is complete)
369		setting.contentdivs[setting.prevpage-1].style.display="none" //collapse last content div shown (it was set to "block")
370		setting.onChange(setting.prevpage, setting.currentpage)
371	}
372	setting.contentdivs[turntopage-1].style.visibility="visible"
373	setting.contentdivs[turntopage-1].style.display="block"
374	if (setting.prevpage<=setting.toclinks.length) //make sure pagination link exists (may not if manually defined via "markup", and user omitted)
375		this.css(setting.toclinks[setting.prevpage-1], "selected", "remove")
376	if (turntopage<=setting.toclinks.length) //make sure pagination link exists (may not if manually defined via "markup", and user omitted)
377		this.css(setting.toclinks[turntopage-1], "selected", "add")
378	setting.prevpage=turntopage
379	if (this.enablepersist)
380		this.setCookie("fcspersist"+setting.id, turntopage)
381},
382
383setopacity:function(setting, value){ //Sets the opacity of targetobject based on the passed in value setting (0 to 1 and in between)
384	var targetobject=setting.contentdivs[setting.currentpage-1]
385	if (targetobject.filters && targetobject.filters[0]){ //IE syntax
386		if (typeof targetobject.filters[0].opacity=="number") //IE6
387			targetobject.filters[0].opacity=value*100
388		else //IE 5.5
389			targetobject.style.filter="alpha(opacity="+value*100+")"
390	}
391	else if (typeof targetobject.style.MozOpacity!="undefined") //Old Mozilla syntax
392		targetobject.style.MozOpacity=value
393	else if (typeof targetobject.style.opacity!="undefined") //Standard opacity syntax
394		targetobject.style.opacity=value
395	setting.curopacity=value
396},
397
398fadeup:function(setting){
399	if (setting.curopacity<1){
400		this.setopacity(setting, setting.curopacity+setting.enablefade[1])
401		window["fcsfade"+setting.id]=setTimeout(function(){featuredcontentslider.fadeup(setting)}, 50)
402	}
403	else{ //when fade is complete
404		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)
405			setting.contentdivs[setting.cacheprevpage-1].style.display="none" //collapse last content div shown (it was set to "block")
406		setting.onChange(setting.cacheprevpage, setting.currentpage)
407	}
408},
409
410cleartimer:function(setting, timervar){
411	if (typeof timervar!="undefined"){
412		clearTimeout(timervar)
413		clearInterval(timervar)
414		if (setting.cacheprevpage!=setting.currentpage){ //if previous content isn't the same as the current shown div
415			setting.contentdivs[setting.cacheprevpage-1].style.display="none"
416		}
417	}
418},
419
420css:function(el, targetclass, action){
421	var needle=new RegExp("(^|\\s+)"+targetclass+"($|\\s+)", "ig")
422	if (action=="check")
423		return needle.test(el.className)
424	else if (action=="remove")
425		el.className=el.className.replace(needle, "")
426	else if (action=="add")
427		el.className+=" "+targetclass
428},
429
430autorotate:function(setting){
431 window["fcsautorun"+setting.id]=setInterval(function(){featuredcontentslider.turnpage(setting, "next")}, setting.autorotate[1])
432},
433
434getCookie:function(Name){ 
435	var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
436	if (document.cookie.match(re)) //if cookie found
437		return document.cookie.match(re)[0].split("=")[1] //return its value
438	return null
439},
440
441setCookie:function(name, value){
442	document.cookie = name+"="+value
443
444},
445
446
447init:function(setting){
448	var persistedpage=this.getCookie("fcspersist"+setting.id) || 1
449	var urlselectedpage=this.urlparamselect(setting.id) //returns null or index from: mypage.htm?featuredcontentsliderid=index
450	this.settingcaches[setting.id]=setting //cache "setting" object
451	setting.contentdivs=[]
452	setting.toclinks=[]
453	setting.topzindex=0
454	setting.currentpage=urlselectedpage || ((this.enablepersist)? persistedpage : 1)
455	setting.prevpage=setting.currentpage
456	setting.revealtype="on"+(setting.revealtype || "click")
457	setting.curopacity=0
458	setting.onChange=setting.onChange || function(){}
459	if (setting.contentsource[0]=="inline")
460		this.buildpaginate(setting)
461	if (setting.contentsource[0]=="ajax")
462		this.ajaxconnect(setting)
463}
464
465}

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.