UNPKG

framework-factory

Version:

A wonderful factory framwork for creating modern object oriented javascript libraries.

47 lines 10.1 kB
/** * ______ _ ______ _ * | ___| | | | ___| | | * | |_ _ __ __ _ _ __ ___ _____ _____ _ __| | __ | |_ __ _ ___| |_ ___ _ __ _ _ * | _| '__/ _` | '_ ` _ \ / _ \ \ /\ / / _ \| '__| |/ / | _/ _` |/ __| __/ _ \| '__| | | | * | | | | | (_| | | | | | | __/\ V V / (_) | | | < | || (_| | (__| || (_) | | | |_| | * \_| |_| \__,_|_| |_| |_|\___| \_/\_/ \___/|_| |_|\_\ \_| \__,_|\___|\__\___/|_| \__, | * __/ | * |___/ * * version: 1.2.1 * Framework Factory - A JavaScript factory framework for developing class libraries, * apps and frameworks * http://www.framework-factory.com * * * Architect and Lead Developer: Mohamed Aamir Maniar * Twitter: @aamironline * Facebook: http://www.facebook.com/aamironline * * http://www.maniartech.com * Twitter: @maniartech * * Copyright (c) 2011-2017 Maniar Technologies Private Limited (India) * * 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(a,b){"use strict";var c;(function(a,b){function d(a){var d,e,f,g,h,i,j={},k=c.plugins.toArray();if("string"==typeof a)j.name=a,j.version="1.0.0",d={};else{a=a||{},j.name=a.name||"framework",j.version=a.version||"1.0.0",d=j.root||{};for(g in a)!0===a.hasOwnProperty(g)&&g in j==!1&&(j[g]=a[g])}for(d.version=j.version,d.name=j.name,d.environment=c.environment,d.config=function(a,c){return j[a]!==b?j[a]:c},d.config.set=function(){var a,b=arguments[0];if(1===arguments.length&&"object"==typeof b)for(a in b)!0===b.hasOwnProperty(a)&&(j[a]=b[a]);else 2===arguments.length&&(j[arguments[0]]=arguments[1])},h=0,i=k.length;h<i;h+=1){if(e=k[h],f=e.info?e.info.name:e.name,d[f]!==b)throw new Error('Plugin with the name "'+f+'" already loaded.');"function"==typeof e?e(d):"object"==typeof e&&e.load(d,c)}return d}c=function(){return new function(){}}(),c.version="1.1.0",c.create=function(a){return d(a)}})(),c.plugins=function(){function a(){}var c=[];return a.prototype={register:function(a){var d=a.info?a.info.name:a.name;if("function"==typeof a||"object"==typeof a){if(d===b)throw new Error("Missing plugin name.");return void c.push(a)}throw new Error("Invalid plugin type.")},getNames:function(){var a,b,d,e=[];for(b=0,d=c.length;b<d;b+=1)a=c[b],e.push(a.name);return e},toArray:function(){return c.slice()}},new a}(),c.typeHandlers=function(){function a(){}var b={};return a.prototype={register:function(a){if("object"==typeof a)return void(b[a.typeHandler]=a);throw new Error("Invalid typeHandler.")},get:function(a){return b[a]},getTypeHandlers:function(){var a,c=[];for(a in b)b.hasOwnProperty(a)&&c.push(a);return c}},new a}(),function(a,b){function d(a,c){var d={func:function(a){return"function"==typeof a||a instanceof Function==!0},string:function(a){return"string"==typeof a||a instanceof String==!0},number:function(a){return"number"==typeof a||a instanceof Number==!0},primitive:function(a){return d.string(a)||d.number(a)},undef:function(a){return a===b},nullOrUndef:function(a){return a===b||null===a},date:function(a){return a instanceof Date==!0},regExp:function(a){return a instanceof RegExp==!0},plainObject:function(a){return a!==b&&null!==a&&("object"==typeof a&&a.constructor===Object)},concreteObject:function(a){return!1===(d.primitive(a)||d.date(a)||d.regExp(a)||d.nullOrUndef(a)||d.array(a))},array:function(a){return a instanceof Array},inBrowser:function(){return a.environment.browser}};d.name="is",a.is=d}c.plugins.register({name:"is",load:d})}(),function(a,b){function d(a){function d(a,b){for(var c in b)Object.prototype.hasOwnProperty.call(b,c)&&(a[c]=b[c]);return a.prototype=Object.create(b.prototype),a.prototype.constructor=a,a.prototype}function e(a){var b,d,e,f=c.typeHandlers.getTypeHandlers();for(d=0,e=f.length;d<e;d+=1)b=c.typeHandlers.get(f[d]),b.setup&&b.setup(a)}var f,g=/xyz/.test(function(){xyz})?/\bbase\b/:/.*/,h=a.config("defaultBaseClass"),i=a.config("requireNew",!1);f=function(j,k){function l(c){var d=Object.keys(q);return!c&&a.is.func(k.getMemberNames)&&(d=d.concat(k.getMemberNames())),d.sort().filter(function(a,c,d){return a!==b&&(!c||a!=d[c-1])})}function m(b){return b in q?q[b]:a.is.func(k.getMember)?k.getMember(b):void 0}function n(a){var c=l(a),d=0,e=c.length,f=null,g={functions:[],others:[]};for(d=0;d<e;d+=1)f=m(c[d]),wd.is.func(f)?g.functions.push(f):f.typeHandler!==b?(g[f.typeHandler]=g[f.typeHandler]||[],g[f.typeHandler].push(f)):g.others.push(f);return g}var o,p,q={},r=Object.create,s=Object.prototype.hasOwnProperty;return k=a[h]!==b?k||a[h]:k||Object,j=j||{},p=i?function(){if(this instanceof p==!1)throw new Error("constructorFn used as function.");this.init!==b&&this.init.apply(this,arguments)}:function(){var a=null;if(this instanceof p==!1)return a=r(p.prototype),a.init!==b&&a.init.apply(a,arguments),a;this.init!==b&&this.init.apply(this,arguments)},o=d(p,k),p.attach=function(d){var e,f,h,i,j,l;for(j in d)s.call(d,j)&&(e=d[j],f=typeof e,h=e,i=!1,a.is.plainObject(e)?(l=c.typeHandlers.get(e.typeHandler))!==b&&l.handler!==b&&(e.name=j,e.tag=e.tag===b?null:e.tag,l.handler(p,j,e),i=!0):"function"===f&&"function"==typeof k.prototype[j]&&g.test(e)&&(o[j]=function(a,c){var d=k;return function(){this.base=d.prototype[a];var e=c.apply(this,arguments);return this.base=b,e}}(j,e),i=!0),i||(o[j]=h)),q[j]=e},p.extend=function(a){return f(a,p)},e(p),p.attach(j),p.getMember=function(a){return m(a)},p.getMemberNames=function(a){return l(a)},p.getMembers=function(a){return n(a)},p},a.Class=function(){return f.apply(null,arguments)}}c.plugins.register({name:"classes",load:d})}(),function(a,b){function d(a){function d(a,c,d,e){if(e=e||function(){throw new Error('Cannot assign to readonly property "'+c+'".')},Object.defineProperty)Object.defineProperty(a,c,{enumerable:!0,configurable:!0,get:d,set:e});else{if(a.__defineGetter__===b)throw new Error("Properties are not supported in current environment.");a.__defineGetter__(c,d),a.__defineSetter__(c,e)}}function e(a,b,c){d(a,b,c)}var f,g,h;f=function(b,c){var d,e;return a.is.plainObject(b)?(e=b.default,a.is.func(b.get)&&(d=b.get)):e=b,c=c||{},{typeHandler:"readonlies",default:e,readonly:!0,get:d,tag:c}},g=function(b,c){var d,e,g;if(a.is.plainObject(b)){if(d=b.default,e=b.get,g=b.set,e&&!g)return f(b)}else d=b;return c=c||{},{typeHandler:"properties",readonly:!1,default:d,get:e,set:g,tag:c}},h=function(a,c,e){var f,g,h=a.prototype,i=e.readonly,j=e.get,k=e.set,l="_"+c,m=e.default;e.name=c,i?j!==b?f=j:(f=function(){return this[l]},e.get=f):(f=j||function(){return this[l]},g=k||function(a){this[l]=a},e.get=f,e.set=g),m!==b&&(h[l]=m),d(h,c,f,g)},a.attachProperty=d,a.attachReadonly=e,a.property=g,a.readonly=f,c.typeHandlers.register({typeHandler:"properties",handler:h}),c.typeHandlers.register({typeHandler:"readonlies",handler:h})}c.plugins.register({name:"properties",load:d})}(),function(a,b){function d(a){var b=function(a,b){return{typeHandler:"attributes",default:a,tag:b}};a.attribute=b,a.attr=b,c.typeHandlers.register({typeHandler:"attributes",handler:function(a,b,c){a.prototype[b]=c.default}})}c.plugins.register({name:"attributes",load:d})}(),function(a,b){function d(a){a.event=function(a){return{typeHandler:"events",tag:a}},c.typeHandlers.register({typeHandler:"events",setup:function(c){var d=c.prototype;d.on=function(c,d){var e,f,g,h,i=c.toLowerCase().split(" ");if(h=this._events=this._events||{_names:[]},!a.is.func(d))throw new Error("Invalid handler!");for(e=0,f=i.length;e<f;e+=1)g=i[e].trim(),h[g]===b&&(h[g]=[],h._names.push(g)),h[g].push(d);return this},d.trigger=function(a,c,d){var e,f,g;if(!this._events)return this;if(a=a.toLowerCase(),(e=this._events[a])===b||0===e.length)return this;for(c=c||{},c.eventName=a,g=0;g<e.length&&(f=e[g],!1!==f.call(d||this,c));g+=1);return this},d.off=function(a,c){var d,e;return a=a.toLowerCase(),(d=this._events[a])===b?this:(c===b?d.length=0:-1!==(e=d.indexOf(c))&&d.splice(e,1),0==d.length&&(e=this._events._names.indexOf(a),-1!=e&&this._events._names.splice(e,1),delete this._events[a]),0===this._events._names.length&&delete this._events,this)},d.unsubscribeAll=function(){for(var a=this._events._names;a.length>0;)this.off(a[0]);return this},d.subscribers=function(a){return this._events?this._events[a.toLowerCase()]||[]:[]}},handler:function(a,b,c){var d=a.prototype;c.name=b,d[b]=function(a){return this.on(b,a),this},d[b].event=!0}})}c.plugins.register({name:"events",load:d})}(),function(a,b){function d(a){var b=function(a){return{typeHandler:"callbacks"}};a.callback=b,c.typeHandlers.register({typeHandler:"callbacks",handler:function(a,b,c){a.prototype[b]=null,c.name=b}})}c.plugins.register({name:"callbacks",load:d})}(),"undefined"!=typeof module&&"object"==typeof module.exports?module.exports=c:"undefined"!=typeof define&&"object"==typeof define.amd?define(function(){return c}):a.FrameworkFactory=c}(this);