UNPKG

esf-core

Version:

EsFramework Javascript core. Contains simple classloader, heavily inspired by ExtJs

31 lines (29 loc) 10.3 kB
/** * almond 0.2.3 Copyright (c) 2011-2012, The Dojo Foundation All Rights Reserved. * Available via the MIT or new BSD license. * see: http://github.com/jrburke/almond for details */ /** * Copyright 2012 jQuery Foundation and other contributors * http://jquery.com/ * * 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: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * 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. */ (function(){var e,t,n;(function(r){function d(e,t){return h.call(e,t)}function v(e,t){var n,r,i,s,o,u,a,f,c,h,p=t&&t.split("/"),d=l.map,v=d&&d["*"]||{};if(e&&e.charAt(0)===".")if(t){p=p.slice(0,p.length-1),e=p.concat(e.split("/"));for(f=0;f<e.length;f+=1){h=e[f];if(h===".")e.splice(f,1),f-=1;else if(h===".."){if(f===1&&(e[2]===".."||e[0]===".."))break;f>0&&(e.splice(f-1,2),f-=2)}}e=e.join("/")}else e.indexOf("./")===0&&(e=e.substring(2));if((p||v)&&d){n=e.split("/");for(f=n.length;f>0;f-=1){r=n.slice(0,f).join("/");if(p)for(c=p.length;c>0;c-=1){i=d[p.slice(0,c).join("/")];if(i){i=i[r];if(i){s=i,o=f;break}}}if(s)break;!u&&v&&v[r]&&(u=v[r],a=f)}!s&&u&&(s=u,o=a),s&&(n.splice(0,o,s),e=n.join("/"))}return e}function m(e,t){return function(){return s.apply(r,p.call(arguments,0).concat([e,t]))}}function g(e){return function(t){return v(t,e)}}function y(e){return function(t){a[e]=t}}function b(e){if(d(f,e)){var t=f[e];delete f[e],c[e]=!0,i.apply(r,t)}if(!d(a,e)&&!d(c,e))throw new Error("No "+e);return a[e]}function w(e){var t,n=e?e.indexOf("!"):-1;return n>-1&&(t=e.substring(0,n),e=e.substring(n+1,e.length)),[t,e]}function E(e){return function(){return l&&l.config&&l.config[e]||{}}}var i,s,o,u,a={},f={},l={},c={},h=Object.prototype.hasOwnProperty,p=[].slice;o=function(e,t){var n,r=w(e),i=r[0];return e=r[1],i&&(i=v(i,t),n=b(i)),i?n&&n.normalize?e=n.normalize(e,g(t)):e=v(e,t):(e=v(e,t),r=w(e),i=r[0],e=r[1],i&&(n=b(i))),{f:i?i+"!"+e:e,n:e,pr:i,p:n}},u={require:function(e){return m(e)},exports:function(e){var t=a[e];return typeof t!="undefined"?t:a[e]={}},module:function(e){return{id:e,uri:"",exports:a[e],config:E(e)}}},i=function(e,t,n,i){var s,l,h,p,v,g=[],w;i=i||e;if(typeof n=="function"){t=!t.length&&n.length?["require","exports","module"]:t;for(v=0;v<t.length;v+=1){p=o(t[v],i),l=p.f;if(l==="require")g[v]=u.require(e);else if(l==="exports")g[v]=u.exports(e),w=!0;else if(l==="module")s=g[v]=u.module(e);else if(d(a,l)||d(f,l)||d(c,l))g[v]=b(l);else{if(!p.p)throw new Error(e+" missing "+l);p.p.load(p.n,m(i,!0),y(l),{}),g[v]=a[l]}}h=n.apply(a[e],g);if(e)if(s&&s.exports!==r&&s.exports!==a[e])a[e]=s.exports;else if(h!==r||!w)a[e]=h}else e&&(a[e]=n)},e=t=s=function(e,t,n,a,f){return typeof e=="string"?u[e]?u[e](t):b(o(e,t).f):(e.splice||(l=e,t.splice?(e=t,t=n,n=null):e=r),t=t||function(){},typeof n=="function"&&(n=a,a=f),a?i(r,e,t,n):setTimeout(function(){i(r,e,t,n)},15),s)},s.config=function(e){return l=e,s},n=function(e,t,n){t.splice||(n=t,t=[]),!d(a,e)&&!d(f,e)&&(f[e]=[e,t,n])},n.amd={jQuery:!0}})(),n("node_modules/almond/almond.js",function(){}),function(){var e=this,n={create:function(e){var t=this.getConstructor(e);return n.override(t,e),t},extend:function(e,t){var r=this.getConstructor(t,e.prototype.constructor),i=function(){};return i.prototype=e.prototype,r.prototype=new i,r.prototype.constructor=t.hasOwnProperty("constructor")?t.constructor:function(){},r.prototype.superClass=e,r.prototype.callParent=function(){var e=r;while(e.prototype[this.callParent.caller.$name]!==this.callParent.caller)e=e.prototype.superClass;e=e.prototype.superClass;if(typeof e=="undefined"){var t=r;while(t.prototype[this.callParent.caller.$name]!==this.callParent.caller)t=t.prototype.superClass;throw"Parent method ("+this.callParent.caller.$name+") cant be called from "+t.prototype.$name+" because it hasn't a mother class"}if(typeof e.prototype[this.callParent.caller.$name]=="undefined")throw"Parent method ("+this.callParent.caller.$name+") is not defined in "+this.$name;return e.prototype[this.callParent.caller.$name].apply(this,arguments)},t&&n.override(r,t),r},getConstructor:function(e,t){return function(){for(var n in this)typeof this[n]=="object"&&(this[n]=r(!0,e[n]instanceof Array?[]:{},this[n]));return e.hasOwnProperty("constructor")?e.constructor.apply(this,arguments):typeof t!="undefined"?t.apply(this,arguments):this}},override:function(e,t){if(typeof t!="object"||!t)throw new TypeError("Object needed as source.");for(var n in t)t.hasOwnProperty(n)&&(typeof t[n]=="function"&&(t[n].$name=n),e.prototype[n]=t[n])}},r=function(){var e,t,n,i,s,o,u=arguments[0]||{},a=1,f=arguments.length,l=!1,c=Object.prototype.toString,h=Object.prototype.hasOwnProperty,p=Array.prototype.push,d=Array.prototype.slice,v=String.prototype.trim,m=Array.prototype.indexOf,g={"[object Boolean]":"boolean","[object Number]":"number","[object String]":"string","[object Function]":"function","[object Array]":"array","[object Date]":"date","[object RegExp]":"regexp","[object Object]":"object"},y={isFunction:function(e){return y.type(e)==="function"},isArray:Array.isArray||function(e){return y.type(e)==="array"},isWindow:function(e){return e!=null&&e==e.window},isNumeric:function(e){return!isNaN(parseFloat(e))&&isFinite(e)},type:function(e){return e==null?String(e):g[c.call(e)]||"object"},isPlainObject:function(e){if(!e||y.type(e)!=="object"||e.nodeType)return!1;try{if(e.constructor&&!h.call(e,"constructor")&&!h.call(e.constructor.prototype,"isPrototypeOf"))return!1}catch(t){return!1}var n;for(n in e);return n===undefined||h.call(e,n)}};typeof u=="boolean"&&(l=u,u=arguments[1]||{},a=2),typeof u!="object"&&!y.isFunction(u)&&(u={}),f===a&&(u=this,--a);for(a;a<f;a++)if((e=arguments[a])!=null)for(t in e){n=u[t],i=e[t];if(u===i)continue;l&&i&&(y.isPlainObject(i)||(s=y.isArray(i)))?(s?(s=!1,o=n&&y.isArray(n)?n:[]):o=n&&y.isPlainObject(n)?n:{},u[t]=r(l,o,i)):i!==undefined&&(u[t]=i)}return u};module.exports=new(n.create({classes:{},instantiators:[],tags:{},singletons:{},tagFilter:{},_ns:"Esf",create:function(e){if(!this.instantiators[arguments.length]){var t=[];for(i=1;i<arguments.length;i++)t.push("a["+i+"]");this.instantiators[arguments.length]=new Function("cls","a","return new cls("+t.join(",")+")")}if(typeof e!="function"){if(!this.classes[e]&&!this.getClass(e))throw"Can not create undefined class "+e;if(typeof this.classes[e].loaded!="undefined"||this.classes[e].loaded==0)throw"Can not create class with unloaded dependencies"}return this.instantiators[arguments.length](typeof e=="function"?e:this.classes[e]||this.getClass(e),arguments)},define:function(r,i,s){typeof r=="object"&&(s=i,i=r,r=!1),typeof s=="undefined"&&(s={}),typeof i=="function"&&(i=i());var o=typeof s.singleton!="undefined"&&s.singleton==1,u=typeof s.extend=="string",a,f=this,l=arguments;if(u){if(!this.getClass(s.extend)){if(!this.Loader||!this.Loader.hasClass(s.extend)||!r)throw new Error("Superclass `"+s.extend+"` of "+(r||"private class")+" not found");this.Loader.require(s.extend,function(){f.define.apply(f,l)})}a=n.extend(this.getClass(s.extend),i)}else a=n.create(i);r&&(a.prototype.$name=r),o&&(a.prototype.$singleton=!0),r&&s.extend==r&&(a.prototype.$overridden=typeof (a.prototype.$overridden=="undefined")?0:++a.prototype.$overridden);if(typeof s.deps!="undefined"){if(!this.Loader)throw"Can not define class with deps without initialized loader";a.prototype.deps={},this.Loader.npm.require(s.deps,a.prototype.deps)}if(o){if(!r)throw new Error("Can not create singleton for private class");this.loader?this.loader.on("load",function(e){if(e==r)return f.singletons[r]=this.create(a),!1}):this.singletons[r]=this.create(a)}if(r){var c=r.split("."),h=e;c[0]==this._ns&&(c.shift(),h=this);for(var p=0;p<c.length-1;p++)typeof h[c[p]]=="undefined"&&(h[c[p]]={}),h=h[c[p]];h[c[c.length-1]]=o?this.singletons[r]:a}if(typeof s.tags!="undefined")for(var d in s.tags){var v;if(typeof s.tags[d]=="object"){v=s.tags[d].name;var m=t("es-hash")(s.tags[d]);typeof this.tagFilter[m]=="undefined"&&(this.tagFilter[m]=[]),this.tagFilter[m].push(o?this.singletons[r]:a)}else v=s.tags[d];typeof this.tags[v]=="undefined"&&(this.tags[v]=[]),this.tags[v].push(o?this.singletons[r]:a)}return r&&(this.classes[r]=a),r?this:a},apply:function(){return r.apply(this,arguments)},findTaggedClasses:function(e,n){if(typeof n!="undefined"){n.name=e;var r=t("es-hash")(n);return typeof this.tagFilter[r]=="undefined"?[]:this.tagFilter[r]}return typeof this.tags[e]=="undefined"?[]:this.tags[e]},alias:function(e,t){if(typeof e=="string"){e=this.getSingleton(e);if(!e)throw"Class ("+e+") not found"}return function(){e[t].apply(e,arguments)}},isSingleton:function(e){var t=this.getClass(e);return t&&t.prototype.singleton},getSingleton:function(e){return typeof this.singletons[e]=="undefined"?!1:this.singletons[e]},getClass:function(t){if(typeof this.classes[t]!="undefined")return this.classes[t];var n=t.split("."),r=e;for(var i=0;i<n.length-1;i++){if(typeof r[n[i]]=="undefined"){r={};break}r=r[n[i]]}if(typeof r[n[n.length-1]]=="function")return this.classes[t]=r[n[n.length-1]];if(this.Loader&&this.Loader.isAutoloaded(t)){this.Loader.require(t);if(typeof this.classes[t]!="undefined")return this.classes[t]}return!1},Loader:!1,globalize:function(){e.Esf=this}}))}(),n("esf-core",function(){})})();