Results 1 to 10 of 11

Hybrid View

  1. #1
    Join Date
    Feb 2007
    Location
    South Florida, USA
    Posts
    1,372
    Plugin Contributions
    4

    Default Loading a javascript site-wide

    I want to write unobtrusive javascript for Zen Cart.
    In other words, javascript that is not hacked into common templates like tpl_main_page.php or html_header.php
    I already know how to add a javascript to header unobtrusively.
    Now comes the body part, usually hacked into tpl_main_page.php.
    There is not a module for this page in includes/modules/pages/, where I can insert the script.
    --------------------------------
    From the wiki:
    Zen Cart's™ modular system can be used to insert <BODY> tag "onload" event handling on a site-wide or per-page basis very easily. Within your /includes/templates/YOURTEMPLATE folder, you can create a /jscript/on_load folder for this purpose.
    Any on_load_*.js file in this directory can be used to modify the body tag with a javascript on_load() function.
    --------------------------------
    Some questions about this:
    1) Does this .js file skip the <script></script> tags like the jscript_*.js files in the jscript folder.
    2) Do I need to write a function? That wouldn't be a problem.
    My question arises because I need to input the following:
    <a href="http://www.instantssl.com" id="comodoTL">SSL</a>
    <script language="JavaScript" type="text/javascript">
    COT("http://www.ladywig.com/includes/templates/mein/images/cornertrust.gif", "SC2", "none");
    </script>
    should I skip the <script> tags and enter the anchor as shown?
    I am updating a Zen Cart contribution to use unobtrusive javascript, so please help.
    Thanks.

  2. #2
    Join Date
    Apr 2004
    Location
    UK
    Posts
    5,821
    Plugin Contributions
    2

    Default Re: Loading a javascript site-wide


  3. #3
    Join Date
    Feb 2007
    Location
    South Florida, USA
    Posts
    1,372
    Plugin Contributions
    4

    Default Re: Loading a javascript site-wide

    Quote Originally Posted by misty View Post
    Thanks for answer but I was aware of that thread and in fact implemented that solution in my website.
    I am looking for a better solution, according to Zen Cart guidelines for javascript.
    The mentioned files should not be hacked into, there is an unobtrusive way to do this, set forth in the docs and in the Wiki.
    I managed to do the header part, but the body part is proving elusive because it involves an on_load() function.
    I need help with that.

  4. #4
    Join Date
    Oct 2006
    Posts
    5,477
    Plugin Contributions
    11

    Default Re: Loading a javascript site-wide

    Depends on the script you are using, for example if you are using a js framework such as jquery or mootools you dont need to insert the code to onload at all. For jquery, you can use $(document).ready(){//code here}
    I no longer provide installation support on forum for all my modules. However, if there are real bugs with the modules please feel free to contact me

  5. #5
    Join Date
    Feb 2007
    Location
    South Florida, USA
    Posts
    1,372
    Plugin Contributions
    4

    Default Re: Loading a javascript site-wide

    Quote Originally Posted by yellow1912 View Post
    Depends on the script you are using, for example if you are using a js framework such as jquery or mootools you dont need to insert the code to onload at all. For jquery, you can use $(document).ready(){//code here}
    Hey yellow,
    Obviously, you are super multi-tasking.
    Actually, this is simpler than that.
    I want to update the mod. for installing a Comodo Corner of Trust.
    So far, this has been done by hacking into the files.
    You can see the solutions that have been implemented by clicking on the link that misty provided.
    That solution is incorrect and doesn't follow the guidelines for javascript in Zen Cart.
    You should be able to load these scripts dynamically and unobtrusively, i.e. without modifying core Zen cart files at all.
    I have achieved this for the header part, by loading the following in includes/templates/CUSTOM/jscript/jscript_comodocorner.js
    //<![CDATA[
    var cot_loc0=(window.ocation.protocol == "https:")? https://secure.comodo.net/trustlogo/javascript/cot.js" :
    "http://www.trustlogo.com/trustlogo/javascript/cot.js";
    document.writeln('<scr' + 'ipt language="JavaScript" src="'+cot_loc0+'" type="text\/javascript">' + '<\/scr' + 'ipt>');
    //]]>
    that's how I got rid of the hack to html_header.php.
    Please note that I used the Zen Cart convention: there are no <script> tags, Zen Cart will put them in for you.
    Also, the file has to be named in a certain way: jscript_XXX.js
    Now, I am looking for help on the body part.
    I know that within same jscript folder I have to create another on_load folder and put in there a file named on_load_comodocorner.js
    This file has to have an on_load function (which can be called anything you like, of course).
    This is what this function needs to load:
    <a href="http://www.instantssl.com" id="comodoTL">SSL</a>
    <script language="JavaScript" type="text/javascript">
    COT("images/cornertrust.gif", "SC2", "none");
    </script>
    So here are my questions:
    1) Should I leave off the <script> tags?
    2) How do I load the anchor tag?
    A suggestion on how to write the function would be much appreciated.
    Thanks for the great support.

  6. #6
    Join Date
    Feb 2007
    Location
    South Florida, USA
    Posts
    1,372
    Plugin Contributions
    4

    Default Re: Loading a javascript site-wide

    var cot_loc0=(window.location.protocol...
    Typo in previous post, sorry.

 

 

Similar Threads

  1. Javascript not loading on Checkout pages
    By tcarden in forum General Questions
    Replies: 3
    Last Post: 25 Mar 2014, 06:43 PM
  2. Implement site wide javascript
    By usr50 in forum General Questions
    Replies: 7
    Last Post: 26 Feb 2011, 03:50 AM
  3. Half Frozen loading stuck site with text only loading
    By Zellcorp in forum Installing on a Windows Server
    Replies: 5
    Last Post: 1 Nov 2009, 09:16 AM
  4. Loading javascript files - prototip
    By guls_guys in forum General Questions
    Replies: 1
    Last Post: 19 Jun 2008, 12:40 PM
  5. Site Wide Javascript
    By traders in forum Templates, Stylesheets, Page Layout
    Replies: 14
    Last Post: 18 Nov 2007, 03:03 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR