Page 1 of 2 12 LastLast
Results 1 to 10 of 15
  1. #1
    Join Date
    May 2006
    Location
    Gardiner, Maine
    Posts
    2,289
    Plugin Contributions
    22

    Default Including jquery with ready doc statements

    I've found myself with a number of jquery based contributions at this point and am now working on streamlining adding in jquery mods that use the ready document statements in the header or footer.

    Doing one mod only requires the addition of a small bit of script into the html_header.php file and is simple for install purposes.

    However, if someone wants to have several jquery mods installed they have to combine 2 statements together and it's just not a simple thing.

    So I was wanting to set up something to control that without the html_header.php /footer being edited. I'm heading towards figuring out how to best do it thru admin configuration setting.

    But I wanted to see if anyone would talk about how jquery might be added in the next version of zen cart. Since jquery is supposed to be added in, I don't really want to do something that doesn't work well with the next version or has to be totally redone.

    If that gets no answer, then I'm open to suggestions.

    What I'm looking at doing would be to:
    1. have the ready doc statements added to a config group for jquery
    2. each would then have an activate / no activate setting
    3. choice of header or footer placement
    4. ability to edit settings inside the each statement
    5. ability to limit that setting to only certain pages

    Am I leaving out anything? Does this sound like an easy / straight forward way of doing it? I dislike have to fancy up coding or add new files just to accomplish a goal and want to keep it as simple as possible so that installation becomes a slam dunk.
    The full-time Zen Cart Guru. WizTech4ZC.com

  2. #2
    Join Date
    May 2006
    Location
    Gardiner, Maine
    Posts
    2,289
    Plugin Contributions
    22

    Default Re: Including jquery with ready doc statements

    Muddling through this myself for the first mod which is pretty simple.

    So far I have created the configuration group and configuration setting which are only 2, 1 to activate the mod and 1 for the page is it needed on which is the product_info page.

    I created a define statement that contains the actual javascript for the document ready statement.

    In the the html_header then, I have placed the enclosing script and now have to create the php that goes inside.
    Code:
    <script type="text/javascript">
    $(document).ready(function() {
    <?php 
    code to be entered here.
    ?>
    });
    </script>
    So now, I need to call up all the jquery mods that are in the database.

    The php comes next:

    The gist of it is if it has the configuration_group_title of 'jQuery Document Ready', then echo each active one here.

    A loop and array are required obviously. I don't remember seeing a loop to pull from configuration settings like that. Trying to follow zen cart code here and or going for efficiency.

    What the best way to do this?
    The full-time Zen Cart Guru. WizTech4ZC.com

  3. #3
    Join Date
    May 2006
    Location
    Gardiner, Maine
    Posts
    2,289
    Plugin Contributions
    22

    Default Re: Including jquery with ready doc statements

    and one more thing - since this will require a select statement, should that be included there in the html header or separated out into another file or place?
    The full-time Zen Cart Guru. WizTech4ZC.com

  4. #4
    Join Date
    Jan 2004
    Posts
    66,364
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Including jquery with ready doc statements

    You don't want to be putting a bunch of javascript statements into configuration settings. That'll start flagging things under PCI/PA-DSS inspections.

    Better to follow something like the existing on_load stuff already in core ... esp since it's essentially the same task, but done differently.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  5. #5
    Join Date
    May 2006
    Location
    Gardiner, Maine
    Posts
    2,289
    Plugin Contributions
    22

    Default Re: Including jquery with ready doc statements

    Great, thanks for the advice and direction. I had veered away from that but still didn't hit on that.
    The full-time Zen Cart Guru. WizTech4ZC.com

  6. #6
    Join Date
    May 2006
    Location
    Gardiner, Maine
    Posts
    2,289
    Plugin Contributions
    22

    Default Re: Including jquery with ready doc statements

    One of the things I was trying to do is be able to activate/deactivate this by not having the ready doc statement included. So I can definitely have the statement added in by creating a jscript file for the pages/product_info folder, but that's too automatic. Is there a way to flag it off and on 'cause I don't think there is.

    Normally the js and the document ready function are separate with jQuery - of course, I'm no expert at jQuery. I just know this is the way the jQuery is done normally.
    The full-time Zen Cart Guru. WizTech4ZC.com

  7. #7
    Join Date
    Jan 2007
    Posts
    1,484
    Plugin Contributions
    10

    Default Re: Including jquery with ready doc statements

    Could this benefit from a template based autoloader that has a define for which pages a certain amount of js and css scripts load? I am not sure I understand the issue, so I might be off-base with my suggestion. But we use multiple jquery scripts that are called depending on which page is called and none of them conflict with each other.

    Zen Cart and it's community are the best!!

  8. #8
    Join Date
    May 2006
    Location
    Gardiner, Maine
    Posts
    2,289
    Plugin Contributions
    22

    Default Re: Including jquery with ready doc statements

    Quote Originally Posted by lankeeyankee View Post
    Could this benefit from a template based autoloader that has a define for which pages a certain amount of js and css scripts load? I am not sure I understand the issue, so I might be off-base with my suggestion. But we use multiple jquery scripts that are called depending on which page is called and none of them conflict with each other.
    This isn't about conflicts - but about using jquery files with document ready statements. This code goes in the header (sometimes in the footer):

    Code:
    <script type="text/javascript">
    $(document).ready(function() {
    		var origsrc = $("#productMainImage a img").attr("src");
    	........
    
    .......................
    	  }
    	);
    });
    </script>
    Not uncommon to run 2 jquery scripts at the same time, so you add in the other inside the $(document).ready(function() { statement.

    What I"m trying to do is to automate that so that no one has to figure out how to add that in or change the html_header. Kinda like adding in another css file but would be done through activation in admin.

    This gives the user more control as well since those ready doc statements can do things like change the speed or color of something in the jquery.

    This is the norm for jquery. Of course all of that can be done within the jquery file itself but if I can make this work then almost any jquery mod can be easily plugged into Zen Cart. That opens up a lot of possibilities for the community.

    Just trying to make it more user friendly since I seem to be creating more and more of these kind of plugins. Selfishly, this would also reduce the amount of support necessary for such plugins!

    Also, sometimes a jquery will be needed on every page - don't forget that. It's not about which page to include it on. But how to add in another one later.
    The full-time Zen Cart Guru. WizTech4ZC.com

  9. #9
    Join Date
    Jan 2004
    Posts
    66,364
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Including jquery with ready doc statements

    I repeat ... that's the same concept that the built-in on_load support uses. So, I recommend that you use that as inspiration for your jquery need.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  10. #10
    Join Date
    May 2006
    Location
    Gardiner, Maine
    Posts
    2,289
    Plugin Contributions
    22

    Default Re: Including jquery with ready doc statements

    Can you give a hint where to start? "built-in on_load support" Obviously, I don't know what you are talking about. I know files, not general terms, and I used zen cart to learn php! Not a strong coder background.
    The full-time Zen Cart Guru. WizTech4ZC.com

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. SSL Issue with jQuery
    By contrive.it in forum General Questions
    Replies: 3
    Last Post: 23 Aug 2011, 07:13 AM
  2. A better way of dealing with large define() statements?
    By gjh42 in forum Templates, Stylesheets, Page Layout
    Replies: 7
    Last Post: 19 May 2011, 01:37 PM
  3. Help with Jquery
    By tthenne in forum Templates, Stylesheets, Page Layout
    Replies: 9
    Last Post: 23 Apr 2011, 01:58 AM
  4. separating pages with body ID and if/then statements
    By doodlebee in forum Templates, Stylesheets, Page Layout
    Replies: 13
    Last Post: 29 Jan 2007, 02:55 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