Jump to:

23377 Posts in 18296 Topics by 2867 members

General Questions

SilverStripe Forums » General Questions » Basic questions

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: 1118 Views
  • frankmullenger
    Avatar
    Forum Moderator
    51 Posts

    Basic questions Link to this post

    I have a few more basic questions, working on my first Silverstripe site and its been quite a frustrating experience so far.

    I have had headaches with javascript, I am trying to implement a basic jquery lightbox script. I was constantly getting the error that lightBox() is not defined. It seems that when I remove $SilverStripeNavigator from the bottom of the page the lightbox works fine and I'm not sure why or how to get around this problem.

    I've tried pretty much every image gallery module there is and nothing has worked for me - is there an image gallery somewhere that will add a tab to the CMS, allow users to upload x many images so I can pull the images out in a for loop in a template page and include some javascript to display them in a nice way.

    Thanks

  • mark_s
    Avatar
    Community Member
    78 Posts

    Re: Basic questions Link to this post

    Hi.

    Your issue may be a conflict between prototype and jquery. SSNavigator uses prototype (as does much of the CMS). Both use the $ symbol as their main function (which is stupid, but that's another subject).

    What may be happening is that jquery and the lightbox load before prototype, and when prototype loads, it overwrites the definition of $, and jquery $ and the lightbox are gone.

    You can correct this in different ways:

    1. by forcing the order. You need to do something like this in your controller init, or somewhere that is always called for each page:

    Requirements::clear();
    Requirements::javascript("path_to_prototype.js");
    Requirements::javascript("path_to_jquery.js");
    Requirements::javascript("path_to_lightbox.js");
    The paths that these are loading from will be visible in firebug (easiest way to see it, but you can see them in the HTML as well, near the end). The above code, or some variation like that, can be used to force the order. It's not particularly elegant, but it's straightforward.

    2. Another way to correct it in your page's code is to use the symbol jquery instead of $. Even if prototype overwrites $, the jquery global is still present.

    3. Another way still is to wrap the jquery code in a closure and explicitly pass jquery global in as $.

    Longer term (past 2.4) we're moving away from prototype, so the conflict will be resolved, but that won't help you in the immediate.

    Mark

  • Tonyair
    Avatar
    Community Member
    81 Posts

    Re: Basic questions Link to this post

    Hello, I have few questions ..

    How to embed something like this:

    <!--[if IE]-->
    <script type="text/javascript" src="bla-bla.js"></script>
    <!--[endif]-->

    And can I put javascript including code into <head> tag?

    Also I tried to use Requirements::clear();, but any way jquery 1.4 included via $SilverStripeNavigator, but liquid-canvas requires jquery-1.3.2

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