AJBnet.js is a javascript framework inspired by the fantastic require.js library. It provides a set of tools to organize and optimize javascript applications.
Why?
I wanted a library that was similar to require.js, but that let me use prototyped objects without too much refactoring. I didn't want to let go of either my past workflow, or the benefits of dynamic intelligent module loading, so I made this.
The AJBnet.autoInit method is run on load, which checks the optional data-init attribute for a JSON object to use for init parameters. If one is not found, this is bypassed. The attribute should be applied to the originating script tag that loads the framework source.
The attribute data-init can be excluded if you want to manually init the framework, for example to delay any additional code from being run on load.
AJBnet.init({debug:false,app:"Gallery/Main"});
AJBnet.define(classpath, dependencies, closure)
The method define is used to describe a namespaced class, or a block of code belonging to a particular namespace. This includes dependencies (optional), and a closure which returns the constructor for that class.
/**
* This file, stored at path example/class.js under the src path,
* defines the namespace, dependencies, and constructor!
* The constructor is returned by the closure.
*/
AJBnet.define("Example/Class",["My/Dependency","Another/Class"],function(){
var Class = function(){
// constructor here;
return this;
}
Class.prototype.property = "a prototypically inherited property of this class";
Class.prototype.method = function( param ){
return "I was a prototypically inherited method of this class, and I was passed " + param;
}
return Class;
});
AJBnet.construct(classpath)
Instantiate a class which has been loaded as a dependency of the current scope or class:
var my_image = AJBnet.construct('Gallery/ImageProxy');
AJBnet.run(classpath)
The run method can be used to run code. It does not need to be loaded yet. For example, the demo button below uses the following, which triggers the codeblock to be loaded and executed:
This example demonstrates the AJBnet.run() method to execute the closure at Gallery/Main, the class file for which has not been loaded yet. Gallery/Main creates an image browser overlay that you can navigate using the left/right keys.
Gallery/Inline
This example utilizes the AJBnet.run() method to execute the closure at Gallery/Inline, the class file for which has not been loaded yet. Gallery/Inline creates an image browser that you can navigate using the buttons in the interface or by clicking on the gallery directly.
Where is the confused looking devil in the top right from?
Cut out of the "Bomber Comics" Issue #2, which is in the Public Domain. There's no particular meaning behind it, but more info on that comic is at comics.org.