Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General 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

Basic questions


Reply


3 Posts   1164 Views

Avatar
frankmullenger

Forum Moderator, 53 Posts

24 May 2010 at 1:45pm

Edited: 24/05/2010 3:03pm

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

Avatar
mark_s

Community Member, 78 Posts

25 May 2010 at 9:20pm

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

Avatar
Tonyair

Community Member, 81 Posts

2 June 2010 at 7:20am

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