Forums / General Questions / Javascript As External File

Javascript As External File

Locked

Started by jill8026 on 24 Aug 2009, 10:42 AM · Views: 2,708

Results 1 to 12 of 12
This thread is locked. New replies are disabled.
24 Aug 2009, 10:42 AM
#1
jill8026 avatar

jill8026

Totally Zenned

Join Date:
May 2007
Posts:
461
Plugin Contributions:
0

Javascript As External File

I have read every thread, I have looked at the Wiki and in the doc file...I completely understand HOW and WHAT to do to get my javascript slide show to be external, but it is not working?

The slideshow works fine (as you can see right now at http://www.munyak.info/hhf/) with the following script code inserted directly into the html_header.php file - but of course I would like to get it out of there to validate!.

<script type="text/javascript">
      
/***********************************************
* Ultimate Fade-In Slideshow (v1.51): © Dynamic Drive (http://www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/
 
var fadeimages=new Array()
//SET IMAGE PATHS. Extend or contract array as needed
fadeimages[0]=["homeslide1.jpg", "", ""] //plain image syntax
fadeimages[1]=["homeslide2.jpg", "", ""] //image with link syntax
fadeimages[2]=["homeslide3.jpg", "", "_new"] //image with link and target syntax
 
 
var fadebgcolor="white"

////NO need to edit beyond here/////////////
 
var fadearray=new Array() //array to cache fadeshow instances
var fadeclear=new Array() //array to cache corresponding clearinterval pointers
 
var dom=(document.getElementById) //modern dom browsers
var iebrowser=document.all
 
function fadeshow(theimages, fadewidth, fadeheight, borderwidth, delay, pause, displayorder){
this.pausecheck=pause
this.mouseovercheck=0
this.delay=delay
this.degree=10 //initial opacity degree (10%)
this.curimageindex=0
this.nextimageindex=1
fadearray[fadearray.length]=this
this.slideshowid=fadearray.length-1
this.canvasbase="canvas"+this.slideshowid
this.curcanvas=this.canvasbase+"_0"
if (typeof displayorder!="undefined")
theimages.sort(function() {return 0.5 - Math.random();}) //thanks to Mike (aka Mwinter) :)
this.theimages=theimages
this.imageborder=parseInt(borderwidth)
this.postimages=new Array() //preload images
for (p=0;p<theimages.length;p++){
this.postimages[p]=new Image()
this.postimages[p].src=theimages[p][0]
}
 
var fadewidth=fadewidth+this.imageborder*2
var fadeheight=fadeheight+this.imageborder*2
 
if (iebrowser&&dom||dom) //if IE5+ or modern browsers (ie: Firefox)
document.write('<div id="master'+this.slideshowid+'" style="position:relative;width:'+fadewidth+'px;height:'+fadeheight+'px;overflow:hidden;"><div id="'+this.canvasbase+'_0" style="position:absolute;width:'+fadewidth+'px;height:'+fadeheight+'px;top:0;left:0;filter:progid:DXImageTransform.Microsoft.alpha(opacity=10);opacity:0.1;-moz-opacity:0.1;-khtml-opacity:0.1;background-color:'+fadebgcolor+'"></div><div id="'+this.canvasbase+'_1" style="position:absolute;width:'+fadewidth+'px;height:'+fadeheight+'px;top:0;left:0;filter:progid:DXImageTransform.Microsoft.alpha(opacity=10);opacity:0.1;-moz-opacity:0.1;-khtml-opacity:0.1;background-color:'+fadebgcolor+'"></div></div>')
else
document.write('<div><img name="defaultslide'+this.slideshowid+'" src="'+this.postimages[0].src+'"></div>')
 
if (iebrowser&&dom||dom) //if IE5+ or modern browsers such as Firefox
this.startit()
else{
this.curimageindex++
setInterval("fadearray["+this.slideshowid+"].rotateimage()", this.delay)
}
}

function fadepic(obj){
if (obj.degree<100){
obj.degree+=10
if (obj.tempobj.filters&&obj.tempobj.filters[0]){
if (typeof obj.tempobj.filters[0].opacity=="number") //if IE6+
obj.tempobj.filters[0].opacity=obj.degree
else //else if IE5.5-
obj.tempobj.style.filter="alpha(opacity="+obj.degree+")"
}
else if (obj.tempobj.style.MozOpacity)
obj.tempobj.style.MozOpacity=obj.degree/101
else if (obj.tempobj.style.KhtmlOpacity)
obj.tempobj.style.KhtmlOpacity=obj.degree/100
else if (obj.tempobj.style.opacity&&!obj.tempobj.filters)
obj.tempobj.style.opacity=obj.degree/101
}
else{
clearInterval(fadeclear[obj.slideshowid])
obj.nextcanvas=(obj.curcanvas==obj.canvasbase+"_0")? obj.canvasbase+"_0" : obj.canvasbase+"_1"
obj.tempobj=iebrowser? iebrowser[obj.nextcanvas] : document.getElementById(obj.nextcanvas)
obj.populateslide(obj.tempobj, obj.nextimageindex)
obj.nextimageindex=(obj.nextimageindex<obj.postimages.length-1)? obj.nextimageindex+1 : 0
setTimeout("fadearray["+obj.slideshowid+"].rotateimage()", obj.delay)
}
}
 
fadeshow.prototype.populateslide=function(picobj, picindex){
var slideHTML=""
if (this.theimages[picindex][1]!="") //if associated link exists for image
slideHTML='<a href="'+this.theimages[picindex][1]+'" target="'+this.theimages[picindex][2]+'">'
slideHTML+='<img src="'+this.postimages[picindex].src+'" border="'+this.imageborder+'px">'
if (this.theimages[picindex][1]!="") //if associated link exists for image
slideHTML+='</a>'
picobj.innerHTML=slideHTML
}
 
 
fadeshow.prototype.rotateimage=function(){
if (this.pausecheck==1) //if pause onMouseover enabled, cache object
var cacheobj=this
if (this.mouseovercheck==1)
setTimeout(function(){cacheobj.rotateimage()}, 100)
else if (iebrowser&&dom||dom){
this.resetit()
var crossobj=this.tempobj=iebrowser? iebrowser[this.curcanvas] : document.getElementById(this.curcanvas)
crossobj.style.zIndex++
fadeclear[this.slideshowid]=setInterval("fadepic(fadearray["+this.slideshowid+"])",50)
this.curcanvas=(this.curcanvas==this.canvasbase+"_0")? this.canvasbase+"_1" : this.canvasbase+"_0"
}
else{
var ns4imgobj=document.images['defaultslide'+this.slideshowid]
ns4imgobj.src=this.postimages[this.curimageindex].src
}
this.curimageindex=(this.curimageindex<this.postimages.length-1)? this.curimageindex+1 : 0
}
 
fadeshow.prototype.resetit=function(){
this.degree=10
var crossobj=iebrowser? iebrowser[this.curcanvas] : document.getElementById(this.curcanvas)
if (crossobj.filters&&crossobj.filters[0]){
if (typeof crossobj.filters[0].opacity=="number") //if IE6+
crossobj.filters(0).opacity=this.degree
else //else if IE5.5-
crossobj.style.filter="alpha(opacity="+this.degree+")"
}
else if (crossobj.style.MozOpacity)
crossobj.style.MozOpacity=this.degree/101
else if (crossobj.style.KhtmlOpacity)
crossobj.style.KhtmlOpacity=this.degree/100
else if (crossobj.style.opacity&&!crossobj.filters)
crossobj.style.opacity=this.degree/101
}
 
 
fadeshow.prototype.startit=function(){
var crossobj=iebrowser? iebrowser[this.curcanvas] : document.getElementById(this.curcanvas)
this.populateslide(crossobj, this.curimageindex)
if (this.pausecheck==1){ //IF SLIDESHOW SHOULD PAUSE ONMOUSEOVER
var cacheobj=this
var crossobjcontainer=iebrowser? iebrowser["master"+this.slideshowid] : document.getElementById("master"+this.slideshowid)
crossobjcontainer.onmouseover=function(){cacheobj.mouseovercheck=1}
crossobjcontainer.onmouseout=function(){cacheobj.mouseovercheck=0}
}
this.rotateimage()
}

</script>

I have taken this code, removed <script> and </script> created a file called jscript_slider.js and uploaded
to every possible folder..including includes/templates/hobbyhill/jscript and also in includes/modules/pages/index

Neither works...it just does nothing....here is what i have in my define main page as well:

<div id="slider">

<script type="text/javascript">
//new fadeshow(IMAGES_ARRAY_NAME, slideshow_width, slideshow_height, borderwidth, delay, pause (0=no, 1=yes), optionalRandomOrder)

new fadeshow(fadeimages, 600, 341, 0, 3000, 1, "R")



 

</script>

</div>

Obviously this is clearly user error.....but I am following the instructions and its not working...can any see anything I am doing wrong or something in my code that is not cutting it?!?!?!?

Thanks so much!!!

Jill || I Love Zen Cart Templates || 2 Dogs Design
I Love To Help But Let's Keep It Public Please To Help Others!

24 Aug 2009, 11:47 AM
#2
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: Javascript As External File

There are several different ways of loading javascript depending upon when and how widely you want it to be available. You've tried several of them! And so far as I can see they're all working, since I see the same javascript on the site three times.

However, the two occasions where the javascript is loaded as an external file, the file itself looks corrupt, which would give the impression that it wasn't working.

Kuroi Web Design and Development | Twitter

(Questions answered in the forum only - so that any forum member can benefit - not by personal message)

24 Aug 2009, 12:06 PM
#3
jill8026 avatar

jill8026

Totally Zenned

Join Date:
May 2007
Posts:
461
Plugin Contributions:
0

Re: Javascript As External File

Thanks Kuroi...how can you tell the file is corrupted though? I do not see an problems with it in Dreamweaver or Wordpad?!

Jill || I Love Zen Cart Templates || 2 Dogs Design
I Love To Help But Let's Keep It Public Please To Help Others!

24 Aug 2009, 12:11 PM
#4
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: Javascript As External File

If you look at the file in a browser there appears to be a pile of metadata that Dreamweaver and Wordpad might be filtering out.

Are you looking at it through Dreamweavers WYSIWYG viewer or the source code view?

Kuroi Web Design and Development | Twitter

(Questions answered in the forum only - so that any forum member can benefit - not by personal message)

24 Aug 2009, 12:18 PM
#5
jill8026 avatar

jill8026

Totally Zenned

Join Date:
May 2007
Posts:
461
Plugin Contributions:
0

Re: Javascript As External File

WOW, I see the problem....I just uploaded a new file to the moduls/pages directory...so I will take a peak at that...

But I have been looking at the source code in dreamweaver and it wasnt showing any of that...

Going to check the new upload....slideshow is still not showing though...I removed all other instances of that file so it is only in one directory now...

Jill || I Love Zen Cart Templates || 2 Dogs Design
I Love To Help But Let's Keep It Public Please To Help Others!

24 Aug 2009, 12:19 PM
#6
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: Javascript As External File

Your validation issue appears to happen because some of the site content has somehow ended up beyond your closing body tag, rather than due to this javascript.

Kuroi Web Design and Development | Twitter

(Questions answered in the forum only - so that any forum member can benefit - not by personal message)

24 Aug 2009, 12:23 PM
#7
jill8026 avatar

jill8026

Totally Zenned

Join Date:
May 2007
Posts:
461
Plugin Contributions:
0

Re: Javascript As External File

I know about that part...I am fixing that too..but the slideshow when it was included in the home page file gave me another 90 or so errors....when I remove it it gives me what you see now...the few things that are left I will fix after I get this working....

I cleaned up the .js file...have it in the

http://www.munyak.info/hhf/includes/modules/pages/index/jscript_slider.js

directory.....so now i have a white box on the home page...but still no slideshow....what else am I missing??!?!?!

Jill || I Love Zen Cart Templates || 2 Dogs Design
I Love To Help But Let's Keep It Public Please To Help Others!

24 Aug 2009, 12:26 PM
#8
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: Javascript As External File

The version you have up now is loading correctly, and will display in a browser, but won't work. Somehow it is encoded as UTF-16 Little Endian. I wonder if the earlier issue was an encoding one too. This may be happening during the file transfer, but I'm afraid I'm not big on encoding issues and what triggers them. :(

Kuroi Web Design and Development | Twitter

(Questions answered in the forum only - so that any forum member can benefit - not by personal message)

24 Aug 2009, 12:51 PM
#9
jill8026 avatar

jill8026

Totally Zenned

Join Date:
May 2007
Posts:
461
Plugin Contributions:
0

Re: Javascript As External File

Kuroi...thank you....at least that gives me a direction to look into the rest....seems like these "weird things" only happen to me....finally got the whole site validated...just need to fix this then I can finish the rest....uuggh

Jill || I Love Zen Cart Templates || 2 Dogs Design
I Love To Help But Let's Keep It Public Please To Help Others!

24 Aug 2009, 1:04 PM
#10
jill8026 avatar

jill8026

Totally Zenned

Join Date:
May 2007
Posts:
461
Plugin Contributions:
0

Re: Javascript As External File

Yes and these weird things happen because I forget silly things! Forgot to put in the proper image name when I recopied the code...all is now good! I never thought to go direct to the file in the browser to look for problems...s o thank you for that tip!!!!!!

Once again you are my hero!!!!!

Jill || I Love Zen Cart Templates || 2 Dogs Design
I Love To Help But Let's Keep It Public Please To Help Others!

7 Sep 2009, 5:56 PM
#11
perkiekat avatar

perkiekat

Zen Follower

Join Date:
Aug 2009
Location:
Carmi, IL
Posts:
354
Plugin Contributions:
0

Re: Javascript As External File

Ok. I'm having a very difficult time getting the code to work on the site I'm currently building. I would like the banner area to have a JavaScript SlideShow just like the one shown at the beginning of this thread from Dynamic Drive.

Here is the website I want to do this. i want it placed in the banner area and not in the main page area where you see "Welcome to Gayles Gallery..." I have been told to place the code in the tpl_header.php replacing the header image code. I have done this. I have also created a .js file and placed the script inside there. I hardcoded the script in the html_header.php hoping this would help grab the script, however, nothing is showing up. I disabled the banner you see now, but still nothing.

Could someone please tell me what I am doing wrong? Here is the code I created, maybe it isn't correct??

<script type="text/javascript"> /*********************************************** * Ultimate Fade-In Slideshow (v1.5): © Dynamic Drive (<http://www.dynamicdrive.com>) * This notice MUST stay intact for legal use * Visit <http://www.dynamicdrive.com/> for this script and 100s more. ***********************************************/ var fadeimages=new Array() //SET IMAGE PATHS. Extend or contract array as needed //this is the actual images to fade and the target pages on click fadeimages[0]=["includes/templates/premium1a/images/rotate1.gif", ", ""] fadeimages[1]=["/includes/templates/premium1a/images/rotate2.gif", ", ""] fadeimages[2]=["/includes/templates/premium1a/images/rotate3.gif", ", ""] fadeimages[3]=["/includes/templates/premium1a/images/rotate4.gif", ", ""] fadeimages[4]=["/includes/templates/premium1a/images/rotate5.gif", ", ""] fadeimages[5]=["/includes/templates/premium1a/images/rotate6.gif", ", ""] fadeimages[6]=["/includes/templates/premium1a/images/rotate7.gif", ", ""] fadeimages[7]=["/includes/templates/premium1a/images/rotate8.gif", ", ""] //var fadeimages2=new Array() //2nd array set example. Remove or add more sets as needed. //SET IMAGE PATHS. Extend or contract array as needed //fadeimages2[0]=["photo1.jpg", "", ""] //plain image syntax //fadeimages2[1]=["photo2.jpg", "http://www.cssdrive.com", ""] //image with link syntax //fadeimages2[2]=["photo3.jpg", "http://www.javascriptkit.com", "_new"] //image with link and target syntax var fadebgcolor="white" ////NO need to edit beyond here///////////// var fadearray=new Array() //array to cache fadeshow instances var fadeclear=new Array() //array to cache corresponding clearinterval pointers var dom=(document.getElementById) //modern dom browsers var iebrowser=document.all function fadeshow(theimages, fadewidth, fadeheight, borderwidth, delay, pause, displayorder){ this.pausecheck=pause this.mouseovercheck=0 this.delay=delay this.degree=10 //initial opacity degree (10%) this.curimageindex=0 this.nextimageindex=1 fadearray[fadearray.length]=this this.slideshowid=fadearray.length-1 this.canvasbase="canvas"+this.slideshowid this.curcanvas=this.canvasbase+"_0" if (typeof displayorder!="undefined") theimages.sort(function() {return 0.5 - Math.random();}) //thanks to Mike (aka Mwinter) :) this.theimages=theimages this.imageborder=parseInt(borderwidth) this.postimages=new Array() //preload images for (p=0;p<theimages.length;p++){ this.postimages[p]=new Image() this.postimages[p].src=theimages[p][0] } var fadewidth=fadewidth+this.imageborder*2 var fadeheight=fadeheight+this.imageborder*2 if (iebrowser&&dom||dom) //if IE5+ or modern browsers (ie: Firefox) document.write('<div id="master'+this.slideshowid+'" style="position:relative;width:'+fadewidth+'px;height:'+fadeheight+'px;overflow:hidden;"><div id="'+this.canvasbase+'_0" style="position:absolute;width:'+fadewidth+'px;height:'+fadeheight+'px;top:0;left:0;filter:progid:DXImageTransform.Microsoft.alpha(opacity=10);-moz-opacity:10;-khtml-opacity:10;background-color:'+fadebgcolor+'"></div><div id="'+this.canvasbase+'_1" style="position:absolute;width:'+fadewidth+'px;height:'+fadeheight+'px;top:0;left:0;filter:progid:DXImageTransform.Microsoft.alpha(opacity=10);-moz-opacity:10;background-color:'+fadebgcolor+'"></div></div>') else document.write('<div><img name="defaultslide'+this.slideshowid+'" src="'+this.postimages[0].src+'"></div>') if (iebrowser&&dom||dom) //if IE5+ or modern browsers such as Firefox this.startit() else{ this.curimageindex++ setInterval("fadearray["+this.slideshowid+"].rotateimage()", this.delay) } } function fadepic(obj){ if (obj.degree<100){ obj.degree+=10 if (obj.tempobj.filters&&obj.tempobj.filters[0]){ if (typeof obj.tempobj.filters[0].opacity=="number") //if IE6+ obj.tempobj.filters[0].opacity=obj.degree else //else if IE5.5- obj.tempobj.style.filter="alpha(opacity="+obj.degree+")" } else if (obj.tempobj.style.MozOpacity) obj.tempobj.style.MozOpacity=obj.degree/101 else if (obj.tempobj.style.KhtmlOpacity) obj.tempobj.style.KhtmlOpacity=obj.degree/100 } else{ clearInterval(fadeclear[obj.slideshowid]) obj.nextcanvas=(obj.curcanvas==obj.canvasbase+"_0")? obj.canvasbase+"_0" : obj.canvasbase+"_1" obj.tempobj=iebrowser? iebrowser[obj.nextcanvas] : document.getElementById(obj.nextcanvas) obj.populateslide(obj.tempobj, obj.nextimageindex) obj.nextimageindex=(obj.nextimageindex<obj.postimages.length-1)? obj.nextimageindex+1 : 0 setTimeout("fadearray["+obj.slideshowid+"].rotateimage()", obj.delay) } } fadeshow.prototype.populateslide=function(picobj, picindex){ var slideHTML="" if (this.theimages[picindex][1]!="") //if associated link exists for image slideHTML='<a href="'+this.theimages[picindex][1]+'" target="'+this.theimages[picindex][2]+'">' slideHTML+='<img src="'+this.postimages[picindex].src+'" border="'+this.imageborder+'px">' if (this.theimages[picindex][1]!="") //if associated link exists for image slideHTML+='</a>' picobj.innerHTML=slideHTML } fadeshow.prototype.rotateimage=function(){ if (this.pausecheck==1) //if pause onMouseover enabled, cache object var cacheobj=this if (this.mouseovercheck==1) setTimeout(function(){cacheobj.rotateimage()}, 100) else if (iebrowser&&dom||dom){ this.resetit() var crossobj=this.tempobj=iebrowser? iebrowser[this.curcanvas] : document.getElementById(this.curcanvas) crossobj.style.zIndex++ fadeclear[this.slideshowid]=setInterval("fadepic(fadearray["+this.slideshowid+"])",50) this.curcanvas=(this.curcanvas==this.canvasbase+"_0")? this.canvasbase+"_1" : this.canvasbase+"_0" } else{ var ns4imgobj=document.images['defaultslide'+this.slideshowid] ns4imgobj.src=this.postimages[this.curimageindex].src } this.curimageindex=(this.curimageindex<this.postimages.length-1)? this.curimageindex+1 : 0 } fadeshow.prototype.resetit=function(){ this.degree=10 var crossobj=iebrowser? iebrowser[this.curcanvas] : document.getElementById(this.curcanvas) if (crossobj.filters&&crossobj.filters[0]){ if (typeof crossobj.filters[0].opacity=="number") //if IE6+ crossobj.filters(0).opacity=this.degree else //else if IE5.5- crossobj.style.filter="alpha(opacity="+this.degree+")" } else if (crossobj.style.MozOpacity) crossobj.style.MozOpacity=this.degree/101 else if (crossobj.style.KhtmlOpacity) crossobj.style.KhtmlOpacity=obj.degree/100 } fadeshow.prototype.startit=function(){ var crossobj=iebrowser? iebrowser[this.curcanvas] : document.getElementById(this.curcanvas) this.populateslide(crossobj, this.curimageindex) if (this.pausecheck==1){ //IF SLIDESHOW SHOULD PAUSE ONMOUSEOVER var cacheobj=this var crossobjcontainer=iebrowser? iebrowser["master"+this.slideshowid] : document.getElementById("master"+this.slideshowid) crossobjcontainer.onmouseover=function(){cacheobj.mouseovercheck=1} crossobjcontainer.onmouseout=function(){cacheobj.mouseovercheck=0} } this.rotateimage() } </script>

Any input from anyone who knows what I am doing wrong, please let me know. I will appreciate this very much! By the way, I do not want the slideshow to have links, just a show.

Zen Cart user all the way for online stores!

12 Sep 2009, 3:12 PM
#12
perkiekat avatar

perkiekat

Zen Follower

Join Date:
Aug 2009
Location:
Carmi, IL
Posts:
354
Plugin Contributions:
0

Re: Javascript As External File

I have it showing now. Had code in wrong file :blush:

Zen Cart user all the way for online stores!