Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Disableing javaScript Libraries?

Our old forums are still available as a read-only archive.

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

Page: 1
Go to End
Author Topic: 1834 Views
  • MKayHavoc
    Avatar
    Community Member
    33 Posts

    Disableing javaScript Libraries? Link to this post

    How can I disable the the following javaScript libraries:

    <script type="text/javascript" src="jsparty/loader.js"></script>
    <script type="text/javascript" src="jsparty/prototype.js"></script>
    <script type="text/javascript" src="jsparty/behaviour.js"></script>
    <script type="text/javascript" src="jsparty/prototype_improvements.js"></script>
    <script type="text/javascript" src="jsparty/tabstrip/tabstrip.js"></script>
    <script type="text/javascript" src="jsparty/scriptaculous/effects.js"></script>

    In my site, but obviously leave them for the CMS backend?

    Cheers

  • Willr
    Avatar
    Forum Moderator
    5497 Posts

    Re: Disableing javaScript Libraries? Link to this post

    You need to use a method called Requirements::block(the file name);. You would put this in your in the init() function Page_Controller class in Page.php.

    So you would need

    Requirements::block("jsparty/loader.js");
    ..

    for each JS file you want to block on the front end.

  • kudesign
    Avatar
    Community Member
    64 Posts

    Re: Disableing javaScript Libraries? Link to this post

    Hi, so if I want to add a js, or a new css to load, do I just add in a requirement?

    I want to load

    slider.css
    and
    slider.js

    e.g.

    Requirements::themedCSS("slider");
    Requirements: "jsparty/slider.js");

  • kudesign
    Avatar
    Community Member
    64 Posts

    Re: Disableing javaScript Libraries? Link to this post

    This is what my page.php looks like at the moment

    <?php

    class Page extends SiteTree {
       static $db = array(
       );
       static $has_one = array(
    );
    }

    class Page_Controller extends ContentController {
       function init() {
          parent::init();
          
          Requirements::themedCSS("layout");
          Requirements::themedCSS("typography");
          Requirements::themedCSS("form");
       }
    }

    ?>

    So can I add to the list

    Requirements::themedCSS("slider");
    Requirements: "jsparty/slider.js");

    thanks!

  • Willr
    Avatar
    Forum Moderator
    5497 Posts

    Re: Disableing javaScript Libraries? Link to this post

    The best way to to keep your own JS in themes/yourthemename/javascript. And you would include it like

    Requirements::javascript("themes/yourthemename/javascript/slider.js");

    in the function init() just like the rest of the Requirements

  • kudesign
    Avatar
    Community Member
    64 Posts

    Re: Disableing javaScript Libraries? Link to this post

    Thanks for the quick reply! this helps. I tried coding it into the template, and it also works, but I think coding it in page.php sounds like a better way to do it.

    Another quick question, any idea why my log-in page login name/openID tabs doesn't hide in Firefox anymore?

    http://www.kudesign.co.nz/studio/Security/login

    I looked at the tabstrip.js, and tabstrip.css, they seem to be working fine... just won't hide in Firefox. Any tip will be much appreciated!!

    1834 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.