This repository has been archived by the owner on Jan 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
class.min.js
executable file
·2 lines (2 loc) · 6.42 KB
/
class.min.js
1
2
/*! class.js v0.8.0 https://github.com/tjbutz/class.js | License: https://github.com/tjbutz/class.js/blob/master/LICENSE */
(function(){"use strict";var a=this,b=a._;!b&&typeof require!="undefined"&&(a._=b=require("underscore"));var c=a.Class,d;typeof exports!="undefined"?d=exports:d=a.Class={},d.VERSION="0.8.0",d.root=a,d.useName=!0,d.noConflict=function(){return a.Class=c,this};var e=function(){},f=/\(/g;b.extend(d,{definition:[],define:function(a,c,g){a&&!b.isString(a)&&(b.isFunction(a)?(g=c,c=a):g=a,a=null),c&&!b.isFunction(c)&&(g=c,c=null),d.onBeforeClassDefine&&d.onBeforeClassDefine(c,g);var h=null;g&&g.hasOwnProperty("constructor")&&(h=g.constructor,delete g.constructor);var i=function(){if(!(this instanceof i))throw new Error("Use new keyword to create a new instance or call/apply class with right scope");d.onBeforeInstantiation&&d.onBeforeInstantiation(this);var a=this.__super__;this.__super__=c,h?h.apply(this,arguments):c&&c.apply(this,arguments),this.__super__=a,d.onAfterInstantiation&&d.onAfterInstantiation(this)};if(a&&d.useName)if(!a.match(f))i=(new Function("constructor","return function "+a+"() { constructor.apply(this, arguments); };"))(i);else throw new Error("Wrong name for class: "+a);c&&(e.prototype=c.prototype,i.prototype=new e,i.prototype.constructor=i,i.prototype.__super__=c.prototype);if(g){b.each(this.definition,function(a){b.isUndefined(g[a])||(this[a].call(this,i,g[a]),delete g[a])},this);if(b.keys(g).length!==0)throw new Error("Unknown key in definition: "+b.keys(g).join(", ")+". Allowed keys are: "+this.definition.join(", "))}if(c){var j=i.prototype;for(var a in j){var k=j[a],l=c.prototype[a];b.isFunction(k)&&b.isFunction(l)&&(j[a]=function(a,b){return function(){var a=this.__super__;this.__super__=c.prototype;var d=b.apply(this,arguments);return this.__super__=a,d}}(a,k))}}return i.extend=this._extend,d.onAfterClassDefine&&d.onAfterClassDefine(i),i},_extend:function(a,b){return d.define(a,this,b)}})}).call(this),function(){"use strict";var a=this.Class||exports,b=this._;a.definition.push("namespace"),a.namespace=function(a,c,d){if(b.isString(a)){var e=c;c=a,a=e}c=c.split(".");var f=d||this.root;if(c.length>0){var g=c.pop();b.each(c,function(a){f=f[a]=f[a]||{}}),f[g]=a}return a}}.call(this),function(){"use strict";var a=this.Class||exports,b=this._;a.definition.push("singleton"),a.singleton=function(a,b){b&&(a.$$instance=null,a.getInstance=function(){return this.$$instance||(this.$$instance=new this)})}}.call(this),function(){"use strict";var a=this.Class||exports,b=this._;a.definition.push("statics"),a.statics=function(a,c){b.extend(a,c)}}.call(this),function(){"use strict";var a=this.Class||exports,b=this._;a.ECMA5=!1,a.types={String:b.isString,Number:b.isNumber,Boolean:b.isBoolean,Array:b.isArray,Function:b.isFunction,Object:b.isObject,Element:b.isElement,Date:b.isDate,Regex:b.isRegExp},a.definition.push("properties"),a.properties=function(a,b){for(var e in b)d(a,e,b[e]);var f=a.prototype;f.set=c(""),f._set=c("_")};var c=function(a){return function(c,d){if(b.isString(c)){var f=c;c={},c[f]=d}for(var f in c){var g=e("set",f,a);if(!b.isUndefined(this[g]))h(this,g,c[f]);else throw new Error('No public set method for property "'+f+'" found.')}return this}},d=function(c,d,h){b.isObject(h)||(h={type:h});var i=e("set",d,f("set",h)),k=e("get",d,f("get",h)),m=c.prototype;a.ECMA5?(m.__defineSetter__(i,j(d,h,k,i)),m.__defineGetter__(k,g(d,h,k,i))):(m[i]=j(d,h,k,i),m[k]=g(d,h,k,i));if(h.type==="Boolean"){var n=e("is",d,f(h,"is"));m[n]=l(k)}},e=function(b,c,d){return!a.ECMA5||b==="is"?d+b+p(c):d+c},f=function(a,b){return b[a==="is"?"get":a]===!1?"_":""},g=function(a,c,d,e){return function(){this.$$properties=this.$$properties||{};if(!b.isUndefined(c.init)){var d=c.init;delete c.init,h(this,e,d)}return this.$$properties[a]}},h=function(b,c,d){a.ECMA5?b[c]=d:b[c](d)},i=function(b,c){return a.ECMA5?b[c]:b[c]()},j=function(c,d,e,f){return function(f){var g=i(this,e);if(d.format){var h=k(this,d.format);if(h)f=h.call(this,f,g,c);else throw new Error('Format method "'+d.format+'" for property "'+c+'" not available.')}if(g===f)return;var j=d.type,l=b.isNull(f)&&d.nullable===!0;if(!l&&j){var m=b.isFunction(j)?o:a.types[j];if(!m)throw new Error('Unknown type "'+j+'" for property "'+c+'".');if(!m.call(this,f)){var n='Wrong type for property "'+c+'". Expected value "'+f+'" to be of type "'+j+'" but found: '+typeof f;throw n+=". Allowed keys are: "+b.keys(a.types).join(", "),new a.TypeError(n,c,f,j)}}var p=d.validate;p&&(b.isArray(p)||(p=[p]),b.each(p,function(e){e=k(this,e);if(!e)throw new Error('Validation method "'+d.validate+'" for property "'+c+'" not available.');var h=e.call(this,f,g,c),i=b.isString(h);if(!h||i){var j=i?h:'Validation for property "'+c+'" with value "'+f+'" failed';throw new a.ValidationError(j,c,f)}},this)),this.$$properties[c]=f;if(d.hasOwnProperty("apply")){var q=k(this,d.apply);if(q)q.call(this,f,g,c);else throw new Error('Apply method "'+d.apply+'" for property "'+c+'" not available.')}if(d.event){var r=this.trigger||this.emit;if(r)r.call(this,d.event,{target:this,value:f,old:g,property:c});else throw new Error("Object does not support events")}return f}},k=function(a,c){return b.isString(c)?a[c]:c},l=function(a){return function(){return i(this,a)}},m=a.ValidationError=a.define("ValidationError",Error,{constructor:function(a,b,c){this.name="ValidationError",this.message=a||"Validation Error",this.property=b,this.value=c}}),n=a.TypeError=m.extend("TypeError",{constructor:function(a,b,c,d){m.apply(this,arguments),this.name="TypeError",this.message=a||"Type Error",this.type=d}}),o=function(a){return this instanceof a},p=function(a){return a.charAt(0).toUpperCase()+a.substring(1)}}.call(this),function(){"use strict";var a=this.Class||exports,b=this._;a.definition.push("mixins"),a.mixins=function(a,c){b.each(c,function(c){var c=b.isFunction(c)?c.prototype:c;b.extend(a.prototype,c)})}}.call(this),function(){"use strict";var a=this.Class||exports,b=this._;a.definition.push("members"),a.members=function(a,c){b.extend(a.prototype,c)}}.call(this),function(){"use strict";var a=this.Class||exports,b=this._;a.definition.push("interfaces"),a.interfaces=function(a,d){b.each(d,function(d){var d=b.isFunction(d)?d.prototype:d;for(var e in d){var f=a.prototype[e];if(b.isUndefined(f)||!b.isFunction(f))throw new Error('The Class does not implement the interface method "'+f+'"');b.isFunction(d[e])&&(a.prototype[e]=c(d[e],f))}})};var c=function(a,b){return function(){return a.apply(this,arguments),b.apply(this,arguments)}}}.call(this);