/*! https://github.com/mckoss/namespace/blob/master/LICENSE.md
// Source: src/namespace.js */
/*! Namespace.js - modular namespaces in JavaScript
by Mike Koss - placed in the public domain
*/
//edited by webfan.de
function Namespace(root, _namespace, version) {
var globalNamespace = root[_namespace];
var VERSION = version;//'3.0.1';
function Plugin() {}
function numeric(s) {
if (!s) {
return 0;
}
var a = s.split('.');
return 10000 * parseInt(a[0]) + 100 * parseInt(a[1]) + parseInt(a[2]);
}
if (globalNamespace) {
if (numeric(VERSION) <= numeric(globalNamespace['VERSION'])) {
return;
}
Plugin = globalNamespace.constructor;
} else {
root[_namespace] = globalNamespace = new Plugin();
}
globalNamespace['VERSION'] = VERSION;
// Return new object with just the listed properties "projected"
// into the new object. Ignore undefined properties.
function project(obj, props) {
var result = {};
if (typeof props == 'string') {
props = [props];
}
for (var i = 0; i < props.length; i++) {
var name = props[i];
if (obj && obj.hasOwnProperty(name)) {
result[name] = obj[name];
}
}
return result;
}
root['project'] = project;
//require method
function Use(path) {
path = path.replace(/-/g, '_');
var parts = path.split('.');
var ns = globalNamespace;
for (var i = 0; i < parts.length; i++) {
if (ns[parts[i]] === undefined) {
ns[parts[i]] = new Plugin();
}
ns = ns[parts[i]];
}
return ns;
}
var proto = Plugin.prototype;
proto['plugin'] = function(/*path, closure*/) {
var ARGS = Array.prototype.slice.call(arguments);
var Plugins = Array.prototype.slice.call(ARGS);
var closure = Plugins.pop();
var Injectors = frdl.Reflector.getFunctionParameters(closure);
var fnName = frdl.Reflector.getFunctionName(closure);
var vm = require('vm');
function contextify(c){
if('undefined'!==typeof o){
return vm.createContext(c);
}
var context ={
frdl : frdl
};
if('angular'===fnName){
context = frdl.a.module.apply(frdl.a, ARGS);
}else if('config'===fnName){
context = frdl.a.module(mod).config.apply(frdl.a, ARGS);
}else if('run'===fnName){
context = frdl.a.module(mod).run.apply(frdl.a, ARGS);
}else if('inject'===fnName || '$inject'===fnName){
context = frdl.a.injector.apply(frdl.a, ARGS);
}else{
frdl.each(Plugins, function(i,mod){
if('string'!==typeof mod){
context[Injectors[i]]= mod;
}else{
if(!!frdl.strpos(mod, 'exports')){
context[Injectors[i]]=require(mod);
}else if(!!frdl.strpos(mod.toLowerCase(), 'widget')){
context[Injectors[i]]= frdl.UI.getWidget(mod);
}else if('undefined'!==typeof frdl[mod]){
context[Injectors[i]]= frdl[mod];
}else {
context[Injectors[i]]= Use(mod);
}
}
});
}
return vm.createContext(context);
}//contextify
return {
script : vm.createScript(closure,{
compile : 'text/typescript'
}),
contextify : contextify,
run : function(o){
let context = contextify(o);
return script.runInNewContext(context);
}
};
/*
var component = Use(path);
if (closure) {
(function(){
var payload = [];
//exports=>this
closure.apply(component, payload);
}());
}
return component;
*/
};
proto['extend'] = function(component) {
var sym;
for ( sym in component) {
if (component.hasOwnProperty(sym)) {
this[sym] = component[sym];
}
}
};
return proto;
}
|