Created
October 21, 2012 19:59
-
-
Save skipme/3928295 to your computer and use it in GitHub Desktop.
module depo declaration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var core_o; | |
(function(){ | |
//"use strict"; | |
var log = function(msg){console.log(msg);}; | |
var extendFunctions = []; | |
function extendFunction(extendFunction, name, after){ | |
extendFunctions.push({name:name, after:after, foo:extendFunction}); | |
} | |
function clone(o) { | |
if(!o || 'object' !== typeof o) { | |
return o; | |
} | |
var c = 'function' === typeof o.pop ? [] : {}; | |
var p, v; | |
for(p in o) { | |
if(o.hasOwnProperty(p)) { | |
v = o[p]; | |
if(v && 'object' === typeof v) { | |
c[p] = clone(v); | |
} | |
else { | |
c[p] = v; | |
} | |
} | |
} | |
return c; | |
} | |
function registrateExtensionsFull(newtruss) | |
{ | |
var done; | |
var prevreg = 0; | |
while(!done) | |
{ | |
done = registrateExtensions(newtruss); | |
if(!done) | |
{ | |
if(newtruss.options.registered.length == prevreg) | |
throw 'missed some module'; | |
} | |
prevreg = newtruss.options.registered.length; | |
} | |
log('extended by '+extendFunctions.length+" modules"); | |
} | |
function registrateExtensions(newtruss) | |
{ | |
// extend by all registered extensions | |
var allregistered = true; | |
newtruss.option("registered", new Array()); | |
var registered = newtruss.options.registered; | |
for (var i = 0; i < extendFunctions.length; i++) { | |
if(registered.indexOf(extendFunctions[i].name)>=0){continue;} | |
var passed = true; | |
if(typeof extendFunctions[i].after === "string") | |
{ | |
if(registered.indexOf(extendFunctions[i].after)>=0) | |
{ | |
passed = true; | |
} else { | |
passed=false; | |
} | |
} else if(typeof extendFunctions[i].after === "object") | |
{ | |
passed = true; | |
for (var j = 0; j < extendFunctions[i].after.length; j++) { | |
if(registered.indexOf(extendFunctions[i].after[j])<0) | |
{ | |
passed = false; | |
break; | |
} | |
} | |
} else if(typeof extendFunctions[i].after==="undefined") { | |
passed = true; | |
} | |
if(passed) { | |
extendFunctions[i].foo(newtruss); | |
registered.push(extendFunctions[i].name); | |
log('extended by '+extendFunctions[i].name); | |
} else { | |
allregistered = false; | |
} | |
} | |
return allregistered; | |
} | |
core_o = { | |
extendModule : extendFunction | |
} | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment