PDA

View Full Version : Snow



marain
07-31-2012, 02:00 PM
1) Script Title: Snow

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex3/snow.htm

3) Describe problem: I've adapted the script to http://www.marainlaw.com/page.php?here=quotations. It works fine. However, I am trying to understand it. It contains the following line: [ICODE]snowsrc=(snowsrc.indexOf("dynamicdrive.com")!=-1)? "snow.gif" : snowsrc
[ICODE] Might someone have the time to explain what this line does? And how it does it?

A.

jscheuer1
07-31-2012, 04:48 PM
It (if it's not efited or removed) prevents hotlinking to Dynamic Drive's snow.gif or other images.

It does this by checking to see if "dynamicdrive" is in the snowsrc variable as configured earlier in the script. If so, it changes the snowsrc variable to 'snow.gif', which would then look for that image in the same folder as the page. If "dynamicdrive" is not in the snowsrc variable, then it leaves it alone and looks for the snowsrc image as the designer has configured it earlier in the script.

It's really not needed any longer because since this script was written, Dynamic Drive has configured its servers to not allow hot linking of images. But, as long as you're not hotlinking to Dynamic Drive, it doesn't do anything anyway, so there's no need for it to be removed.

marain
07-31-2012, 05:48 PM
Thank you.

My reason for asking was this: Now on my to-do list is to modify snow to present a distinct image, depending on month of the year. The line in question referenced the image that came with the original script. Thus I needed to understand it in order to determine whether I needed to make changes to it when implementing my contemplated modifications.

("to-do" list means God knows when I'll get to it.)

Best,

A.

jscheuer1
07-31-2012, 07:45 PM
Well, put another way, it's just a shorthand way of doing:


if (snowsrc.indexOf("dynamicdrive.com") != -1){
snowsrc = "snow.gif";
} else {
snowsrc = snowsrc;
}

And if done that way, in this case the highlighted and red else part can be skipped.

As I said, you don't need to worry about it. If you want date dependent images you can do that up front where the snowsrc is first defined.

Like if you wanted a different image for each month (near the top where it first defines snowsrc, you could replace that with):


snowsrc = new Date().getMonth() + '.gif';

That way it would look for 0.gif in Jan, 1.gif in Feb, and so on.