Allows your application to selectively load classes and lets you control when you want to instantiate the loaded class.
This is useful if you are building a large website and are packaging all your classes into one JavaScript file. Sometimes you want some scripts to be deferred and requested only when they are needed. This is when ScriptLoader will be useful to you.
NEW (2015/SEP/22) - 1.4 Mootools 1.5.2 Support.
To load the external class and instantiate it (default behavior):
new ScriptLoader('MooClassName', [arg_0, arg_1, ...]);
To load the external class and instantiate it later:
var loader = new ScriptLoader('MooClassName', [arg_0, arg_1, ...], { autoStart: false }); loader.addEvent('load', function() { // Code // ... this.process(myLoader); }.bind(loader));
To get the reference of an instance:
var loader = new ScriptLoader('MooClassName', [arg_0, arg_1, ...]); loader.addEvent('processEnd', function() { this.getInstance().doSomething(); // doSomething is an instance method. }.bind(loader));
An example that uses some options:
new ScriptLoader('MooClassName', [arg_0, arg_1, ...], { path: '/javascript/{Klass}.js' });
NEW - To load multiple classes at once
var loader = new ScriptLoader.Multiple( [ 'GoogleMaps.Control', 'GoogleMaps.Control.Type', 'GoogleMaps.Control.Zoom', 'GoogleMaps.Marker' ], { path: '/javascript/{Klass}.js' }); loader.addEvent('load', this.process_after_loading.bind(this));
new ScriptLoader(mooClassName, arguments, [options])
A note on comments here: These comments are moderated. No comments will show up until they are approved. Comments that are not productive (i.e. inflammatory, rude, etc) will not be approved.
Found a bug in this plugin? Please report it this repository's Github Issues.
blog comments powered by Disqus