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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

How in the world do I implement this?


Go to End


5 Posts   1292 Views

Avatar
TerryMiddleton

Community Member, 108 Posts

2 May 2009 at 10:32am

Okay, I've been up awhile and my brian is a little slow, however I must be missing something on the scale of Cloverfield.

I would like to implement this: http://www.lokeshdhakar.com/projects/lightbox2/

Where do you put the javascript to get executed? Where does the Requirements::javascript get put?

It seems so very simple to implement but it has taken me the better part of today to get even broken.

Any hep would be so appreciated.

Terry

Avatar
Willr

Forum Moderator, 5523 Posts

2 May 2009 at 11:48am

Hey Terry,

On the page type you would like to add the JS (or if its on every page) just put Requirements::javascript( - link to file - ); for each JS file you need to include in the function init() in the Controller of the page. If you need to load a CSS file you can use Requirements::css()

Confused? Maybe an example will help. This is what we use in the forum to load custom JS and CSS

...
class ForumHolder_Controller extends Page_Controller {

	function init() {
		Requirements::themedCSS('Forum'); // loads themes/your_theme/css/Forum.css
		Requirements::javascript("jsparty/jquery/jquery.js"); 
		Requirements::javascript("forum/javascript/jquery.MultiFile.js");
		Requirements::javascript("forum/javascript/forum.js");
		parent::init(); // you must have this line
	}
...

Avatar
TerryMiddleton

Community Member, 108 Posts

2 May 2009 at 12:43pm

willr,

Thanks a million for this.

I know it's simple, but I must be missing something.

I have in my Page.php the following:

class Page_Controller extends ContentController {

public function init() {

//Sifr::add_font('trade', 'themes/rittheme/fonts/tradegothic.swf');
Sifr::replaceElement(".Title","SolexMinLin",'sColor:"#007CA8",sLinkColor:"#fe6e0e",sHoverColor:"#fe6e0e"');
Sifr::loadSifr();
// Note: you should use SS template require tags inside your templates
// instead of putting Requirements calls here. However these are
// included so that our older themes still work
Requirements::themedCSS("layout");
Requirements::themedCSS("typography");
Requirements::themedCSS("form");
Requirements::themedCSS("lightbox");

Requirements::javascript( "mysite/javascript/jquery.js" );
Requirements::javascript( "mysite/javascript/jquery.lightbox.js" );

parent::init();
}

It doesn't fire. I did the ?flush=1 I basically did exactly what the lightbox2 code has and it looks correct when I view source. Weird.

here's my page... Is there something I'm missing?

http://63.247.208.15/dose-calibration/

Terry

PS. I really appreciate you helping out on this.

Avatar
Willr

Forum Moderator, 5523 Posts

2 May 2009 at 8:18pm

Have you got the firebug plugin for firefox? its essential for doing any sort of webdevelopment work. One thing it shows is the JS error console, and the errors on a page. If your sites case I can see it has 1 error - $(document).ready is not a function - so it seems like maybe how this is implemented is incorrect or maybe the prototype code SS has is conflicting. See http://doc.silverstripe.com/doku.php?id=jquery for an example jquery file and try that

Avatar
TerryMiddleton

Community Member, 108 Posts

3 May 2009 at 3:23pm

Yes....Thank you willr.

I got it to work.

I so appreciate you helping everyone out. This is going to make the client exceedingly happy. Plus, it opens up SS to all kinds of jquery utilities.

Thanks again,

Terry