Global JavaScript Object for CMS Made Simple

General project discussion. NOT for help questions.
Post Reply
bbonora
Forum Members
Forum Members
Posts: 48
Joined: Mon Nov 06, 2006 6:10 am

Global JavaScript Object for CMS Made Simple

Post by bbonora »

I'm interested in creating a module that will allow other modules to send JavaScript to page templates. The module would be a tag at the bottom of the page and would combine, minify and cache all the JS into a single file at the bottom of the page and eliminate all the inline JS that occurs now.

Both WordPress and Drupal already have system to handle Plugin/Module JS and I was wondering if anybody had any feedback on a good way to implement this into CMS Made Simple. I have couple of ideas but am interested in what the group thinks.
psy
Power Poster
Power Poster
Posts: 463
Joined: Sat Jan 22, 2005 11:19 am

Re: Global JavaScript Object for CMS Made Simple

Post by psy »

You can achieve what you want with smarty template code.

Eg, in a module template (assumes CGExtensions is installed for {jsmin} but you can assign any tag):

Code: Select all

{jsmin assign='js'}
{literal}
<__script__>
$(document).ready(function()({
...
});
</__script>
{/literal}
{append var=pagejs value=$js}
Then in your page template immediately above the <__body> tag:

Code: Select all

<__script__ src="source/to/jquery"></__script>
{if is_array($pagejs)}
{foreach from=$pagejs item=js}
{$js}
{/foreach}
{/if}
Vars from the module template are then included in the javascript before it gets sent to the bottom of the page.

See http://forum.cmsmadesimple.org/viewtopi ... =4&t=70092 for more info.

Rolf also has a great solution to combine scripts into one page. See https://www.cmscanbesimple.org/blog/eas ... s-and-code

hth
psy
Post Reply

Return to “General Discussion”