Permalink
Browse files

Refactor for node.js, making build() and watch() callable programatic…

…ally, added src and min commands to the cli, and moved some stuff around, better folder organization
  • Loading branch information...
1 parent 249a8a9 commit 14b436b78b098d4519f06536a9d31f5a6ce197ff Taka Kojima committed Feb 5, 2012
View
416 bin/minion.Interface.js
@@ -1,414 +1,70 @@
var fs = require("fs");
-var color = require("ansi-color").set;
-var jshint = require("jshint").JSHINT;
+var path = require("path");
var minion = require("../lib/minion.js");
-
minion.define("minion", {
Interface : minion.extend("minion.Singleton", {
_args : {},
- _configObj : {},
- _currentBuildIndex : 0,
- _compiledClasses: [],
- _compressedFiles : [],
- _errored : false,
- _filesToWatch : [],
- _basePath : "",
setArgs : function (args){
this._args = args;
},
- build : function (configFile, quiet, cb) {
-
- if(typeof quiet == "undefined") {quiet = false;}
-
- this._configObj = {};
- this._currentBuildIndex = 0;
- this._compiledClasses = [];
- this._compressedFiles = [];
- this._errored = false;
- this._filesToWatch = [];
- this._basePath = process.cwd();
-
- var path, outputPath, configObj, includeMinion;
-
- configFile = this._parsePath(this._args.c, this._parsePath(configFile, null));
-
- // Load Config File
- if(configFile){
- this._filesToWatch.push(configFile);
- configObj = this._getJSONFile(configFile);
-
- if(configFile.indexOf("/") > -1){
- if(this._isAbsolutePath(configFile)){
- this._basePath = "";
- }
- this._basePath += configFile.substr(0, configFile.lastIndexOf("/"));
- }
- }
-
- // Otherwise, build the config obj ourselves
- else{
-
- includeMinion = this._args.i || false;
- path = this._parsePath(this._args.p, process.cwd());
- output = this._parsePath(this._args.o, null);
-
- this._basePath = path;
-
- var c = this._args._[1];
-
- var buildGroup = {
- "class_path" : path,
- "output" : output,
- "classes" : [c],
- "prepend_files" : [],
- "append_files" : [],
- "include_minion" : includeMinion,
- "embed_provides" : false,
- "jshint" : this._args.jshint
- };
-
- configObj = {build_groups: [buildGroup]};
-
- configObj.output_path = this._args.p;
- }
+ build : function () {
+ /*
+ -p The path to your class definitions.
+ -o This specifies the file you want MinionJS to write the minified contents to.
+ -w Run in watch mode, will rebuild everytime a file in the build tree is modified.
+ -i Whether or not to include MinionJS in the minified js file.
+ -c Configuration File. You can use a Config File to specify options for your build, this is the preferred method.
+ */
if(this._args.w){
- configObj.watch = true;
+ this.watch();
+ return;
}
- if(configObj.vars){
- configObj = this._parseJSONTemplate(configObj.vars, configObj);
- }
-
- this._configObj = configObj;
-
- if(configObj.build_groups.length >= 1){
- this._currentBuildIndex = 0;
- this._doBuild(this._configObj.build_groups[0], quiet, cb);
+ if(this._args.c) {
+ minion.build(this._args.c, null, true);
}
else{
- if(!quiet){
- this._logError("No build group found!!!");
- }
- else{
- return new Error("No build group found!!!");
- }
- }
- },
-
- _doBuild : function (group, quiet, cb) {
-
- var _classes = [];
- var path = group.class_path || this._configObj.class_path;
- var output_path = group.output_path || this._configObj.output_path || path;
-
- minion.configure({
- classPath : this._parsePath(path)
- });
-
- for(var j = 0; j < group.classes.length; j ++){
- var className = group.classes[j];
- if(className.indexOf("*") > -1){
- _classes = _classes.concat(this._getAllClassesInNamespace(className));
- }
- else{
- _classes.push(className);
- }
- }
-
- try{
-
- minion.require(_classes, this.proxy( function(){
-
- var loadedClasses = this._getAllDependencies(_classes);
-
- var output = group.include_minion ? this._compress(__dirname + "/minion.js") : "";
-
- for(var i = loadedClasses.length-1; i >= 0; i --) {
- if(this._compiledClasses.indexOf(loadedClasses[i]) > -1){
- // If this file has already been compiled, and include_duplicates != true, exclude it from the list.
- if(!group.include_duplicates){
- loadedClasses.splice(i, 1);
- }
- }
- else{
- this._compiledClasses.push(loadedClasses[i]);
- }
- }
-
- var jshint_check = group.jshint || this._configObj.jshint || false;
- var jshint_opts = group.jshint_options || this._configObj.jshint_options || {};
-
- for(var i = 0; i < loadedClasses.length; i ++){
- var file = minion.getURL(loadedClasses[i]);
-
- if(jshint_check){
-
- if(!jshint(this._getFileContents(file), jshint_opts)){
- this._logError("JSHINT failed on file... " + file);
- this._log("", "red+bold");
- this._log("------------------------------------------------------------------------------", "red+bold");
- this._log("", "red+bold");
-
- for (var j = 0; j < jshint.errors.length; j ++) {
- var error = jshint.errors[j];
- this._logError(("Line : " + error.line + ", Character : " + error.character + ", Reason : " + error.reason + "\n " + this._trim(error.evidence)) + "\n");
- }
-
- //return;
- }
- }
- if(!this._errored){
- output += this._compress(file) + ";";
- }
- this._filesToWatch.push(file);
- }
-
- if(!this._errored){
- if(group.output){
- fs.writeFile(group.output, output);
- }
- else{
- var err = "Please specify an output path for this build group..." + _classes.join(", ");
- if(!quiet){
- this._logError(err);
- }
- else{
- return new Error(err);
- }
- }
-
- this._compressedFiles.push({
- file : this._outputPath(group.output, path, output_path),
- classes: loadedClasses
- });
-
- // If there is another build group, let's build that one...
- if(this._configObj.build_groups[this._currentBuildIndex+1]){
- this._currentBuildIndex += 1;
- this._doBuild(this._configObj.build_groups[this._currentBuildIndex], quiet, cb);
- }
-
- if(!quiet){
- // Otherwise, we can now output all the minion.configure code...
- this._log("");
- this._log("");
- this._log("*********************************** BUILD SUCCESSFUL ************************************");
- this._log("");
- this._log("");
- this._log("----------------------------------------------------------------------------------------");
- this._log("Copy and paste the following into your code, before the first minion.require() call:");
- this._log("----------------------------------------------------------------------------------------");
- this._log("");
- this._log("minion.configure({paths: " + JSON.stringify(this._compressedFiles, null, 4) + "});");
- this._log("");
- this._log("----------------------------------------------------------------------------------------");
- this._log("");
- }
-
- if(cb){
- cb(this._compressedFiles);
- }
- }
-
- // If the watch flag was passed, set up watchers on all the loaded files, rebuilding whenever a file changes
- if(this._configObj.watch){
- if(!quiet){
- this._log("");
- this._log("****************************** WATCHING FOR CHANGES *********************************");
- this._watchFiles();
- }
- }
-
- }));
- }
- catch(e){
- var err = "An unexpected error occured when trying to compile the following classes..." + _classes.join(", ");
- if(!quiet){
- this._logError(err);
- }
- else{
- return new Error(err);
- }
- }
- },
-
- _getFileContents : function(file){
- return fs.readFileSync(file, 'utf-8');
- },
-
- _compress : function (file) {
-
- var fs = require('fs');
- var uglify = require('uglify-js').uglify;
- var parser = require('uglify-js').parser;
-
- var code = this._getFileContents(file);
-
- code = parser.parse(code);
- code = uglify.ast_mangle(code);
- code = uglify.ast_squeeze(code);
- code = uglify.gen_code(code);
-
- return code;
- },
-
- _isAbsolutePath : function(path) {
- return path[0] === "/";
- },
-
- _parsePath : function (path, fallbackValue) {
- if(!path){return fallbackValue};
- return path[0] === "/" ? path : this._basePath + "/" + path;
- },
-
- _getJSONFile : function (file) {
- var str = fs.readFileSync(file, 'utf-8');
- return JSON.parse(str);
- },
-
- _writeJSONFile : function (file, obj) {
- fs.writeFile(file, JSON.stringify(obj, null, 4));
- },
-
- _parseJSONTemplate : function (vars, obj) {
-
- // String
- if(typeof obj === "string"){
- for (var v in vars){
- obj = obj.replace("{{" + v + "}}", vars[v]);
- }
- return obj;
- }
- // Array
- else if(obj instanceof Array){
- for(var i = 0; i < obj.length; i ++){
- obj[i] = this._parseJSONTemplate(vars, obj[i]);
- }
+ var opts = {};
+ opts.class_path - this._args.p;
+ opts.output = this._args.o;
+ opts.include_minion = this._args.i;
+ minion.build(opts, null, true);
}
- // Object
- else if(typeof obj === "object"){
- for (var prop in obj){
- obj[prop] = this._parseJSONTemplate(vars, obj[prop]);
- }
- }
-
- return obj;
-
},
- _trim : function(s) {
- return s.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
- },
-
- _log : function (msg, clr){
- clr = clr || "cyan";
- console.log(color(msg, clr));
- },
-
- _logError : function(err) {
- if(!this._errored){
- this._log("");
- this._log("");
- this._log("*********************************** BUILD FAILURE ************************************", "red+bold");
- this._log("");
- this._log("");
- this._errored = true;
+ watch : function () {
+ console.dir(this._args);
+ if(this._args.c) {
+ minion.watch(this._args.c, null, true);
}
-
- this._log("Error : " + err, "red+bold");
- },
-
- _outputPath : function(path, rootPath, outputPath) {
- path = path.replace(this._parsePath(rootPath), "");
- path = path.replace(rootPath, "");
- outputPath = outputPath[outputPath.length-1] === "/" ? outputPath : outputPath + "/";
- if(path[0] === "/"){
- path = path.substr(1);
- }
- return outputPath + path;
- },
-
- // Recursively checks Class __dependencies and adds them all to an array
- _getAllDependencies : function (classes) {
-
- var dependencies = [];
-
- for(var i = 0; i < classes.length; i ++) {
- var c = minion.get(classes[i]);
-
- // Don't add the base minion classes to the dependency list as they are already compiled.
- if (c.__nsID !== "minion") {
- dependencies.push(classes[i]);
-
- if(c.__dependencies && c.__dependencies.length > 0){
- dependencies = dependencies.concat(this._getAllDependencies(c.__dependencies));
- }
- }
+ else{
+ var opts = {};
+ opts.class_path - this._args.p;
+ opts.output = this._args.o;
+ opts.include_minion = this._args.i;
+ minion.watch(opts, null, true);
}
-
- return dependencies;
},
- // Recursively checks directories under the given namespace and returns a list of all Files/Classes in said namespace/directory.
- _getAllClassesInNamespace : function(namespace){
-
- var _classes = [];
-
- var dirPath = minion.getURL(namespace);
- var dirStats = fs.statSync(dirPath);
-
- namespace = namespace.replace(".*", "");
-
- if(!dirStats.isDirectory()){
- this._logError(dirPath + " is not a directory!");
- return [];
- }
-
- var files = fs.readdirSync(dirPath);
-
- for(var i = 0; i < files.length; i ++){
- var file = files[i];
- var fileStats = fs.statSync(dirPath + "/" + file);
-
- if(fileStats.isDirectory()){
- _classes = _classes.concat(this._getAllClassesInNamespace(namespace + "." + file + ".*"));
- }
-
- else if(file.indexOf(".js") > -1){
- _classes.push(namespace + "." + file.replace(".js", ""));
- }
- }
+ // Outputs the browser version of the source to the path specified i.e. `minion src minion.js` will write a file to cwd/minion.js
+ src : function () {
+ var output = path.normalize(process.cwd() + "/" + this._args._[1]);
+ fs.writeFileSync(output, fs.readFileSync(path.normalize(__dirname + "/../dist/minion-latest.js"), 'utf-8'));
- return _classes;
},
- // Watches all files in this._filesToWatch and calls this._build() if any changes are made.
- _watchFiles : function (){
- for(var i = 0; i < this._filesToWatch.length; i ++) {
- var file = this._filesToWatch[i];
- fs.watchFile(file, {persistent: true, interval: 50}, this.proxy(function (curr, prev){
- if (+curr.mtime > +prev.mtime) {
- this._unwatchFiles();
- this.build();
- }
- }));
- }
- },
- // Cleans up any watchers on this._filesToWatch files.
- _unwatchFiles : function() {
- for(var i = 0; i < this._filesToWatch.length; i ++) {
- var file = this._filesToWatch[i];
- fs.unwatchFile(file);
- }
+ // Outputs the minified source to the path specified i.e. `minion min minion.min.js` will write a file to cwd/minion.min.js
+ min : function () {
+ var output = path.normalize(process.cwd() + "/" + this._args._[1]);
+ fs.writeFileSync(output, fs.readFileSync(path.normalize(__dirname + "/../dist/minion-latest.min.js"), 'utf-8'));
}
-
})
});
View
187 dist/minion-1.4.4.js
@@ -2,10 +2,10 @@
* minion.JS v1.4.4
* http://minion.org
*
- * (c) 2011, Taka Kojima
+ * (c) 2012, Taka Kojima (taka@gigafied.com)
* Licensed under the MIT License
*
- * Date: Sat Feb 4 07:13:18 2012 -0800
+ * Date: Sun Feb 5 09:08:32 2012 -0800
*/
/**
@@ -43,6 +43,8 @@ THE SOFTWARE.</p>
TODO:
- Multiple inheritance
- Independent library support, i.e. ability to do minion.require("minion.libs.jquery") to load jquery
+ - AMD Compliant?
+ - minion.provides("namespace.*");
- __preDefine method on Classes, takes 1 argument, a callback that gets called once __preDefine does all it needs to do
*/
@@ -95,40 +97,30 @@ var minion = (function (root) {
var _ns = {};
var _errorTimeout = 1e4;
- /**
- * @exports _minion as minion
- * @class
- */
var _minion = {};
/*================= HELPER FUNCTIONS =================*/
- /** @private */
var _isArray = Array._isArray || function (a) {
return a instanceof Array;
};
- /** @private */
var _isObject = function (obj) {
return typeof obj === "object";
};
- /** @private */
var _isString = function (s) {
return typeof s === 'string' || s instanceof String;
};
- /** @private */
var _isFunction = function (fn) {
return typeof fn === "function";
};
- /** @private */
var _strToArray = function (s) {
return (!_isArray(s)) ? [s] : s;
};
- /** @private */
var _concatArray = function (a, b, forceUnique) {
b = b || [];
if(!forceUnique){
@@ -148,7 +140,6 @@ var minion = (function (root) {
return b;
};
- /** @private */
var _copyToNS = function(o1,o2){
for (var i in o1) {
if(o1.hasOwnProperty(i)){
@@ -157,7 +148,6 @@ var minion = (function (root) {
}
};
- /** @private */
var _removeFromNS = function(o1,o2){
for (var i in o1) {
if(o1.hasOwnProperty(i)){
@@ -169,7 +159,7 @@ var minion = (function (root) {
// Recursively checks dependencies
- /** @private */
+
var _areDependenciesLoaded = function (o) {
o = _minion.get(o, false);
var i;
@@ -187,7 +177,7 @@ var minion = (function (root) {
return true;
};
- /** @private */
+
var _checkLoadQueue = function () {
var i, j, q, dependenciesLoaded, classes, classesArray;
q = {};
@@ -215,7 +205,7 @@ var minion = (function (root) {
}
};
- /** @private */
+
var _checkExtendQueue = function () {
var eq = _extendQueue;
var i, superClass, ns, id;
@@ -244,7 +234,7 @@ var minion = (function (root) {
_checkLoadQueue();
};
- /** @private */
+
var _checkWaitQueue = function () {
var w = _waitingForLoad;
@@ -274,10 +264,6 @@ var minion = (function (root) {
/**
* Injects a Script tag into the DOM
- *
- * @param f The path of the file to inject.
- * @param c The class which maps to the file we are injecting.
- * @private
*/
var _inject = function(f, c) {
@@ -305,7 +291,6 @@ var minion = (function (root) {
_waitingForLoad.push(injectObj);
- /** @ignore */
script.onreadystatechange = /** @ignore */ script.onload = function (e) {
if (_minion.isDefined(c)) {
injectObj.s.onload = injectObj.s.onreadystatechange = null;
@@ -314,7 +299,6 @@ var minion = (function (root) {
}
};
- /** @ignore */
script.onerror = function (e) {
injectObj.s.onerror = null;
_waitingForLoad.splice(_waitingForLoad.indexOf(injectObj), 1);
@@ -329,9 +313,6 @@ var minion = (function (root) {
/**
* Does all the loading of JS files
- *
- * @param q The queue to be loaded
- * @private
*/
var _load = function (q) {
@@ -358,12 +339,6 @@ var minion = (function (root) {
/**
* Used by minion.get() and minion.define().
* Get the namespace/Class, or creates it if it does not exist. Also optionally creates Objects in the specified namepsace.
- *
- * @param {String|Object}id The fully qualified namespace.
- * @param {Boolean} autoCreate Whether or not to create a blank object if the namespace does not yet exist.
- * @param {Object} [definitions] An object of class definitions which will be added to the namespace.
- * @returns {Object} The object that represents the fully qualified namespace passed in as the first argument.
- * @private
*/
var _namespace = function (id, autoCreate, definitions) {
@@ -458,9 +433,6 @@ var minion = (function (root) {
/**
* Configure minion.
- *
- * @public
- * @param {Object} configObj Configuration object, possible properties are : classPath, separator and fileSuffix
*/
_minion.configure = function (configObj) {
@@ -485,22 +457,23 @@ var minion = (function (root) {
/**
* Alias minion under a different namespace. I.e. var woot = minion.alias("woot");
- *
- * @public
- * @param {String} alias The name of the namespace to alias minion under.
*/
_minion.alias = function (alias) {
_aliases.push(alias);
return _minion;
};
+ _minion.getAliases = function () {
+ return _aliases;
+ };
+
+ _minion.separator = function () {
+ return _separator;
+ };
+
/**
* Gets the object by it's fully qualified identifier.
- *
- * @public
- * @param {String} id The identifier to get
- * @returns {Object|Boolean} The object that represents the identifier or false if it has not yet been defined.
*/
_minion.get = function (id) {
@@ -523,11 +496,6 @@ var minion = (function (root) {
/**
* Defines Classes under the given namespace.
- *
- * @public
- * @param {String} id The namespace to define the Classes under.
- * @param {Object} [definitions] An object of class definitions which will be added to the namespace
- * @returns {Object} The object that represents the namespace passed in as the first argument.
*/
_minion.define = function (id, definitions) {
var r = _namespace(id, true, definitions);
@@ -537,10 +505,6 @@ var minion = (function (root) {
/**
* Gets the URL for a given identifier.
- *
- * @public
- * @param {String} id The fully qualified name to look up.
- * @returns {String} The URL of the file that maps to the fully qualified name.
*/
_minion.getURL = function (id) {
@@ -557,12 +521,8 @@ var minion = (function (root) {
};
/**
- * Checks to see whether the given fully qualified name or Object is defined as a minion class. (Checks for .__isDefined)<br>
+ * Checks to see whether the given fully qualified name or Object is defined as a minion class. (Checks for .__isDefined)
* NOTE: Classes that have not yet loaded all of their dependencies, will return FALSE for this check.
- *
- * @public
- * @param {String|Object} id The fully qualfied class name, or an Object.
- * @returns {Boolean} Whether or not this is defined.
*/
_minion.isDefined = function (id) {
@@ -572,11 +532,6 @@ var minion = (function (root) {
/**
* Extends a given class asynchronously.
- *
- * @public
- * @param {String} id The fully qualified name of the Class you want to extend.
- * @param {Object} obj A new Class Object
- * @returns {Object} The extended Class, or, if still waiting on dependencies, the original Object with a few more properties for internal minion use.
*/
_minion.extend = function (id, obj) {
@@ -597,10 +552,6 @@ var minion = (function (root) {
/**
* Tells minion that filePath provides the class definitions for these classes.
* Useful in cases where you group specific things into minfiied js files.
- *
- * @public
- * @param {String} file The path of a JS file.
- * @param {String|Array} definitions Fully qualfiied name(s) of class(es)
*/
_minion.provides = function (file, definitions) {
@@ -619,10 +570,6 @@ var minion = (function (root) {
/**
* Asyncrhonously loads in js files for the classes specified.
* If the classes have already been loaded, or are already defined, the callback function is invoked immediately.
- *
- * @public
- * @param {String|Array} ids The fully qualified name(s) of the class(es) to load.
- * @param {Function} callback The function to call once all classes (and their dependencies) have been loaded.
*/
_minion.require = function (ids, callback) {
@@ -673,11 +620,6 @@ var minion = (function (root) {
*
* Identifiers can contain the* wildcard character as its last segment (eg: test.*)
* which will import all Classes under the given namespace.
- *
- * @public
- * @param {String|Array} ids The fully qualfiied name(s) to import into the global namespace.
- * @param {Object=[root]} The scope to use.
- * @returns {Object} Returns the object passed in as the second argument, with the classes passed in as the first argument as properties.
*/
_minion.use = function (ids, scope) {
@@ -720,38 +662,38 @@ var minion = (function (root) {
return scope;
};
- /** @private */
+
_minion.enableNotifications = function () {
if (_minion.isDefined("minion.NotificationManager")) {
if (!_notificationManager) {
_notificationManager = new (minion.get("minion.NotificationManager"))();
- /** @private */
+
_minion.subscribe = function () {
_notificationManager.subscribe.apply(_notificationManager, arguments);
};
- /** @private */
+
_minion.unsubscribe = function () {
_notificationManager.unsubscribe.apply(_notificationManager, arguments);
};
- /** @private */
+
_minion.publish = function () {
_notificationManager.publish.apply(_notificationManager, arguments);
};
- /** @private */
+
_minion.holdNotification = function () {
_notificationManager.holdNotification.apply(_notificationManager, arguments);
};
- /** @private */
+
_minion.releaseNotification = function () {
_notificationManager.releaseNotification.apply(_notificationManager, arguments);
};
- /** @private */
+
_minion.cancelNotification = function () {
_notificationManager.cancelNotification.apply(_notificationManager, arguments);
};
@@ -783,11 +725,11 @@ var minion = (function (root) {
minion.define("minion", {
/**
- * The minion Base Class
- * Classical JavaScript Inheritance (or an attempt thereof)
- * minion.Class is the ONLY Class to extend this directly, do not directly extend this Class.
- * Largely taken from: http://ejohn.org/blog/simple-javascript-inheritance/
- * @ignore */
+ The minion Base Class
+ Classical JavaScript Inheritance (or an attempt thereof)
+ minion.Class is the ONLY Class to extend this directly, do not directly extend this Class.
+ Largely taken from: http://ejohn.org/blog/simple-javascript-inheritance/
+ */
__BaseClass__ : (function() {
@@ -844,12 +786,10 @@ var minion = (function (root) {
// Checks the function contents to see if it has a reference to __super
var _doesCallSuper = /xyz/.test(function(){var xyz;}) ? /\b__super\b/ : /.*/;
- /** @ignore */
var _baseClass = function(){};
_baseClass.__isDefined = true;
- /** @ignore */
_baseClass.__extend = function(obj) {
// By passing "__no_init__" as the first argument, we skip calling the constructor and other initialization;
@@ -891,8 +831,6 @@ var minion = (function (root) {
Handy for referencing dependencies. If a Class requires example.Test, then you can reference said class
in any method by this.__imports.Test;
- This method is preferred over this.use_dependencies(), as you have to explicitly call this.unuse_dependencies()
- to be responsible, at the end of every method.
*/
if(!_class.prototype.hasOwnProperty("__imports")){
_class.prototype.__imports = minion.use(this.__dependencies, {});
@@ -1007,13 +945,11 @@ var minion = (function (root) {
__isDefined: true
},
- /**
- *
+ /**
* The base minion Class. All Classes are required to be descendants
* of this class, either directly, or indirectly.
- *
- * @constructs
*/
+
init: function(){
if(!this._interestHandlers){
this._interestHandlers = [];
@@ -1022,27 +958,21 @@ var minion = (function (root) {
/**
* Local version of window.setTimeout that keeps scope of <i>this</i>.<br>
- *
- * @returns {Number} A timeout ID
*/
setTimeout : function(func, delay){
return setTimeout(this.proxy(func), delay);
},
/**
* Local version of window.setInterval that keeps scope of <i>this</i>.<br>
- *
- * @returns {Number} An interval ID
*/
setInterval : function(func, delay){
return setInterval(this.proxy(func), delay);
},
/**
- * Shorthand for <i>func.bind(this)</i><br>
- * or rather, <i>$.proxy(func, this)</i> in jQuery terms
- *
- * @returns {Function} The proxied function
+ * Shorthand for func.bind(this)
+ * or rather, $.proxy(func, this) in jQuery terms
*/
proxy : function(func){
var bind = function (context) {
@@ -1058,10 +988,6 @@ var minion = (function (root) {
/**
* Subscribes to a notification.
- *
- * @public
- * @param {String} name The name of the Notification you are subscribing to.
- * @param {Function} handler A function to be called upon receiving the given Notification.
*/
subscribe : function(name, handler, priority){
@@ -1076,9 +1002,6 @@ var minion = (function (root) {
/**
* Unsubscribes from a notification.
- *
- * @public
- * @param {String} name The name of the Notification you are unsubscribing from.
*/
unsubscribe : function(name){
@@ -1104,17 +1027,12 @@ var minion = (function (root) {
/**
* Publishes a notification with the specified data.
- *
- * @param {String} name The name of the Notification you are publishing.
- * @param {Object} data An object of data you want to send with the Notification.
- * @param {Function} callback A callback function to be invoked if Notification.respond() is called
*/
publish : function(name, data, callback){
minion.publish(name, data, this, callback);
},
- /** @ignore */
handleNotification : function(n){
var handler = this._interestHandlers[n.name];
if(handler){
@@ -1131,22 +1049,15 @@ var minion = (function (root) {
minion.define("minion", {
- /** @lends minion.Singleton# */
-
Singleton : minion.extend("minion.Class", {
/**
- *
* A way to easily implement Singletons.
- *
- * @constructs
- * @extends minion.Class
*/
init : function(){
},
- /** @ignore */
__preInit : function(){
if(this.constructor.__instance){
return this.constructor.__instance;
@@ -1158,18 +1069,14 @@ var minion = (function (root) {
return this.constructor.__instance;
},
- /** @ignore */
__static : {
- /** @lends minion.Singleton# */
__isSingleton: true,
/**
*
* Returns the instance of this Singleton. If this Class has not yet been instantiated, creates a new instance and returns that.
* Otherwise, it returns the already existing reference.
- *
- * @memberOf minion.Singleton#
*/
getInstance : function(){
if(!this.__instance){
@@ -1185,13 +1092,11 @@ var minion = (function (root) {
});
})();(function(){
-
+
"use strict";
minion.define("minion", {
- /** @lends minion.Static# */
-
Static : minion.extend("minion.Singleton", {
__static : {
@@ -1201,11 +1106,7 @@ var minion = (function (root) {
},
/**
- *
* A way to easily implement Static Classes.
- *
- * @constructs
- * @extends minion.Singleton
*/
init : function(){
@@ -1220,8 +1121,6 @@ var minion = (function (root) {
minion.define("minion", {
- /** @lends minion.Notification# */
-
Notification : minion.extend("minion.Class", {
data : {},
@@ -1235,11 +1134,6 @@ var minion = (function (root) {
*
* Notifications are the backbone of Minion's pub/sub model.
* You should not have to construct Notification's directly, as the publish() method does this for you.
- *
- * @constructs
- * @param {String} name The name of the Notification.
- * @param {Object} data An object of data associated with the Notification.
- * @param {Function} callback A callback function. This gets invoked by calling Notification.respond();
*/
init : function(name, data, callback) {
this.name = name;
@@ -1250,18 +1144,13 @@ var minion = (function (root) {
/**
*
* Holds a notification. Useful if you want to do other things before other instances receive this Notification,
- *
- * @public
*/
hold : function() {
this.status = 2;
},
/**
- *
* Releases a Notification, call this at some point after hold();
- *
- * @public
*/
release : function() {
@@ -1270,10 +1159,7 @@ var minion = (function (root) {
},
/**
- *
* Cancels a Notification, any instances interested in this Notification higher up the chain will not receive it.
- *
- * @public
*/
cancel : function() {
@@ -1288,11 +1174,7 @@ var minion = (function (root) {
},
/**
- *
* Dispatches a Notification. You will rarely ever construct or call dispatch() on Notifications directly, as the publish() method handles all of this.
- *
- * @param {Object} obj An Object referencing what is dispatching this Notification.
- * @public
*/
dispatch : function(obj) {
@@ -1325,7 +1207,6 @@ var minion = (function (root) {
/*
This Class handles all the nitty gritty Notification stuff.
- TODO: Be nice and add some comments for other people :)
*/
require : [
View
6 dist/minion-1.4.4.min.js
@@ -2,9 +2,9 @@
* minion.JS v1.4.4
* http://minion.org
*
- * (c) 2011, Taka Kojima
+ * (c) 2012, Taka Kojima (taka@gigafied.com)
* Licensed under the MIT License
*
- * Date: Sat Feb 4 07:13:18 2012 -0800
+ * Date: Sun Feb 5 09:08:32 2012 -0800
*/
- var minion=function(a){"use strict",Array.prototype.indexOf=Array.prototype.indexOf||function(a,b){if(!!this.length&&this instanceof Array&&arguments.length>=1){b=b||0;if(b<this.length){while(b<this.length){if(this[b]===a)return b;b+=1}return-1}return-1}return-1};var b=[],c=["minion"],d=".",e="",f="",g,h=[],i=[],j,k=[],l=[],m,n=500,o=typeof window=="undefined",p=a,q={},r=1e4,s={},t=Array._isArray||function(a){return a instanceof Array},u=function(a){return typeof a=="object"},v=function(a){return typeof a=="string"||a instanceof String},w=function(a){return typeof a=="function"},x=function(a){return t(a)?a:[a]},y=function(a,b,c){b=b||[];if(!c)return a||[].concat(b);b=[].concat(b),a=a||[];for(var d=0,e=a.length;d<e;d+=1)b.indexOf(a[d])<0&&(b[b.length]=a[d]);return b},z=function(a,b){for(var c in a)a.hasOwnProperty(c)&&(b[c]=a[c])},A=function(a,b){for(var c in a)a.hasOwnProperty(c)&&(b[c]=null,delete b[c])},B=function(a){a=s.get(a,!1);var b;if(!a.__isDefined)return!1;if(a.__dependencies)for(b=0;b<a.__dependencies.length;b+=1)if(!B(a.__dependencies[b]))return!1;return!0},C=function(){var a,b,c,d,e,f;c={},e={},f=[];for(a=h.length-1;a>=0;a--){c=h[a],d=!0;for(b=0;b<c.c.length;b++){d=B(c.c[b]);if(!d)break}d&&(c.cb&&c.cb.apply(p,s.get(c.c)),h.splice(a,1))}},D=function(){var a=i,b,c,e,f;for(b=a.length-1;b>=0;b--){e=a[b].split(d),f=e.splice(e.length-1,1)[0],e=s.get(e.join(d),!1);if(e[f].__toExtend){c=s.get(e[f].__extendedFrom,!1);if(c.__isDefined){e[f].__toExtend=!1,delete e[f].__toExtend,e[f]=s.extend(e[f].__extendedFrom,e[f]),a.splice(b,1),setTimeout(D,0);return}}}C()},E=function(){var a=k,b,c;j&&clearTimeout(j);for(b=0;b<a.length;b+=1)c=a[b],c.e+=50,s.isDefined(c.c)?c.s.onload():c.e>=r&&c.s.onerror();a.length>0&&(j=setTimeout(E,n))},F=function(a,b){var c=document,d="body",e,f;if(!c[d])return setTimeout(function(){F(a,b)},0);f=c.createElement("script"),f.async=!0,e={f:a,c:b,e:0,s:f},k.push(e),f.onreadystatechange=f.onload=function(a){s.isDefined(b)&&(e.s.onload=e.s.onreadystatechange=null,e.s.onerror=null,k.splice(k.indexOf(e),1))},f.onerror=function(a){throw e.s.onerror=null,k.splice(k.indexOf(e),1),Error(e.c+" failed to load. Attempted to load from file: "+e.f)},f.src=a,c[d].appendChild(f)},G=function(a){h.push(a);for(var b=0;b<a.f.length;b+=1)o?require(a.f[b]):F(a.f[b],a.c[b]);j=setTimeout(E,n)},H=function(a,b,e){a=a||"",e=e||!1;var f=q,g;if(a&&!u(a)&&!w(a)){var h=a.split(d);c.indexOf(h[0])>-1&&(f=s,h.splice(0,1));for(g=0;g<h.length;g+=1){if(!f[h[g]]){if(!b)return!1;f[h[g]]={}}f=f[h[g]]}}else{if(a==="")return!1;f=a}if(e){e.require=y(e.require);var j=e.require;for(var k in e)if(k!=="require"){var l=a+d+k,m=e[k];m.__extendedFrom&&j.push(m.__extendedFrom),m.__toExtend&&i.indexOf(l)<0&&i.push(l),m.__static=m.__static||{},m.__nsID=a,m.__ns=f,m.__class=k,j.length>0&&(m.__dependencies=y(m.__dependencies,j,!0),s.require(j));if(s.isDefined(m)&&m.prototype){var n=m.prototype;n.__nsID=a,n.__ns=f,n.__class=k,j.length>0&&(n.__dependencies=y(n.__dependencies,j,!0))}f[k]=m}}return f};return s.configure=function(a){a=a||{},e=a.classPath||e,e=e.lastIndexOf("/")===e.length-1?e:e+"/",d=a.separator||d,f=a.fileSuffix||f;if(a.paths)for(var b=0;b<a.paths.length;b++){var c=a.paths[b];s.provides(c.file,c.classes)}g=!0},s.alias=function(a){return c.push(a),s},s.get=function(a){if(!t(a))return H(a,!1);var b=s.use(a,{}),c=[];for(var d in b)b.hasOwnProperty(d)&&c.push(b[d]);return c},s.define=function(a,b){var c=H(a,!0,b);return D(),c},s.getURL=function(a){if(b[a])return b[a];var c=a.indexOf("*")>-1;a=c?a.replace(".*",""):a;var g=e+a.replace(RegExp("\\"+d,"g"),"/")+(c?"":".js")+(f?"?"+f:"");return g},s.isDefined=function(a){return a=!u(a)&&!w(a)?H(a,!1):a,a?a.__isDefined:!1},s.extend=function(a,b){return s.isDefined(a)?b=s.get(a).__extend(b):b.__toExtend=!0,b.__extendedFrom=a,b},s.provides=function(a,c){c=x(c);for(var d=0;d<c.length;d+=1)b[c[d]]=a},s.require=function(a,b){g||s.configure(),a=x(a);var c=[],d=[];for(var e=0;e<a.length;e++){var f=a[e],h=s.getURL(f),i=s.get(f);d.push(f),l.indexOf(h)<0&&!s.get(f)&&(c.push(h),l.push(h))}if(c.length>0){var j={f:c,c:d,cb:b};setTimeout(function(){G(j)},0)}else b&&b.apply(p,s.get(a))},s.use=function(a,b){a=a||[],a=x(a),b=b||q,b===q&&s.unuse();var c,e,f,g,h;for(c=0;c<a.length;c+=1){e=a[c],f=s.get(e,!0),g=e.split(d),e=g.splice(g.length-1,1)[0],g=s.get(g.join(d),!1);if(e==="*")for(h in g)g.hasOwnProperty(h)&&(b[h]=g[h]);else g[e]&&(b[e]=g[e])}return b},s.enableNotifications=function(){s.isDefined("minion.NotificationManager")&&(m||(m=new(minion.get("minion.NotificationManager")),s.subscribe=function(){m.subscribe.apply(m,arguments)},s.unsubscribe=function(){m.unsubscribe.apply(m,arguments)},s.publish=function(){m.publish.apply(m,arguments)},s.holdNotification=function(){m.holdNotification.apply(m,arguments)},s.releaseNotification=function(){m.releaseNotification.apply(m,arguments)},s.cancelNotification=function(){m.cancelNotification.apply(m,arguments)}))},typeof p.define=="function"&&p.define.amd&&p.define([],function(){return s}),o&&(module.exports=s),s}(this);(function(){"use strict",minion.define("minion",{__BaseClass__:function(){var a=function(a){var b,c,d;if(!a||typeof a!="object")return a;if(a instanceof Date)return(new Date).setTime(a.getTime());if(a instanceof Array)return a.concat();if(typeof a=="object"){d={};for(c in a)a.hasOwnProperty(c)&&(d[c]=a[c]);return d}return a},b=function(a,b){return function(){var c=this.__super||null;this.__super=b;var d=a.apply(this,arguments);return c?this.__super=c:(this.__super=null,delete this.__super),d}},c=/xyz/.test(function(){var a})?/\b__super\b/:/.*/,d=function(){};return d.__isDefined=!0,d.__extend=function(e){var f=this,g=new f("__no_init__"),h={},i=this;for(var j in e)e.hasOwnProperty(j)&&(j!=="__static"?typeof e[j]=="function"&&typeof g[j]=="function"&&c.test(e[j])?g[j]=b(e[j],g[j]):g[j]=e[j]:typeof e[j]=="object"&&j.indexOf("__")!==0&&(h[j]=e[j]));var k=function(){if(arguments[0]!=="__no_init__"){k.prototype.hasOwnProperty("__imports")||(k.prototype.__imports=minion.use(this.__dependencies,{}));if(!this.__preInit){for(var b in h)h.hasOwnProperty(b)&&(this[b]=a(h[b]));return this.init.apply(this,arguments)}return this.__preInit.apply(this,arguments)}};k.prototype=g,k.prototype.constructor=k,k.__extend=d.__extend,k.prototype.__extend=function(a,b){return function(){return b.apply(a,arguments)}}(k,k.__extend),k.__ns=e.__ns||"",k.__nsID=e.__nsID||"",k.__class=e.__class||"",k.__dependencies=e.__dependencies||[];var l;if(e.__static){k.__static=k.__static||{};for(l in e.__static)k[l]||(k[l]=e.__static[l],k.__static[l]=e.__static[l]);k.__static=e.__static}if(this.__static){k.__static=k.__static||{};for(l in this.__static)k[l]||(k[l]=this.__static[l],k.__static[l]=this.__static[l])}if(k.__static.__isStatic){var m=k,n=new m;n.__static=k.__static;for(l in k.__static)n[l]=k.__static[l];return n}return k},d}()})})(),function(){"use strict",minion.define("minion",{Class:minion.extend("minion.__BaseClass__",{__static:{__isDefined:!0},init:function(){this._interestHandlers||(this._interestHandlers=[])},setTimeout:function(a,b){return setTimeout(this.proxy(a),b)},setInterval:function(a,b){return setInterval(this.proxy(a),b)},proxy:function(a){var b=function(a){if(!a)return this;var b=this;return function(){return b.apply(a,Array.prototype.slice.call(arguments))}};return b.call(a,this)},subscribe:function(a,b,c){this._interestHandlers||(this._interestHandlers=[]),b&&!this._interestHandlers[a]&&(minion.subscribe(this,a,c),this._interestHandlers[a]=b)},unsubscribe:function(a){this._interestHandlers&&this._interestHandlers[a]&&(this._interestHandlers[a]=null,delete this._interestHandlers[a]),minion.unsubscribe(this,a)},unsubscribeAll:function(){for(var a in this._interestHandlers)this._interestHandlers.hasOwnProperty(a)&&this.unsubscribe(a);this._interestHandlers=[]},publish:function(a,b,c){minion.publish(a,b,this,c)},handleNotification:function(a){var b=this._interestHandlers[a.name];b&&this.proxy(b)(a)}})})}(),function(){"use strict",minion.define("minion",{Singleton:minion.extend("minion.Class",{init:function(){},__preInit:function(){return this.constructor.__instance?this.constructor.__instance:(this.init.apply(this,arguments),this.constructor.__instance=this,this.constructor.__instance)},__static:{__isSingleton:!0,getInstance:function(){if(!this.__instance){var a=this;return this.__instance=new a,this.__instance}return this.__instance}}})})}(),function(){"use strict",minion.define("minion",{Static:minion.extend("minion.Singleton",{__static:{__isDefined:!0,__isStatic:!0},init:function(){}})})}(),function(){"use strict",minion.define("minion",{Notification:minion.extend("minion.Class",{data:{},name:"",dispatcher:null,status:0,pointer:0,callback:null,init:function(a,b,c){this.name=a,this.data=b,this.callback=c},hold:function(){this.status=2},release:function(){this.status=1,minion.releaseNotification(this)},cancel:function(){minion.cancelNotification(this),this.data={},this.name="",this.status=0,this.pointer=0,this.dispatcher=null,this.callback=null},dispatch:function(a){this.status=1,this.pointer=0,this.dispatcher=a,minion.publish(this)},respond:function(){this.callback&&(this.callback.apply(typeof this.dispatcher=="object"?this.dispatcher:this,arguments),this.callback=null,this.cancel())}})}),minion.define("minion",{require:["minion.Notification"],NotificationManager:minion.extend("minion.Singleton",{_pendingNotifications:[],_pendingNotificationNames:[],_interests:{},_removeQueue:[],subscribe:function(a,b,c){c=isNaN(c)?-1:c,this._interests[b]=this._interests[b]||[],c>-1&&c<this._interests[b].length?this._interests[b].splice(c,0,a):this._interests[b].push(a)},unsubscribe:function(a,b){if(b instanceof Array){for(var c=0;c<b.length;c++)this.unsubscribe(a,b[c]);return}var d=this._interests[b].indexOf(a);if(a&&d>-1)if(this._pendingNotificationNames.indexOf(b)>-1){var e=this._removeQueue[b]=this._removeQueue[b]||[];e.push(a)}else this._interests[b].splice(d,1)},publish:function(a,b,c,d){a instanceof this.__imports.Notification||(a=new this.__imports.Notification(a,b,d),a.status=1,a.pointer=0,a.dispatcher=c);var e=a.name;this._interests[e]&&(this._pendingNotifications.push(a),this._pendingNotificationNames.push(e),this._notifyObjects(a))},_notifyObjects:function(a){var b=a.name;while(a.pointer<this._interests[b].length){if(a.status!==1)return;this._interests[b][a.pointer].handleNotification&&this._interests[b][a.pointer].handleNotification(a),a.pointer++}a.status===1&&!a.callback&&this.cancelNotification(a)},getNotification:function(a){for(var b=0;b<this._pendingNotifications.length;b++)if(this._pendingNotifications[b].name===a)return this._pendingNotifications[b]},releaseNotification:function(a){a.status=1,this._pendingNotifications.indexOf(a)>-1&&this._notifyObjects(a)},cancelNotification:function(a){if(a){var b=a.name;this._pendingNotifications.splice(this._pendingNotifications.indexOf(a),1),a.status=0;if(this._removeQueue[b]){for(var c=0;c<this._removeQueue.length;c++)this.unsubscribe(this._removeQueue[b][c],b);this._removeQueue[b]=null,delete this._removeQueue[b]}a=null}}})}),minion.enableNotifications()}();
+ var minion=function(a){"use strict",Array.prototype.indexOf=Array.prototype.indexOf||function(a,b){if(!!this.length&&this instanceof Array&&arguments.length>=1){b=b||0;if(b<this.length){while(b<this.length){if(this[b]===a)return b;b+=1}return-1}return-1}return-1};var b=[],c=["minion"],d=".",e="",f="",g,h=[],i=[],j,k=[],l=[],m,n=500,o=typeof window=="undefined",p=a,q={},r=1e4,s={},t=Array._isArray||function(a){return a instanceof Array},u=function(a){return typeof a=="object"},v=function(a){return typeof a=="string"||a instanceof String},w=function(a){return typeof a=="function"},x=function(a){return t(a)?a:[a]},y=function(a,b,c){b=b||[];if(!c)return a||[].concat(b);b=[].concat(b),a=a||[];for(var d=0,e=a.length;d<e;d+=1)b.indexOf(a[d])<0&&(b[b.length]=a[d]);return b},z=function(a,b){for(var c in a)a.hasOwnProperty(c)&&(b[c]=a[c])},A=function(a,b){for(var c in a)a.hasOwnProperty(c)&&(b[c]=null,delete b[c])},B=function(a){a=s.get(a,!1);var b;if(!a.__isDefined)return!1;if(a.__dependencies)for(b=0;b<a.__dependencies.length;b+=1)if(!B(a.__dependencies[b]))return!1;return!0},C=function(){var a,b,c,d,e,f;c={},e={},f=[];for(a=h.length-1;a>=0;a--){c=h[a],d=!0;for(b=0;b<c.c.length;b++){d=B(c.c[b]);if(!d)break}d&&(c.cb&&c.cb.apply(p,s.get(c.c)),h.splice(a,1))}},D=function(){var a=i,b,c,e,f;for(b=a.length-1;b>=0;b--){e=a[b].split(d),f=e.splice(e.length-1,1)[0],e=s.get(e.join(d),!1);if(e[f].__toExtend){c=s.get(e[f].__extendedFrom,!1);if(c.__isDefined){e[f].__toExtend=!1,delete e[f].__toExtend,e[f]=s.extend(e[f].__extendedFrom,e[f]),a.splice(b,1),setTimeout(D,0);return}}}C()},E=function(){var a=k,b,c;j&&clearTimeout(j);for(b=0;b<a.length;b+=1)c=a[b],c.e+=50,s.isDefined(c.c)?c.s.onload():c.e>=r&&c.s.onerror();a.length>0&&(j=setTimeout(E,n))},F=function(a,b){var c=document,d="body",e,f;if(!c[d])return setTimeout(function(){F(a,b)},0);f=c.createElement("script"),f.async=!0,e={f:a,c:b,e:0,s:f},k.push(e),f.onreadystatechange=f.onload=function(a){s.isDefined(b)&&(e.s.onload=e.s.onreadystatechange=null,e.s.onerror=null,k.splice(k.indexOf(e),1))},f.onerror=function(a){throw e.s.onerror=null,k.splice(k.indexOf(e),1),Error(e.c+" failed to load. Attempted to load from file: "+e.f)},f.src=a,c[d].appendChild(f)},G=function(a){h.push(a);for(var b=0;b<a.f.length;b+=1)o?require(a.f[b]):F(a.f[b],a.c[b]);j=setTimeout(E,n)},H=function(a,b,e){a=a||"",e=e||!1;var f=q,g;if(a&&!u(a)&&!w(a)){var h=a.split(d);c.indexOf(h[0])>-1&&(f=s,h.splice(0,1));for(g=0;g<h.length;g+=1){if(!f[h[g]]){if(!b)return!1;f[h[g]]={}}f=f[h[g]]}}else{if(a==="")return!1;f=a}if(e){e.require=y(e.require);var j=e.require;for(var k in e)if(k!=="require"){var l=a+d+k,m=e[k];m.__extendedFrom&&j.push(m.__extendedFrom),m.__toExtend&&i.indexOf(l)<0&&i.push(l),m.__static=m.__static||{},m.__nsID=a,m.__ns=f,m.__class=k,j.length>0&&(m.__dependencies=y(m.__dependencies,j,!0),s.require(j));if(s.isDefined(m)&&m.prototype){var n=m.prototype;n.__nsID=a,n.__ns=f,n.__class=k,j.length>0&&(n.__dependencies=y(n.__dependencies,j,!0))}f[k]=m}}return f};return s.configure=function(a){a=a||{},e=a.classPath||e,e=e.lastIndexOf("/")===e.length-1?e:e+"/",d=a.separator||d,f=a.fileSuffix||f;if(a.paths)for(var b=0;b<a.paths.length;b++){var c=a.paths[b];s.provides(c.file,c.classes)}g=!0},s.alias=function(a){return c.push(a),s},s.getAliases=function(){return c},s.separator=function(){return d},s.get=function(a){if(!t(a))return H(a,!1);var b=s.use(a,{}),c=[];for(var d in b)b.hasOwnProperty(d)&&c.push(b[d]);return c},s.define=function(a,b){var c=H(a,!0,b);return D(),c},s.getURL=function(a){if(b[a])return b[a];var c=a.indexOf("*")>-1;a=c?a.replace(".*",""):a;var g=e+a.replace(RegExp("\\"+d,"g"),"/")+(c?"":".js")+(f?"?"+f:"");return g},s.isDefined=function(a){return a=!u(a)&&!w(a)?H(a,!1):a,a?a.__isDefined:!1},s.extend=function(a,b){return s.isDefined(a)?b=s.get(a).__extend(b):b.__toExtend=!0,b.__extendedFrom=a,b},s.provides=function(a,c){c=x(c);for(var d=0;d<c.length;d+=1)b[c[d]]=a},s.require=function(a,b){g||s.configure(),a=x(a);var c=[],d=[];for(var e=0;e<a.length;e++){var f=a[e],h=s.getURL(f),i=s.get(f);d.push(f),l.indexOf(h)<0&&!s.get(f)&&(c.push(h),l.push(h))}if(c.length>0){var j={f:c,c:d,cb:b};setTimeout(function(){G(j)},0)}else b&&b.apply(p,s.get(a))},s.use=function(a,b){a=a||[],a=x(a),b=b||q,b===q&&s.unuse();var c,e,f,g,h;for(c=0;c<a.length;c+=1){e=a[c],f=s.get(e,!0),g=e.split(d),e=g.splice(g.length-1,1)[0],g=s.get(g.join(d),!1);if(e==="*")for(h in g)g.hasOwnProperty(h)&&(b[h]=g[h]);else g[e]&&(b[e]=g[e])}return b},s.enableNotifications=function(){s.isDefined("minion.NotificationManager")&&(m||(m=new(minion.get("minion.NotificationManager")),s.subscribe=function(){m.subscribe.apply(m,arguments)},s.unsubscribe=function(){m.unsubscribe.apply(m,arguments)},s.publish=function(){m.publish.apply(m,arguments)},s.holdNotification=function(){m.holdNotification.apply(m,arguments)},s.releaseNotification=function(){m.releaseNotification.apply(m,arguments)},s.cancelNotification=function(){m.cancelNotification.apply(m,arguments)}))},typeof p.define=="function"&&p.define.amd&&p.define([],function(){return s}),o&&(module.exports=s),s}(this);(function(){"use strict",minion.define("minion",{__BaseClass__:function(){var a=function(a){var b,c,d;if(!a||typeof a!="object")return a;if(a instanceof Date)return(new Date).setTime(a.getTime());if(a instanceof Array)return a.concat();if(typeof a=="object"){d={};for(c in a)a.hasOwnProperty(c)&&(d[c]=a[c]);return d}return a},b=function(a,b){return function(){var c=this.__super||null;this.__super=b;var d=a.apply(this,arguments);return c?this.__super=c:(this.__super=null,delete this.__super),d}},c=/xyz/.test(function(){var a})?/\b__super\b/:/.*/,d=function(){};return d.__isDefined=!0,d.__extend=function(e){var f=this,g=new f("__no_init__"),h={},i=this;for(var j in e)e.hasOwnProperty(j)&&(j!=="__static"?typeof e[j]=="function"&&typeof g[j]=="function"&&c.test(e[j])?g[j]=b(e[j],g[j]):g[j]=e[j]:typeof e[j]=="object"&&j.indexOf("__")!==0&&(h[j]=e[j]));var k=function(){if(arguments[0]!=="__no_init__"){k.prototype.hasOwnProperty("__imports")||(k.prototype.__imports=minion.use(this.__dependencies,{}));if(!this.__preInit){for(var b in h)h.hasOwnProperty(b)&&(this[b]=a(h[b]));return this.init.apply(this,arguments)}return this.__preInit.apply(this,arguments)}};k.prototype=g,k.prototype.constructor=k,k.__extend=d.__extend,k.prototype.__extend=function(a,b){return function(){return b.apply(a,arguments)}}(k,k.__extend),k.__ns=e.__ns||"",k.__nsID=e.__nsID||"",k.__class=e.__class||"",k.__dependencies=e.__dependencies||[];var l;if(e.__static){k.__static=k.__static||{};for(l in e.__static)k[l]||(k[l]=e.__static[l],k.__static[l]=e.__static[l]);k.__static=e.__static}if(this.__static){k.__static=k.__static||{};for(l in this.__static)k[l]||(k[l]=this.__static[l],k.__static[l]=this.__static[l])}if(k.__static.__isStatic){var m=k,n=new m;n.__static=k.__static;for(l in k.__static)n[l]=k.__static[l];return n}return k},d}()})})(),function(){"use strict",minion.define("minion",{Class:minion.extend("minion.__BaseClass__",{__static:{__isDefined:!0},init:function(){this._interestHandlers||(this._interestHandlers=[])},setTimeout:function(a,b){return setTimeout(this.proxy(a),b)},setInterval:function(a,b){return setInterval(this.proxy(a),b)},proxy:function(a){var b=function(a){if(!a)return this;var b=this;return function(){return b.apply(a,Array.prototype.slice.call(arguments))}};return b.call(a,this)},subscribe:function(a,b,c){this._interestHandlers||(this._interestHandlers=[]),b&&!this._interestHandlers[a]&&(minion.subscribe(this,a,c),this._interestHandlers[a]=b)},unsubscribe:function(a){this._interestHandlers&&this._interestHandlers[a]&&(this._interestHandlers[a]=null,delete this._interestHandlers[a]),minion.unsubscribe(this,a)},unsubscribeAll:function(){for(var a in this._interestHandlers)this._interestHandlers.hasOwnProperty(a)&&this.unsubscribe(a);this._interestHandlers=[]},publish:function(a,b,c){minion.publish(a,b,this,c)},handleNotification:function(a){var b=this._interestHandlers[a.name];b&&this.proxy(b)(a)}})})}(),function(){"use strict",minion.define("minion",{Singleton:minion.extend("minion.Class",{init:function(){},__preInit:function(){return this.constructor.__instance?this.constructor.__instance:(this.init.apply(this,arguments),this.constructor.__instance=this,this.constructor.__instance)},__static:{__isSingleton:!0,getInstance:function(){if(!this.__instance){var a=this;return this.__instance=new a,this.__instance}return this.__instance}}})})}(),function(){"use strict",minion.define("minion",{Static:minion.extend("minion.Singleton",{__static:{__isDefined:!0,__isStatic:!0},init:function(){}})})}(),function(){"use strict",minion.define("minion",{Notification:minion.extend("minion.Class",{data:{},name:"",dispatcher:null,status:0,pointer:0,callback:null,init:function(a,b,c){this.name=a,this.data=b,this.callback=c},hold:function(){this.status=2},release:function(){this.status=1,minion.releaseNotification(this)},cancel:function(){minion.cancelNotification(this),this.data={},this.name="",this.status=0,this.pointer=0,this.dispatcher=null,this.callback=null},dispatch:function(a){this.status=1,this.pointer=0,this.dispatcher=a,minion.publish(this)},respond:function(){this.callback&&(this.callback.apply(typeof this.dispatcher=="object"?this.dispatcher:this,arguments),this.callback=null,this.cancel())}})}),minion.define("minion",{require:["minion.Notification"],NotificationManager:minion.extend("minion.Singleton",{_pendingNotifications:[],_pendingNotificationNames:[],_interests:{},_removeQueue:[],subscribe:function(a,b,c){c=isNaN(c)?-1:c,this._interests[b]=this._interests[b]||[],c>-1&&c<this._interests[b].length?this._interests[b].splice(c,0,a):this._interests[b].push(a)},unsubscribe:function(a,b){if(b instanceof Array){for(var c=0;c<b.length;c++)this.unsubscribe(a,b[c]);return}var d=this._interests[b].indexOf(a);if(a&&d>-1)if(this._pendingNotificationNames.indexOf(b)>-1){var e=this._removeQueue[b]=this._removeQueue[b]||[];e.push(a)}else this._interests[b].splice(d,1)},publish:function(a,b,c,d){a instanceof this.__imports.Notification||(a=new this.__imports.Notification(a,b,d),a.status=1,a.pointer=0,a.dispatcher=c);var e=a.name;this._interests[e]&&(this._pendingNotifications.push(a),this._pendingNotificationNames.push(e),this._notifyObjects(a))},_notifyObjects:function(a){var b=a.name;while(a.pointer<this._interests[b].length){if(a.status!==1)return;this._interests[b][a.pointer].handleNotification&&this._interests[b][a.pointer].handleNotification(a),a.pointer++}a.status===1&&!a.callback&&this.cancelNotification(a)},getNotification:function(a){for(var b=0;b<this._pendingNotifications.length;b++)if(this._pendingNotifications[b].name===a)return this._pendingNotifications[b]},releaseNotification:function(a){a.status=1,this._pendingNotifications.indexOf(a)>-1&&this._notifyObjects(a)},cancelNotification:function(a){if(a){var b=a.name;this._pendingNotifications.splice(this._pendingNotifications.indexOf(a),1),a.status=0;if(this._removeQueue[b]){for(var c=0;c<this._removeQueue.length;c++)this.unsubscribe(this._removeQueue[b][c],b);this._removeQueue[b]=null,delete this._removeQueue[b]}a=null}}})}),minion.enableNotifications()}();
View
1,337 dist/minion-1.5.1.js
@@ -0,0 +1,1337 @@
+/*
+ * minion.JS v1.5.1
+ * http://minion.org
+ *
+ * (c) 2012, Taka Kojima (taka@gigafied.com)
+ * Licensed under the MIT License
+ *
+ * Date: Sun Feb 5 09:08:32 2012 -0800
+ */
+ /**
+
+@fileOverview
+
+<h4>MinionJS - Cross-Platform & Cross-Browser JavaScript Inheritance</h4>
+
+<p>Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:</p>
+
+<p>The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.</p>
+
+<p>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.</p>
+*/
+
+
+/**
+* Global MinionJS Object with Static methods.
+*
+* @namespace
+*/
+
+/*
+ TODO:
+ - Multiple inheritance
+ - Independent library support, i.e. ability to do minion.require("minion.libs.jquery") to load jquery
+ - AMD Compliant?
+ - minion.provides("namespace.*");
+ - __preDefine method on Classes, takes 1 argument, a callback that gets called once __preDefine does all it needs to do
+*/
+
+var minion = (function (root) {
+
+ "use strict";
+
+ // If Array.indexOf is not defined, let's define it.
+ Array.prototype.indexOf = Array.prototype.indexOf || function (a, b) {
+ if (!this.length || !(this instanceof Array) || arguments.length < 1) {
+ return -1;
+ }
+
+ b = b || 0;
+
+ if (b >= this.length) {
+ return -1;
+ }
+
+ while (b < this.length) {
+ if (this[b] === a) {
+ return b;
+ }
+ b += 1;
+ }
+ return -1;
+ };
+
+ var _classMappings = [];
+ var _aliases = ["minion"];
+
+ var _separator = ".";
+ var _class_path = "";
+ var _file_suffix = "";
+
+ var _initialized;
+
+ var _loadQueue = [];
+ var _extendQueue = [];
+
+ var _waitID;
+ var _waitingForLoad = [];
+ var _loadedFiles = [];
+ var _notificationManager;
+ var _waitInterval = 500;
+
+ var _isNode = (typeof window === "undefined");
+
+ var _root = root;
+ var _ns = {};
+ var _errorTimeout = 1e4;
+
+ var _minion = {};
+
+ /*================= HELPER FUNCTIONS =================*/
+
+ var _isArray = Array._isArray || function (a) {
+ return a instanceof Array;
+ };
+
+ var _isObject = function (obj) {
+ return typeof obj === "object";
+ };
+
+ var _isString = function (s) {
+ return typeof s === 'string' || s instanceof String;
+ };
+
+ var _isFunction = function (fn) {
+ return typeof fn === "function";
+ };
+
+ var _strToArray = function (s) {
+ return (!_isArray(s)) ? [s] : s;
+ };
+
+ var _concatArray = function (a, b, forceUnique) {
+ b = b || [];
+ if(!forceUnique){
+ return a || [].concat(b);
+ }
+
+ // Force unique values
+ b = [].concat(b);
+ a = a || [];
+
+ for(var i = 0, l = a.length; i < l; i += 1){
+ if(b.indexOf(a[i]) < 0){
+ b[b.length] = a[i];
+ }
+ }
+
+ return b;
+ };
+
+ var _copyToNS = function(o1,o2){
+ for (var i in o1) {
+ if(o1.hasOwnProperty(i)){
+ o2[i] = o1[i];
+ }
+ }
+ };
+
+ var _removeFromNS = function(o1,o2){
+ for (var i in o1) {
+ if(o1.hasOwnProperty(i)){
+ o2[i] = null;
+ delete o2[i];
+ }
+ }
+ };
+
+
+ // Recursively checks dependencies
+
+ var _areDependenciesLoaded = function (o) {
+ o = _minion.get(o, false);
+ var i;
+
+ if (!o.__isDefined) {
+ return false;
+ }
+ if (o.__dependencies) {
+ for (i = 0; i < o.__dependencies.length; i += 1) {
+ if (!_areDependenciesLoaded(o.__dependencies[i])) {
+ return false;
+ }
+ }
+ }
+ return true;
+ };
+
+
+ var _checkLoadQueue = function () {
+ var i, j, q, dependenciesLoaded, classes, classesArray;
+ q = {};
+ classes = {};
+ classesArray = [];
+
+ for (i = _loadQueue.length - 1; i >= 0; i --) {
+
+ q = _loadQueue[i];
+ dependenciesLoaded = true;
+
+ for (j = 0; j < q.c.length; j ++) {
+ dependenciesLoaded = _areDependenciesLoaded(q.c[j]);
+ if (!dependenciesLoaded) {
+ break;
+ }
+ }
+
+ if (dependenciesLoaded) {
+ if (q.cb) {
+ q.cb.apply(_root, _minion.get(q.c));
+ }
+ _loadQueue.splice(i, 1);
+ }
+ }
+ };
+
+
+ var _checkExtendQueue = function () {
+ var eq = _extendQueue;
+ var i, superClass, ns, id;
+
+ for (i = eq.length - 1; i >= 0; i --) {
+
+ ns = eq[i].split(_separator);
+ id = ns.splice(ns.length - 1, 1)[0];
+ ns = _minion.get(ns.join(_separator), false);
+
+ if (ns[id].__toExtend) {
+ superClass = _minion.get(ns[id].__extendedFrom, false);
+ if (superClass.__isDefined) {
+
+ ns[id].__toExtend = false;
+ delete ns[id].__toExtend;
+
+ ns[id] = _minion.extend(ns[id].__extendedFrom, ns[id]);
+
+ eq.splice(i, 1);
+ setTimeout(_checkExtendQueue, 0);
+ return;
+ }
+ }
+ }
+ _checkLoadQueue();
+ };
+
+
+ var _checkWaitQueue = function () {
+
+ var w = _waitingForLoad;
+ var i, o;
+
+ if (_waitID) {
+ clearTimeout(_waitID);
+ }
+
+ for (i = 0; i < w.length; i += 1) {
+ o = w[i];
+ o.e += 50;
+
+ if (_minion.isDefined(o.c)) {
+ o.s.onload();
+ }
+
+ else if (o.e >= _errorTimeout) {
+ o.s.onerror();
+ }
+ }
+
+ if (w.length > 0) {
+ _waitID = setTimeout(_checkWaitQueue, _waitInterval);
+ }
+ };
+
+ /**
+ * Injects a Script tag into the DOM
+ */
+
+ var _inject = function(f, c) {
+
+ var doc = document;
+ var body = "body";
+
+ var injectObj, script;
+
+ if (!doc[body]) {
+ return setTimeout(function(){
+ _inject(f,c);
+ }, 0);
+ }
+
+ script = doc.createElement("script");
+ script.async = true;
+
+ injectObj = {
+ f : f, // File
+ c : c, // Class
+ e : 0, // Elapsed Time
+ s : script // Script
+ };
+
+ _waitingForLoad.push(injectObj);
+
+ script.onreadystatechange = /** @ignore */ script.onload = function (e) {
+ if (_minion.isDefined(c)) {
+ injectObj.s.onload = injectObj.s.onreadystatechange = null;
+ injectObj.s.onerror = null;
+ _waitingForLoad.splice(_waitingForLoad.indexOf(injectObj), 1);
+ }
+ };
+
+ script.onerror = function (e) {
+ injectObj.s.onerror = null;
+ _waitingForLoad.splice(_waitingForLoad.indexOf(injectObj), 1);
+ throw new Error(injectObj.c + " failed to load. Attempted to load from file: " + injectObj.f);
+ };
+
+ script.src = f;
+
+ // Append the script to the document body
+ doc[body].appendChild(script);
+ };
+
+ /**
+ * Does all the loading of JS files
+ */
+
+ var _load = function (q) {
+
+ _loadQueue.push(q);
+
+ for (var i = 0; i < q.f.length; i += 1) {
+
+ if(_isNode){
+ require(q.f[i]);
+ }
+ else{
+ _inject(q.f[i], q.c[i]);
+ }
+ }
+
+ /*
+ If the load times out, fire onerror after the time defined by _errorTimeout (default is 10 seconds)
+ (can be changed through minion.config({minion.errorTimeout : ms});
+ */
+ _waitID = setTimeout(_checkWaitQueue, _waitInterval);
+ };
+
+ /**
+ * Used by minion.get() and minion.define().
+ * Get the namespace/Class, or creates it if it does not exist. Also optionally creates Objects in the specified namepsace.
+ */
+
+ var _namespace = function (id, autoCreate, definitions) {
+ id = id || "";
+ definitions = definitions || false;
+
+ var ns = _ns;
+ var i;
+
+ if (id && !_isObject(id) && !_isFunction(id)) {
+ var parts = id.split(_separator);
+
+ if (_aliases.indexOf(parts[0]) > -1) {
+ ns = _minion;
+ parts.splice(0,1);
+ }
+
+ for (i = 0; i < parts.length; i += 1) {
+ if (!ns[parts[i]]) {
+ if (autoCreate) {
+ ns[parts[i]] = {};
+ }
+ else{
+ return false;
+ }
+ }
+ ns = ns[parts[i]];
+ }
+ }
+
+ else if (id !== "") {
+ ns = id;
+ }
+ else{
+ return false;
+ }
+
+ if (definitions) {
+
+ definitions.require = _concatArray(definitions.require);
+ var cr = definitions.require;
+
+ for (var className in definitions) {
+
+ if (className !== "require") {
+
+ var qualifiedName = id + _separator + className;
+ var c = definitions[className];
+
+ if (c.__extendedFrom) {
+ cr.push(c.__extendedFrom);
+ }
+
+ if (c.__toExtend) {
+ if (_extendQueue.indexOf(qualifiedName) < 0) {
+ _extendQueue.push(qualifiedName);
+ }
+ }
+
+ c.__static = c.__static || {};
+
+ c.__nsID = id;
+ c.__ns = ns;
+ c.__class = className;
+
+ if (cr.length > 0) {
+ c.__dependencies = _concatArray(c.__dependencies, cr, true);
+ _minion.require(cr);
+ }
+
+ if (_minion.isDefined(c) && c.prototype) {
+ var proto = c.prototype;
+ proto.__nsID = id;
+ proto.__ns = ns;
+ proto.__class = className;
+
+ if (cr.length > 0) {
+ proto.__dependencies = _concatArray(proto.__dependencies, cr, true);
+ }
+ }
+
+ ns[className] = c;
+ }
+ }
+ }
+
+ return ns;
+ };
+
+ /*================= END OF HELPER FUNCTIONS =================*/
+
+
+ /**
+ * Configure minion.
+ */
+
+ _minion.configure = function (configObj) {
+
+ configObj = configObj || {};
+
+ _class_path = configObj.classPath || _class_path;
+ _class_path = (_class_path.lastIndexOf("/") === _class_path.length - 1) ? _class_path : _class_path + "/";
+
+ _separator = configObj.separator || _separator;
+ _file_suffix = configObj.fileSuffix || _file_suffix;
+
+ if(configObj.paths){
+ for(var i = 0; i < configObj.paths.length; i ++){
+ var m = configObj.paths[i];
+ _minion.provides(m.file, m.classes);
+ }
+ }
+
+ _initialized = true;
+ };
+
+ /**
+ * Alias minion under a different namespace. I.e. var woot = minion.alias("woot");
+ */
+
+ _minion.alias = function (alias) {
+ _aliases.push(alias);
+ return _minion;
+ };
+
+ _minion.getAliases = function () {
+ return _aliases;
+ };
+
+ _minion.separator = function () {
+ return _separator;
+ };
+
+ /**
+ * Gets the object by it's fully qualified identifier.
+ */
+
+ _minion.get = function (id) {
+ if(!_isArray(id)){
+ return _namespace(id, false);
+ }
+ else{
+ var classes = _minion.use(id, {});
+ var classesArray = [];
+
+ for (var c in classes) {
+ if(classes.hasOwnProperty(c)) {
+ classesArray.push(classes[c]);
+ }
+ }
+
+ return classesArray;
+ }
+ };
+
+ /**
+ * Defines Classes under the given namespace.
+ */
+ _minion.define = function (id, definitions) {
+ var r = _namespace(id, true, definitions);
+ _checkExtendQueue();
+ return r;
+ };
+
+ /**
+ * Gets the URL for a given identifier.
+ */
+
+ _minion.getURL = function (id) {
+
+ if (_classMappings[id]) {
+ return _classMappings[id];
+ }
+
+ var isDir = id.indexOf("*") > -1;
+ id = isDir ? id.replace(".*", "") : id;
+ var url = _class_path + id.replace(new RegExp('\\' + _separator, 'g'), '/') + (isDir ? "" : '.js') + ((_file_suffix) ? "?" + _file_suffix : "");
+
+ return url;
+ };
+
+ /**
+ * Checks to see whether the given fully qualified name or Object is defined as a minion class. (Checks for .__isDefined)
+ * NOTE: Classes that have not yet loaded all of their dependencies, will return FALSE for this check.
+ */
+
+ _minion.isDefined = function (id) {
+ id = (!_isObject(id) && !_isFunction(id)) ? _namespace(id, false) : id;
+ return (id) ? id.__isDefined : false;
+ };
+
+ /**
+ * Extends a given class asynchronously.
+ */
+
+ _minion.extend = function (id, obj) {
+
+ // If the Class exists and is a minion class, then return the extended object.
+ if (_minion.isDefined(id)) {
+ obj = _minion.get(id).__extend(obj);
+ }
+ else{
+ obj.__toExtend = true;
+ }
+
+ obj.__extendedFrom = id;
+
+ return obj;
+ };
+
+ /**
+ * Tells minion that filePath provides the class definitions for these classes.
+ * Useful in cases where you group specific things into minfiied js files.
+ */
+
+ _minion.provides = function (file, definitions) {
+
+ // If classes is a String, create an array
+ definitions = _strToArray(definitions);
+
+ // If the file is not absolute, prepend the _class_path
+ //file = (!new RegExp("(http://|/)[^ :]+").test(file)) ? _class_path + file : file;
+
+ for (var i = 0; i < definitions.length; i += 1) {
+ _classMappings[definitions[i]] = file;
+ }
+ };
+
+ /**
+ * Asyncrhonously loads in js files for the classes specified.
+ * If the classes have already been loaded, or are already defined, the callback function is invoked immediately.
+ */
+
+ _minion.require = function (ids, callback) {
+ if (!_initialized) {
+ _minion.configure();
+ }
+
+ ids = _strToArray(ids);
+
+ var fileList = [];
+ var classList = [];
+
+ for (var i = 0; i < ids.length; i ++) {
+
+ var id = ids[i];
+ var file = _minion.getURL(id);
+ var get = _minion.get(id);
+
+ classList.push(id);
+
+ if ((_loadedFiles.indexOf(file) < 0) && !_minion.get(id)) {
+ fileList.push(file);
+ _loadedFiles.push(file);
+ }
+ }
+
+ if (fileList.length > 0) {
+
+ var q = {
+ f : fileList,
+ c : classList,
+ cb : callback
+ };
+
+ //_load(q);
+ setTimeout(function(){_load(q);}, 0);
+ }
+
+ else if (callback) {
+ callback.apply(_root, _minion.get(ids));
+ }
+ };
+
+ /**
+ * Copies an array of classes (by their fully qualified names) to the specified object/scope.
+ *
+ * By calling minion.use("test.Example", obj), you will be able to refer to test.Example as just obj.Example.
+ *
+ * Identifiers can contain the* wildcard character as its last segment (eg: test.*)
+ * which will import all Classes under the given namespace.
+ */
+
+ _minion.use = function (ids, scope) {
+
+ ids = ids || [];
+ ids = _strToArray(ids);
+ scope = scope || _ns;
+
+ if (scope === _ns) {
+ _minion.unuse();
+ }
+
+ var i, id, obj, ns, n;
+
+ for (i = 0; i < ids.length; i += 1) {
+
+ id = ids[i];
+
+ obj = _minion.get(id, true);
+ ns = id.split(_separator);
+ id = ns.splice(ns.length - 1, 1)[0];
+ ns = _minion.get(ns.join(_separator), false);
+
+ if (id === '*') {
+ // injects all ids under namespace into the root namespace
+ for (n in ns) {
+ if(ns.hasOwnProperty(n)){
+ scope[n] = ns[n];
+ }
+ }
+ }
+ else{
+ // injects this id into the root namespace
+ if (ns[id]) {
+ scope[id] = ns[id];
+ }
+ }
+ }
+
+ return scope;
+ };
+
+
+ _minion.enableNotifications = function () {
+ if (_minion.isDefined("minion.NotificationManager")) {
+ if (!_notificationManager) {
+ _notificationManager = new (minion.get("minion.NotificationManager"))();
+
+
+ _minion.subscribe = function () {
+ _notificationManager.subscribe.apply(_notificationManager, arguments);
+ };
+
+
+ _minion.unsubscribe = function () {
+ _notificationManager.unsubscribe.apply(_notificationManager, arguments);
+ };
+
+
+ _minion.publish = function () {
+ _notificationManager.publish.apply(_notificationManager, arguments);
+ };
+
+
+ _minion.holdNotification = function () {
+ _notificationManager.holdNotification.apply(_notificationManager, arguments);
+ };
+
+
+ _minion.releaseNotification = function () {
+ _notificationManager.releaseNotification.apply(_notificationManager, arguments);
+ };
+
+
+ _minion.cancelNotification = function () {
+ _notificationManager.cancelNotification.apply(_notificationManager, arguments);
+ };
+ }
+ }
+ };
+
+ /*
+ Define minion as an AMD module, if define is defined (and has .amd as a property)
+ */
+ if (typeof _root.define === "function" && _root.define.amd) {
+ _root.define([], function () {
+ return _minion;
+ });
+ }
+
+ // Export for node
+ if (_isNode){
+ module.exports = _minion;
+ }
+
+ return _minion;
+
+})(this);(function(){
+
+ "use strict";
+
+ //* @ignore */
+ minion.define("minion", {
+
+ /**
+ The minion Base Class
+ Classical JavaScript Inheritance (or an attempt thereof)
+ minion.Class is the ONLY Class to extend this directly, do not directly extend this Class.
+ Largely taken from: http://ejohn.org/blog/simple-javascript-inheritance/
+ */
+
+ __BaseClass__ : (function() {
+
+ /*
+ Attempts to shallow copy objects, so as to not have a bunch of references lying around in object instances
+ Otherwise, it is bad news bears doing something like this.nArray.push() in a Class method
+ because it modifies nArray on prototype, and thus any other instances of said Class
+ */
+ var _copy = function (obj) {
+ var i, attr, c;
+
+ // Null, undefined, number, boolean, string, function all get returned immediately, no need to copy them.
+ if (!obj || typeof obj !== "object") {
+ return obj;
+ }
+
+ if (obj instanceof Date) {
+ return new Date().setTime(obj.getTime());
+ }
+
+ if (obj instanceof Array) {
+ return obj.concat();
+ }
+
+ if (typeof obj === "object") {
+ c = {};
+ for (attr in obj) {
+ if (obj.hasOwnProperty(attr)) {
+ c[attr] = obj[attr];
+ }
+ }
+ return c;
+ }
+ // If it fails, just return the original object.
+ return obj;
+ };
+
+ var _createSuperFunction = function (fn, superFn) {
+ return function() {
+ var tmp = this.__super || null;
+
+ // Reference the prototypes method, as super temporarily
+ this.__super = superFn;
+
+ var ret = fn.apply(this, arguments);
+
+ // Reset this.__super
+ if(tmp){this.__super = tmp;}
+ else{this.__super = null; delete this.__super;}
+ return ret;
+ };
+ };
+
+ // Checks the function contents to see if it has a reference to __super
+ var _doesCallSuper = /xyz/.test(function(){var xyz;}) ? /\b__super\b/ : /.*/;
+
+ var _baseClass = function(){};
+
+ _baseClass.__isDefined = true;
+
+ _baseClass.__extend = function(obj) {
+
+ // By passing "__no_init__" as the first argument, we skip calling the constructor and other initialization;
+ var This = this;
+ var _proto = new This("__no_init__");
+ var _perInstanceProps = {};
+ var _this = this;
+
+ // Copy the object's properties onto the prototype
+ for(var name in obj) {
+
+ if(obj.hasOwnProperty(name)) {
+
+ if(name !== "__static"){
+ // If we're overwriting an existing function that calls this.__super, do a little super magic.
+ if(typeof obj[name] === "function" && typeof _proto[name] === "function" && _doesCallSuper.test(obj[name])){
+ _proto[name] = _createSuperFunction(obj[name], _proto[name]);
+ }
+ else{
+ _proto[name] = obj[name];
+ }
+ }
+
+ /*
+ If it's an array or an object, we need to make a per instance copy of these values, so as to not affect other
+ instances when dealing with Arrays or Objects.
+ */
+ else if (typeof obj[name] === "object" && name.indexOf("__") !== 0) {
+ _perInstanceProps[name] = obj[name];
+ }
+ }
+ }
+
+ var _class = function() {
+
+ if(arguments[0] !== "__no_init__"){
+
+ /*
+ Handy for referencing dependencies. If a Class requires example.Test, then you can reference said class
+ in any method by this.__imports.Test;
+
+ */
+ if(!_class.prototype.hasOwnProperty("__imports")){
+ _class.prototype.__imports = minion.use(this.__dependencies, {});
+ }
+
+ if(!this.__preInit){
+
+ for (var attr in _perInstanceProps) {
+ if (_perInstanceProps.hasOwnProperty(attr)) {
+ this[attr] = _copy(_perInstanceProps[attr]);
+ }
+ }
+
+ // All real construction is actually done in the init method
+ return this.init.apply(this, arguments);
+ }
+
+ else{
+ return this.__preInit.apply(this, arguments);
+ }
+
+ }
+ };
+
+ // Set the prototype and Constructor accordingly.
+ _class.prototype = _proto;
+ //* @ignore */
+ _class.prototype.constructor = _class;
+
+ // Expose the extend method
+ //* @ignore */
+ _class.__extend = _baseClass.__extend;
+
+ _class.prototype.__extend = (function(scope, fn){
+ return function(){
+ return fn.apply(scope, arguments);
+ };
+ })(_class, _class.__extend);
+
+ /*
+ Custom minion properties, anything beginning with an __ on a Class or instance, is populated and used by minion.
+ The "__" prefix is used to avoid naming conflictions with developers, and allows
+ us to not have to impose a list of reserved words on developers.
+ */
+
+ _class.__ns = obj.__ns || "";
+ _class.__nsID = obj.__nsID || "";
+ _class.__class = obj.__class || "";
+ _class.__dependencies = obj.__dependencies || [];
+
+ /*
+ Add all static methods and properties that are defined in the __static object.
+ Only write to it if it doesn't already exist, to disable overwriting things we actually need for minion by malicious or
+ plain bad code.
+ */
+ var prop;
+
+ if(obj.__static){
+ _class.__static = _class.__static || {};
+ for(prop in obj.__static){
+ if(!_class[prop]){
+ _class[prop] = obj.__static[prop];
+ _class.__static[prop] = obj.__static[prop];
+ }
+ }
+ _class.__static = obj.__static;
+ }
+
+ if(this.__static){
+ _class.__static = _class.__static || {};
+ for(prop in this.__static){
+ if(!_class[prop]){
+ _class[prop] = this.__static[prop];
+ _class.__static[prop] = this.__static[prop];
+ }
+ }
+ }
+
+ if(_class.__static.__isStatic){
+
+ var StaticClass = _class;
+ var s = new StaticClass();
+
+ s.__static = _class.__static;
+
+ for(prop in _class.__static){
+ s[prop] = _class.__static[prop];
+ }
+
+ return s;
+ }
+
+ return _class;
+ };
+
+ return _baseClass;
+
+ })()
+ });
+
+})();(function(){
+
+ "use strict";
+
+ minion.define("minion", {
+
+ /** @lends minion.Class# */
+
+ Class : minion.extend("minion.__BaseClass__", {
+
+ __static : {
+ __isDefined: true
+ },
+
+ /**
+ * The base minion Class. All Classes are required to be descendants
+ * of this class, either directly, or indirectly.
+ */
+
+ init: function(){
+ if(!this._interestHandlers){
+ this._interestHandlers = [];
+ }
+ },
+
+ /**
+ * Local version of window.setTimeout that keeps scope of <i>this</i>.<br>
+ */
+ setTimeout : function(func, delay){
+ return setTimeout(this.proxy(func), delay);
+ },
+
+ /**
+ * Local version of window.setInterval that keeps scope of <i>this</i>.<br>
+ */
+ setInterval : function(func, delay){
+ return setInterval(this.proxy(func), delay);
+ },
+
+ /**
+ * Shorthand for func.bind(this)
+ * or rather, $.proxy(func, this) in jQuery terms
+ */
+ proxy : function(func){
+ var bind = function (context) {
+ if (!context) {return this;}
+ var this_ = this;
+ return function() {
+ return this_.apply(context, Array.prototype.slice.call(arguments));
+ };
+ };
+
+ return bind.call(func, this);
+ },
+
+ /**
+ * Subscribes to a notification.
+ */
+
+ subscribe : function(name, handler, priority){
+ if(!this._interestHandlers){
+ this._interestHandlers = [];
+ }
+ if(handler && !this._interestHandlers[name]){
+ minion.subscribe(this, name, priority);
+ this._interestHandlers[name] = handler;
+ }
+ },
+
+ /**
+ * Unsubscribes from a notification.
+ */
+
+ unsubscribe : function(name){
+ if(this._interestHandlers && this._interestHandlers[name]){
+ this._interestHandlers[name] = null;
+ delete this._interestHandlers[name];
+ }
+ minion.unsubscribe(this, name);
+ },
+
+ /**
+ * Unsubscribes from all notifications registered via this.subscribe();
+ */
+
+ unsubscribeAll : function(){
+ for(var interest in this._interestHandlers){
+ if(this._interestHandlers.hasOwnProperty(interest)){
+ this.unsubscribe(interest);
+ }
+ }
+ this._interestHandlers = [];
+ },
+
+ /**
+ * Publishes a notification with the specified data.
+ */
+
+ publish : function(name, data, callback){
+ minion.publish(name, data, this, callback);
+ },
+
+ handleNotification : function(n){
+ var handler = this._interestHandlers[n.name];
+ if(handler){
+ this.proxy(handler)(n);
+ }
+ }
+
+ })
+ });
+
+})();(function(){
+
+ "use strict";
+
+ minion.define("minion", {
+
+ Singleton : minion.extend("minion.Class", {
+
+ /**
+ * A way to easily implement Singletons.
+ */
+ init : function(){
+
+ },
+
+ __preInit : function(){
+ if(this.constructor.__instance){
+ return this.constructor.__instance;
+ }
+
+ this.init.apply(this, arguments);
+
+ this.constructor.__instance = this;
+ return this.constructor.__instance;
+ },
+
+ __static : {
+
+ __isSingleton: true,
+
+ /**
+ *
+ * Returns the instance of this Singleton. If this Class has not yet been instantiated, creates a new instance and returns that.
+ * Otherwise, it returns the already existing reference.
+ */
+ getInstance : function(){
+ if(!this.__instance){
+ var This = this;
+ this.__instance = new This();
+ return this.__instance;
+ }
+ return this.__instance;
+ }
+ }
+
+ })
+ });
+
+})();(function(){
+
+ "use strict";
+
+ minion.define("minion", {
+
+ Static : minion.extend("minion.Singleton", {
+
+ __static : {
+ __isDefined : true,
+ __isStatic : true
+
+ },
+
+ /**
+ * A way to easily implement Static Classes.
+ */
+ init : function(){
+
+ }
+
+ })
+ });
+
+})();(function(){
+
+ "use strict";
+
+ minion.define("minion", {
+
+ Notification : minion.extend("minion.Class", {
+
+ data : {},
+ name : "",
+ dispatcher : null,
+ status : 0, // 0 : Closed; 1 : Pending; 2 : Hold
+ pointer : 0,
+ callback : null,
+
+ /**
+ *
+ * Notifications are the backbone of Minion's pub/sub model.
+ * You should not have to construct Notification's directly, as the publish() method does this for you.
+ */
+ init : function(name, data, callback) {
+ this.name = name;
+ this.data = data;
+ this.callback = callback;
+ },
+
+ /**
+ *
+ * Holds a notification. Useful if you want to do other things before other instances receive this Notification,
+ */
+ hold : function() {
+ this.status = 2;
+ },
+
+ /**
+ * Releases a Notification, call this at some point after hold();
+ */
+
+ release : function() {
+ this.status = 1;
+ minion.releaseNotification(this);
+ },
+
+ /**
+ * Cancels a Notification, any instances interested in this Notification higher up the chain will not receive it.
+ */
+
+ cancel : function() {
+ minion.cancelNotification(this);
+
+ this.data = {};
+ this.name = "";
+ this.status = 0;
+ this.pointer = 0;
+ this.dispatcher = null;
+ this.callback = null;
+ },
+
+ /**
+ * Dispatches a Notification. You will rarely ever construct or call dispatch() on Notifications directly, as the publish() method handles all of this.
+ */
+