Forums / Templates, Stylesheets, Page Layout / Javascript on Main Page

Javascript on Main Page

Locked

Views: 3,598

Results 1 to 11 of 11
This thread is locked. New replies are disabled.
22 Oct 2009, 3:01 AM
#1
charinlasvegas avatar

charinlasvegas

Zen Follower

Join Date:
Jan 2009
Location:
Vegas Baby!
Posts:
311
Plugin Contributions:
0

Javascript on Main Page

This is kind of a dumb-dumb question :lookaroun

I want to use a dhtml slideshow from dynamic drive on my main page.

Step 1: Insert the below style sheet in the HEAD section of your page:

<style type="text/css">

/*set CSS for SPAN tag surrounding each image*/
.seqslidestyle{
margin-right: 15px;
}
</style>

On WHICH page am I inserting this code (includes/languages/english/index.php???) , and WHERE exactly does it go? Do I put it before the opening <?php on the page or somewhere else?

This is the script I'm looking at using:
http://www.dynamicdrive.com/dynamicindex14/multiframeslide.htm

Completed: BellaFavori.com
In Progress: WeddingDivasLV.com
Coming Soon: ???

22 Oct 2009, 4:11 AM
#2
charinlasvegas avatar

charinlasvegas

Zen Follower

Join Date:
Jan 2009
Location:
Vegas Baby!
Posts:
311
Plugin Contributions:
0

Re: Javascript on Main Page

Ok, I think I got but it's not working very well. Guess it just needs some tweaking.

Completed: BellaFavori.com
In Progress: WeddingDivasLV.com
Coming Soon: ???

22 Oct 2009, 4:26 AM
#3
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Javascript on Main Page

Try just adding the style rule to your stylesheet:```
/set CSS for SPAN tag surrounding each image/
.seqslidestyle{
margin-right: 15px;
}

22 Oct 2009, 6:08 AM
#4
charinlasvegas avatar

charinlasvegas

Zen Follower

Join Date:
Jan 2009
Location:
Vegas Baby!
Posts:
311
Plugin Contributions:
0

Re: Javascript on Main Page

Thanks, Glenn. I'm going to have to scratch this idea anyway, this slideshow doesn't work well & I can't find any other that shows multiple frames at the same time.

Completed: BellaFavori.com
In Progress: WeddingDivasLV.com
Coming Soon: ???

9 Dec 2009, 6:35 AM
#5
lotii10396 avatar

lotii10396

New Zenner

Join Date:
Sep 2007
Posts:
48
Plugin Contributions:
0

Re: Javascript on Main Page

I too am wanting a slide-show on the main page (only one frame though), and have got this running OK, except I can only load the additional jscript globally but I need it to only run on the main page. I can't get my head around the template system here, so any advise would be greatly appreciated. To get the additional javascript to load I have modded a template driven file:

includes/templates/MY_TEMPLATE/common/html_header.php

and hard-coded the links to the script files that are residing in:

/includes/templates/MY_TEMPLATE/jscript/

echo '<script type="text/javascript" src="' . $template->get_template_dir('.js',DIR_WS_TEMPLATE, $current_page_base,'jscript') . '/file1.js"></script>'."\n";
echo '<script type="text/javascript" src="' . $template->get_template_dir('.js',DIR_WS_TEMPLATE, $current_page_base,'jscript') . '/file2.js"></script>'."\n";
echo '<script type="text/javascript" src="' . $template->get_template_dir('.js',DIR_WS_TEMPLATE, $current_page_base,'jscript') . '/file3.js"></script>'."\n";

It looks to me like they are supposed to auto-load but nothing happens unless I hard code it. Existing code snip below:

/**

  • load all site-wide jscript_*.js files from includes/templates/YOURTEMPLATE/jscript, alphabetically
    */
    $directory_array = $template->get_template_part($template->get_template_dir('.js',DIR_WS_TEMPLATE, $current_page_base,'jscript'), '/^jscript_/', '.js');
    while(list ($key, $value) = each($directory_array)) {
    echo '<script type="text/javascript" src="' . $template->get_template_dir('.js',DIR_WS_TEMPLATE, $current_page_base,'jscript') . '/' . $value . '"></script>'."\n";
    }

/**

  • load all page-specific jscript_*.js files from includes/modules/pages/PAGENAME, alphabetically
    */
    $directory_array = $template->get_template_part($page_directory, '/^jscript_/', '.js');
    while(list ($key, $value) = each($directory_array)) {
    echo '<script type="text/javascript" src="' . $page_directory . '/' . $value . '"></script>' . "\n";
    }

I have tried getting the script to load by adding the script files into:

includes/modules/pages/index/

but it doesn't work.


So does anyone know where to put the script file so that ONLY a specific page within Zen Cart will load it? I have read several articles saying it can be done, but none of the instructions are right....

Adrian

9 Dec 2009, 7:05 AM
#6
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Javascript on Main Page

load all site-wide jscript_*.js files

You need to name the files according to the convention so they will be picked up.

jscript_file1.js
jscript_file2.js
jscript_file3.js

or something more descriptive.

9 Dec 2009, 9:56 AM
#7
lotii10396 avatar

lotii10396

New Zenner

Join Date:
Sep 2007
Posts:
48
Plugin Contributions:
0

Re: Javascript on Main Page

Aha - I wasn't looking closely enough and assumed the the code was looking for a *.js file in a jscript directory [ ../jscript/myfilename.js] as this is the structure elsewhere in the code.

Now that you have pointed this out I can see it is actually prefixing the variable value with [ jscript_ ]

Thanks for that, that sorts a major roadblock I had! Adrian

9 Dec 2009, 12:23 PM
#8
lotii10396 avatar

lotii10396

New Zenner

Join Date:
Sep 2007
Posts:
48
Plugin Contributions:
0

Re: Javascript on Main Page

LOL. FYI in the end I had to go back to hard-coded script file insertion. The reason being that the auto-loading of the jscript_*.js files seems to be based on the URL variable main_page=index (or other), so whilst it did work for the home page, as this variable is still used elsewhere in the site the scripts were being loaded on other pages as well, creating errors.

Tried writing some conditional statements in the js code but it isn't simple nor obvious code, and js is certainly not my strong point so I gave up this line of attack....:(

So I went back to hard-coding but added a php check for the cPath URL variable. As this URL variable seems (fingers crossed) to be used for deeper pages if it doesn't exist then I am assuming the user is at the home page and therefore the additional scripts are loaded and the slide-show runs.

Hard-coding here not too naughty as it is in a template file anyway.

Whole exercise not wasted time, as I need to load additional js files elsewhere in the site so now I know how to do this properly.

Cheers, Adrian

9 Dec 2009, 5:53 PM
#9
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Javascript on Main Page

The $cPath test will only work for category/product pages. Any other kind of page will not have a cPath.
The best test for homepage is a variable introduced in v1.3.7 called $this_is_home_page. It is always true on the homepage and false elsewhere.

10 Dec 2009, 10:46 AM
#10
lotii10396 avatar

lotii10396

New Zenner

Join Date:
Sep 2007
Posts:
48
Plugin Contributions:
0

Re: Javascript on Main Page

sweet....this makes things foolproof.

Because of the complex js I went and had a look-see at the sites that were first requesting this, and I see that they obviously gave up on this method and instead went to flash files!

In my case I want to be able to reference specific files (eg. image1. image2, etc) so all the shop owner needs to do is upload new files named the same and they have a new slideshow.

Cheers, Adrian

10 Dec 2009, 10:50 AM
#11
lotii10396 avatar

lotii10396

New Zenner

Join Date:
Sep 2007
Posts:
48
Plugin Contributions:
0

Re: Javascript on Main Page

gjh42:

The $cPath test will only work for category/product pages. Any other kind of page will not have a cPath.
The best test for homepage is a variable introduced in v1.3.7 called $this_is_home_page. It is always true on the homepage and false elsewhere.

BTW the php check was:

main_page = index AND cPAth = null

This seemed to work (hadn't dug too deep though) but obviously a dedicated home page variable makes life a lot simpler.

Adrian