Jump to:

22972 Posts in 11596 Topics by 2824 members

General Questions

SilverStripe Forums » General Questions » Requirements - changing JS loading order.

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1515 Views
  • Hamish
    Avatar
    Community Member
    712 Posts

    Requirements - changing JS loading order. Link to this post

    I've come across an issue where the order in which prototype and jQuery are loaded cause issues. In the CMS, prototype is called first, then jQuery kindly lets it do its thing by running with noConflict.

    However, I'm trying to use a TabSets outside of the CMS and for some reason unknown, jQuery is appearing before prototype. This causes prototype to semi-fail. Validators don't work properly, I get errors like "$ is not a function" etc. I guess it isn't surprising considering that TabSet loads the entire jQuery library just so it can use livequery, but uses prototype for all it's internal logic in (tabstrip.js).

    I mean, surely whoever wrote this in TabSet.php felt a little bit dirty

       public function FieldHolder() {
          Requirements::javascript(THIRDPARTY_DIR . "/loader.js");
          Requirements::javascript(THIRDPARTY_DIR . "/prototype.js");
          Requirements::javascript(THIRDPARTY_DIR . "/behaviour.js");
          Requirements::javascript(THIRDPARTY_DIR . "/prototype_improvements.js");
          Requirements::javascript(THIRDPARTY_DIR . "/jquery/jquery.js");
          Requirements::javascript(THIRDPARTY_DIR . "/jquery/jquery_improvements.js");
          Requirements::javascript(THIRDPARTY_DIR . '/jquery/plugins/livequery/jquery.livequery.js');
          Requirements::javascript(THIRDPARTY_DIR . "/tabstrip/tabstrip.js");
          Requirements::css(THIRDPARTY_DIR . "/tabstrip/tabstrip.css");
          
          return $this->renderWith("TabSetFieldHolder");
       }

    Anyway, is there any way for force javascript requirements to appear in a particular order. Since prototype refuses to play nicely, it is up to jQuery to save the day by loading second. Any tips appreciated.

    Regards,
    Hamish

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: Requirements - changing JS loading order. Link to this post

    By the way, I found out it was the loading order by copying the generated source into a static page, then swapped the scripts around. Simply moving prototype before jquery fixes the problem.

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: Requirements - changing JS loading order. Link to this post

    Ok, found where jQuery was being loaded and preceded it with a requrements all for prototype. So now I have to load prototype every time I want to juse jQuery, on the off-chance that something else will try to load prototype later. Makes jQuery seem a little pointless :/

  • david_nash
    Avatar
    Community Member
    55 Posts

    Re: Requirements - changing JS loading order. Link to this post

    Could you post your code for this? I'm having real problems getting jquery and prototype to play nicely.

    1515 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.