• twitter image
  • facebook image
  • youtube image
  • linkedin image
Language: CMS Made Simple Czech CMS Made Simple France CMS Made Simple Spain CMS Made Simple Hungary CMS Made Simple Russia CMS Made Simple Netherlands

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: How do I add Javascripts?
PostPosted: Thu Feb 23, 2012 5:46 pm 
Offline
Power Poster
Power Poster
User avatar

Joined: Sat Jul 07, 2007 9:22 am
Posts: 606
Location: Almelo, The Netherlands
I'm building my first module.

This module use Jquery and Javascript.

When the module is called, Jquery an Javascript must be loaded in the HEAD.
Code:
<link rel="stylesheet" href="path/Style.css" />
<script src="path/jquery-1.4.3.min.js"></script>

How can I realise that when the module is loaded, the code above is placed in the HEAD?

_________________
Lees het nu!!! Het 1e lustrum: de 5e CMSms workshop


Top
 Profile  
 
 Post subject: Re: How do I add Javascripts?
PostPosted: Thu Feb 23, 2012 7:38 pm 
Offline
Power Poster
Power Poster
User avatar

Joined: Tue Dec 23, 2008 8:39 pm
Posts: 1316
Take a look at the Gallery module.. It registers a trigger that gets called when the final HTML output is generated. It then inserts all the JavaScript and CSS stuff right before the </head>


Top
 Profile  
 
 Post subject: Re: How do I add Javascripts?
PostPosted: Fri Feb 24, 2012 4:11 am 
Offline
Dev Team Member
Dev Team Member
User avatar

Joined: Tue Oct 19, 2004 6:44 pm
Posts: 6576
Location: Fernie British Columbia, Canada
Quote:
Take a look at the Gallery module.. It registers a trigger that gets called when the final HTML output is generated. It then inserts all the JavaScript and CSS stuff right before the </head>


And this is exactly the WRONG way to do this. Because it does not leave control up to the developer to manage this stuff. What were to happen (for example) if you wanted two galleries with two different templates (and therefore two different sets of javascript requirements).. or two different modules that needed javascript on the same page.

The proper way to handle this is to give the developer control over the issue. Typically this is done by another action in the module... like {mymodule action=incjs} or something that can be placed in the page template header.

IIRC the Album module does this in a smart way... when the album module is called in the body, the template that is activated is 'saved', and when the {Album action='incjs'} (or whatever it is) is called, it detects that 'saved' template and knows what javascripts/stylesheets to include etc. But it also does not get in the way of the developer removing that capability, or doing something else entirely.

_________________
Follow me on twitter
--
if you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
----------------
Don't make me angry..... you won't like me when I'm angry....


Top
 Profile  
 
 Post subject: Re: How do I add Javascripts?
PostPosted: Fri Feb 24, 2012 5:39 am 
Offline
Power Poster
Power Poster
User avatar

Joined: Tue Dec 23, 2008 8:39 pm
Posts: 1316
I like the automatic inclusion, for ease of use, but think it would be good to have the option to manually place it as well, in case you need to put it in a particular spot.


Top
 Profile  
 
 Post subject: Re: How do I add Javascripts?
PostPosted: Fri Feb 24, 2012 11:05 am 
Offline
Power Poster
Power Poster
User avatar

Joined: Wed Sep 05, 2007 8:03 pm
Posts: 3642
Location: The Netherlands
calguy1000 wrote:
And this is exactly the WRONG way to do this.
:-X

calguy1000 wrote:
it does not leave control up to the developer to manage this stuff.
Not true: Gallery provides developers a way to control what the module puts in the head section.

_________________
Get nice guestbook messages from your site visitors with the brand new Gbook module.
Integrate Piwik Web Analytics in your site admin with the Piwik module.
Extend your global site settings with the Custom Global Settings module.
The Fourth Dutch CMS Made Simple Workshop on April 9 2011 was great fun! Read all about it here
Announcement: The Fifth Dutch CMS Made Simple Workshop coming up?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Arvixe - A CMSMS Partner