Dashboard > People > Shaun McCormick > 2008 > February > 18 > External JS for Manager Pages

View Attachments (0) Info

External JS for Manager Pages

So one of the moves MODx Revolution has done recently is move its JS scripts to external files. Some have asked about the motivation for such a move, and the explanation is pretty simple...

...caching.

 Pre-this-move, the JS to initialize each manager page was inline in the Smarty template. This was great for the time, but as the JS started to get more and more complex with new Ext2 functionality, the JS got longer and longer, and started to clutter. Also, many IDEs such as Eclipse and Aptana weren't able to take advantage of code hinting, coloring or debugging when the JS was inline.

So, we moved to putting as much of the JS in external files, in the sections/ directory of the js template. This allowed the browser to cache the JS file (best) and gave each page it's own JS-driven Ext.Component. An example was such for creating a context:

Ext.namespace('MODx');
Ext.onReady(function() {
    new MODx.Context();
});

MODx.Context = function(config) {
	config = config || {};
	Ext.applyIf(config,{
		form: 'mutate_context'
		,fields: {
			key: _textfields['key']
            ,description: _textareas['description']
		}
		,actions: {
            'new': 'context/create'
            ,edit: 'context/update'
            ,cancel: 'context'
        }
        ,buttons: [{
            process: 'create'
            ,text: _('save')
            ,method: 'remote'
            ,reload: true
        },{
            process: 'cancel'
            ,text: _('cancel')
            ,params: { a: 'context' }
        }]
        ,loadStay: true
	});
	MODx.Context.superclass.constructor.call(this,config);
};
Ext.extend(MODx.Context,MODx.Component);

As you can see, this allowed a lot of flexibility on manager page design, as well as keeping yet another block of code separate from the content. Another point for proper MVC programming.

  February 2008 >>
Sun Mon Tue Wed Thu Fri Sat
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29  

PHP Coding in MODx Revolution, Pt. I >>


Browse Space
- Pages
- Labels
- Attachments
- Bookmarks
- News
- Activity
- Advanced

Explore Confluence
- Popular Labels
- Notation Guide

Your Account
Log In

Other Features

View a printable version of the current page.

Add Content


Powered by Atlassian Confluence 2.7.1, the Enterprise Wiki.
Bug/feature request - Contact administrators