Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2012
    Posts
    48
    Plugin Contributions
    0

    Default Loading hava script file for ez pages

    Hi Everyone

    I have some javascript files that only get loaded of 6 ez pages.

    I caurrently have them in the footer so the are loaded last however

    Is there a way that I can only load these java script when the pages that require are displayed

    I tried the following bit think i may be barking up the wrong tree

    if ($current_page_base == 'page' and $id == '5' or $_GET['id'] == '5' or $_GET['id'] == '15' or $_GET['id'] == 9or $_GET['id'] == '16') {
    $flag_disable_jscript = flase;
    <script type="text/javascript" src="includes/templates/theme407/js/mhgallery.js"></script>
    <script type="text/javascript" src="includes/templates/theme407/js/initgallerytvframing.js"></script>
    <script type="text/javascript" src="includes/templates/theme407/js/initgallerystandard.js"></script>
    }

    I am not sure if this will work or if I have the format correct for an ez ppage

    Many Thanks

  2. #2
    Join Date
    Jul 2005
    Location
    Upstate NY
    Posts
    22,010
    Plugin Contributions
    25

    Default Re: Loading hava script file for ez pages

    You can use the autoloader system to load the proper javascripts where you want them, without touching any existing files.

    First, don't save your js files like
    /includes/templates/theme407/js/mhgallery.js

    In the general case where you want them loaded every time, save them like
    /includes/templates/theme407/jscript/jscript_mhgallery.js

    For your particular case where you only want them loaded on certain ez-pages, you need a helper file to do the testing. Then (since you *don't* want them autoloaded) you might name the js files in a way that will be bypassed by the auto system, say keeping your original names.
    includes/templates/theme407/jscript/mhgallery.js
    Make a new helper file in this folder:
    /includes/modules/pages/page/jscript_mhgallery.php
    with content like
    PHP Code:
    <?php
    //load these js files for this set of ez-pages

    if ($_GET['id'] == '5' or $_GET['id'] == '15' or $_GET['id'] == or $_GET['id'] == '16') {
    echo 
    '<script type="text/javascript" src="includes/templates/theme407/jscript/mhgallery.js"></script>
    <script type="text/javascript" src="includes/templates/theme407/jscript/initgallerytvframing.js"></script>
    <script type="text/javascript" src="includes/templates/theme407/jscript/initgallerystandard.js"></script>'
    ;
    }
    //EOF
    I haven't done exactly this before, so if it doesn't work the first time, let me know and we'll tweak it.

    Note: you had a typo in your original code that would mess up - no space after 9 here:
    $_GET['id'] == 9or $_GET['id'] ==
    Last edited by gjh42; 17 May 2013 at 01:56 AM.

  3. #3
    Join Date
    Jul 2005
    Location
    Upstate NY
    Posts
    22,010
    Plugin Contributions
    25

    Default Re: Loading hava script file for ez pages

    You need to pay close attention to the way you write logic tests. Grouping alternate clauses is essential.

    if ($current_page_base == 'page' and $id == '5' or $_GET['id'] == '5' or $_GET['id'] == '15' or or $_GET['id'] == '16')

    Any one of these being true would let the enclosed code execute, while you intended for $current_page_base == 'page' to always be required, along with one of the ids being true. This is done with correct parentheses:

    if ($current_page_base == 'page' and ($id == '5' or $_GET['id'] == '5' or $_GET['id'] == '15' or $_GET['id'] == 9or $_GET['id'] == '16')) {


    $flag_disable_jscript = flase;
    has no function, even without the typo. A flag by itself does nothing; it must be checked somewhere and appropriate action taken for it to be useful.

 

 

Similar Threads

  1. Replies: 9
    Last Post: 19 Apr 2012, 05:56 PM
  2. no new file button for ez pages
    By charliepingpong in forum Templates, Stylesheets, Page Layout
    Replies: 1
    Last Post: 29 Oct 2011, 06:49 AM
  3. Java script restrict loading in specific page only
    By time111 in forum Templates, Stylesheets, Page Layout
    Replies: 6
    Last Post: 28 Jun 2010, 08:53 AM
  4. java script not loading
    By shocker in forum Templates, Stylesheets, Page Layout
    Replies: 9
    Last Post: 1 Aug 2009, 09:41 AM
  5. Change File Permissions by script
    By caanan in forum Installing on a Windows Server
    Replies: 1
    Last Post: 17 Apr 2008, 10:52 PM

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