PDA

View Full Version : Storing the Ultimate Fading Slideshow in a separate file



photodah
05-31-2007, 04:17 PM
I am trying to put the Ultimate Fade-in slideshow (v1.5) into a different .js file so I don't have to have all that code in the head of my site, also so I can more easily use it on several pages. And I am not having any luck. I am new at this and have done my best to try several things. Also I am using another script for a menu, so do I have to identify them differently so that they work and if so how do I do that.

Thanks for who ever helps the newbee

Veronica
05-31-2007, 07:51 PM
Select everything from the javascript code but not the <script type="text/javascript"> at the top or the </script> at the bottom.
Copy and paste into a file called fadin.js

Then in the head of your document, delete the javascript code (including the script open and close tags) and replace it with a link to your external script:

<script type="text/javascript" src="fadin.js">
/***********************************************
* Ultimate Fade-In Slideshow (v1.5): Dynamic Drive DHTML code library (http://www.dynamicdrive.com)
* Visit DynamicDrive.com for hundreds of original DHTML scripts
* This notice must stay intact for legal use
***********************************************/
</script>

Do the same thing for the second script, giving it a different name, and adding a link to this second js file in the head of your document.

The above link assumes you've put the js files in the same directory. If you put them in a different directory, you would need to just put the path to that as your src.

(Note to John - thanks again - hopefully this is my last edit!)

jscheuer1
05-31-2007, 08:38 PM
Veronica, please don't advise folks to disregard the DD usage policy which, among other things, states that the credit must remain in the source code of the page(s) that use the script.


replace it with a link to your external script:

<script type="text/javascript" src="fadin.js"></script>

If you do that, you will be in violation of the Dynamic Drive Usage policy. Other than that, the advice is sound. Here is my more verbose set of tips for making a script external (pay particular attention to 'One other thing' at the end):


Use a text editor to save the script, call it 'file_name.js' where 'file_name' can be any valid file name of your choosing. Substitute the name of your external .js file for some.js in the below:


<script src="some.js" type="text/javascript"></script>

Common problems arise when:

1 ) The script file is not in the directory specified. In the above example it must be in the same directory as the page(s) that use it. Below, it can be in the scripts directory off of the root of a domain:


<script src="http://www.somedomain.com/scripts/some.js" type="text/javascript"></script>

2 ) Opening, closing and/or 'hiding' tags are left in the external file. This means that you must strip:
<script>
<!--and
//-->
</script>and any of their many variations from the beginning and end of the external file.

3 ) The external call (<script src="some.js" type="text/javascript"></script>) is not inserted into the page at the correct spot. The external call must be inserted at the same place on the page where the script was/would have been.

4 ) Paths to other files (if) used by the script are no longer valid due to its location. This is only a problem if the external script is kept in a different directory than the page it was working on when it was an internal script. To correct this, use absolute paths inside the script. Absolute path examples:


http://www.somedomain.com/images/button.gif

http://www.somedomain.com/~mysitename/index.html

5 ) Inappropriately combining two or more scripts into one external file. Usually external scripts can be combined if one knows enough about scripting to do so properly. Even then it is possible to overlook something.

A rule of thumb when testing is, if it won't work on the page, it won't work as an external file either.

One other thing, if this is a DD script or any script that requires the credit remain for legal use, include the credit in the on page call, ex:


<script src="some.js" type="text/javascript">
/***********************************************
* IFrame SSI script II- &#169; Dynamic Drive DHTML code library (http://www.dynamicdrive.com)
* Visit DynamicDrive.com for hundreds of original DHTML scripts
* This notice must stay intact for legal use
***********************************************/
</script>

Make sure to retain all the 'decorations', as these include begin and end javascript comment delimiters without which the script won't function.

Veronica
05-31-2007, 09:32 PM
Sorry! I thought the credit in the js file was the way to do it. Now I know better. I fixed in in the original reply.

Thanks for correcting that - and also thank for all the help you give people on this site.:)

jscheuer1
06-01-2007, 05:20 AM
Sorry! I thought the credit in the js file was the way to do it. Now I know better. I fixed in in the original reply.

Thanks for correcting that - and also thank for all the help you give people on this site.:)

That's OK, I figured it was just an oversight on your part, as you usually know what you are talking about. Thanks for fixing it (although the credit you featured is from a different script), and Thank You for all the help you provide the folks here in these forums.

Just to clarify, for this particular script, it should look something like so:


<script src="some.js" 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.
***********************************************/
</script>

To photodah,

Warning: Please include a link to the DD script in question in your post. See this thread (http://www.dynamicdrive.com/forums/showthread.php?t=6) for the proper posting format when asking a question.

peebs24
08-27-2007, 04:40 PM
Hi John & Veronica,
I just tried copying the script into a separate .js file and it diesn't work properly. When the script is embedded it works fine.
The problem is that the Slide show script is in 2 parts - one in the <head> and one in the <body>. If you call up the entire .js file from the <head> then the <body> part doesn't work properly. When the script is embedded, the <body> part of the script is in a <div> to give it placement and it works OK.
I have tried putting just the <head> part of the .js file and leaving the <body> part of the script embedded but, of course, when the .js file has run it leaves no variables for the embedded bit to work on.
I posted the same question earlier today :-

"I am new to scripts and have been using the ultimate fader script to learn on.
I have manged to get it to work on my html page with the script imbedded in the code. My next try was to put the script into an external file and get it o work that way. Problem:- the ultimate fader is in effect two scripts - the first is the bit that goes in the <head> and the secon is the bit that goes in the <body> I can run the entire script from a separate .js file but then it is all in the <head> section. If I just run the first part of the script from a separate .js file into the <head> section and leave the second part imbedded in the html file I get errors when i try to run it like fadeshow not declared etc.
How do I run a two part script from a separate .js file? I tried leaving part of the html that goes between the 2 parts of the script in the .js file but that was a disaster!!
Any help will be appreciated by a newbie!!
Peter"

Kiterson pointed me to your comments - hence this reply,
Many thanks for any help that either of you can give a poor newbie!!
Peter

peebs24
08-27-2007, 06:43 PM
[QUOTE=jscheuer1;94896]Make sure to retain all the 'decorations', as these include begin and end javascript comment delimiters without which the script won't function.

John,
How do you define "decorations" ?
Peter

jscheuer1
08-27-2007, 07:21 PM
Make sure to retain all the 'decorations', as these include begin and end javascript comment delimiters without which the script won't function.

John,
How do you define "decorations" ?
Peter


<script src="some.js" 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.
***********************************************/
</script>

Each comment is different, in the above comment, the only essential decorations are:


<script src="some.js" 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.
***********************************************/
</script>

But you may as well keep them all. In any case, it is easier to just say, 'keep all', than to try to explain to novices all the possible ways a comment can appear, and how to avoid changing it in such a way that will mess up the script.