Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge remote-tracking branch 'origin/dev'

  • Loading branch information...
commit f3e0bb3c896f7d1f64898b41512e724096440351 2 parents 2f5195b + 969f016
@melechi melechi authored
View
56 bin/jskk.min-1.0.1.js
@@ -0,0 +1,56 @@
+Object.extend=function(a,c){if(Object.isAssocArray(c)){if(a==null||Object.isUndefined(a))a={};for(var b in c)if(Object.isAssocArray(c)){if(Object.isUndefined(a[b])||a[b]==null||a[b]==false)a[b]={};a[b]=Object.extend(a[b],c[b])}else a[b]=Object.isArray(c[b])?Object.extend(a[b],c[b]):c[b];delete b}else if(Object.isArray(c)){Object.isArray(a)||(a=[]);b=0;for(var d=c.length;b<d;b++)a[b]=Object.extend(a[b],c[b]);delete b}else a=c;return a};Object.clone=function(a){var c={};return c=Object.extend(c,a)};
+Object.isUndefined=function(a){return typeof a=="undefined"};Object.isDefined=function(a){return typeof a!="undefined"};Object.isFunction=function(a){return typeof a=="function"};Object.isString=function(a){return typeof a=="string"};Object.isNumber=function(a){return typeof a=="number"};Object.isNumeric=function(a){return a!=""&&Object.prototype.toString.call(a)!=="[object Array]"&&!isNaN(Number(a))};Object.isElement=function(a){return a&&a.nodeType==1};
+Object.isArray=function(a){return Object.prototype.toString.call(a)==="[object Array]"};Object.isDate=function(a){return Object.prototype.toString.call(a)==="[object Date]"};Object.isNull=function(a){return a===null};Object.isAssocArray=function(a){return Object.prototype.toString.call(a)==="[object Object]"};Object.isBoolean=function(a){return typeof a=="boolean"};
+Object.isEmpty=function(a,c){if(!a||Object.isUndefined(a)||Object.isNull(a)||Object.isArray(a)&&a.length===0||Object.isString(a)&&(a.trim()===""||a==="0")||Object.isNumber(a&&a===0))return true;else if(c&&/^(\t*)|(\v*)|(\s*)$/.test(a))return true;return false};Object.toQueryString=function(a){if(this.isString(a))return a;var c="",b;for(b in a)!this.isFunction(a[b])&&typeof a[b]!="object"&&(c+=encodeURIComponent(b)+"="+encodeURIComponent(a[b])+"&");return c};
+Object.toIndexedArray=function(a){var c=[],b;for(b in a)c.push(a[b]);return c};Object.toArray=function(a){if(Object.isArray(a))return a;if(Object.isString(a))return a.split("");else if(!Object.isNumber(a)&&Object.isAssocArray(a)){var c=[];if(Object.isIndexed(a))for(item in a)Object.isNumber(item)&&(c[item]=a[item]);else{var b=-1;for(item in a)b++,Object.isNumber(item)&&Object.isDefined(c[b])?(c[b+1]=c[b],c[b]=a[item],b++):c[b]=a[item]}return c}return[a]};
+Object.isIndexed=function(a){if(Object.isAssocArray(a)){var c=false,b;for(b in a)if(c=true,!Object.isNumeric(b))return false;return c}return false};Object.ifSetOr=function(a,c){return Object.isDefined(a)?a:c||null};
+Object.isEqual=function(a,c){var b;if(typeof a!=typeof c)return false;for(b in a)if(typeof c[b]=="undefined")return false;for(b in a)if(a[b])switch(typeof a[b]){case "object":if(!Object.isEqual(a[b],c[b]))return false;break;case "function":if(typeof c[b]=="undefined"||a[b].toString()!=c[b].toString())return false;break;default:if(a[b]!=c[b])return false}else if(c[b])return false;for(b in c)if(typeof a[b]=="undefined")return false;return true};
+Object.extend(Function.prototype,{bind:function(){if(arguments.length<2&&typeof arguments[0]=="undefined")return this;var b=this,a=$JSKK.toArray(arguments),c=a.shift();return function(){return b.apply(c,a.concat($JSKK.toArray(arguments)))}},curry:function(){if(!arguments.length)return this;var b=this,a=$JSKK.toArray(arguments);return function(){return b.apply(this,a.concat($JSKK.toArray(arguments)))}},intercept:function(){if(!(arguments.length<1&&typeof arguments[0]!="function")){var b=this,a=$JSKK.toArray(arguments),
+c=a.shift();return function(){c.apply(this,a.concat($JSKK.toArray(arguments)));return b.apply(this,a.concat($JSKK.toArray(arguments)))}}},join:function(){if(!(arguments.length<1&&typeof arguments[0]!="function")){var b=this,a=$JSKK.toArray(arguments),c=a.shift();return function(){b.apply(this,a.concat($JSKK.toArray(arguments)));return c.apply(this,a.concat($JSKK.toArray(arguments)))}}},sequencedJoin:function(){if(!(arguments.length<1&&typeof arguments[0]!="function")){var b=this,a=$JSKK.toArray(arguments),
+c=a.shift();return function(){var d=b.apply(this,a.concat($JSKK.toArray(arguments)));return Object.isNull(d)?null:Object.isAssocArray(d)&&Object.isDefined(d.args)?c.apply(this,d.args):c.call(this,d)}}},defer:function(){var b=this,a=$JSKK.toArray(arguments),c=a.shift(),d=a.shift(),e=a.shift();Object.isArray(e)||(e=[e]);window.setTimeout(function(){b.apply(d,e)},c)},delay:function(){arguments[0]*=1E3;this.defer.apply(this,arguments)}});
+var $break={};
+Object.extend(Array.prototype,{_each:function(b){for(var a=0,c=this.length;a<c;a++)b(this[a])},each:function(b){var a=0;try{this._each(function(c){b(c,a++)})}catch(c){if(c!=$break)throw c;}return this},find:function(b){var a;this.each(function(c,d){if(b(c,d))throw a=c,$break;});return a},findAll:function(b){var a=[];this.each(function(c,d){b(c,d)&&a.push(c)});return a},first:function(){return this[0]},last:function(){return this[this.length-1]},inArray:function(b){return this.find(function(a){return b==a?
+true:false})!=void 0?true:false},without:function(){if(Object.isArray(arguments[0])){var b=$JSKK.toArray(arguments[0]);return this.findAll(function(a){return!b.include(a)})}else return b=$JSKK.toArray(arguments),this.findAll(function(a){return!b.include(a)})},min:function(){return Math.min.apply(this,this)},max:function(){return Math.max.apply(this,this)},sum:function(){for(var b=0,a=0,c=this.length;a<c;a++)b+=Number(this[a]);return b},average:function(){return this.sum()/this.length}});
+Object.extend(String.prototype,{nl2br:function(){return this.replace(/[\r\n\f]/g,"<br />")},trim:function(){for(var a=this.replace(/^\s\s*/,""),b=/\s/,e=a.length;b.test(a.charAt(--e)););return a.slice(0,e+1)},toQueryParams:function(a){var b=this.trim().match(/([^?#]*)(#.*)?$/);return!b?{}:b[1].split(a||"&").inject({},function(a,b){if((b=b.split("="))[0]){var c=decodeURIComponent(b.shift()),d=b.length>1?b.join("="):b[0];Object.isUndefined(d)||(d=decodeURIComponent(d));c in a?(Object.isArray(a[c])||
+(a[c]=[a[c]]),a[c].push(d)):a[c]=d}return a})},ellipse:function(a){return this.length>a?this.substr(0,a-3)+"...":this},lowerFirst:function(){var a=this.substring(0,1),b=this.substring(1);return a.toLowerCase()+b}});
+var $JSKK={version:"1.0.0",emptyFunction:function(){},namespace:function(){var a=/^(?:[\$a-zA-Z_]\w*[.])*[\$a-zA-Z_]\w*$/;return function(c,f){var b;b=c;var e=f||window,h;if(Object.isString(b)){var d,g;if(!a.test(b))throw Error('"'+b+'" is not a valid name for a package.');d=e;g=b.split(".");e=0;for(h=g.length;e<h;e++)b=g[e],d[b]=d[b]||{},d=d[b]}else throw new TypeError;return d}}(),usingPackage:function(){var a=arguments;return function(c){return c.apply(a[0],a)}},toArray:function(a){if(!a)return[];
+if(!(typeof a=="function"&&a=="[object NodeList]")&&a.toArray)return a.toArray();for(var c=a.length||0,f=Array(c);c--;)f[c]=a[c];return f}};if(Object.isUndefined(window.console))window.console={log:$JSKK.emptyFunction,debug:$JSKK.emptyFunction};else if(Object.isUndefined(window.console.debug))window.console.debug=window.console.log;
+$JSKK.Interface={create:function(a){if(Object.isString(a)){var e=window,d=a,c={};c.$name=a;c.$namespace="window";a=c}else if(Object.isUndefined(a.$name))throw Error("Interface name must be defined.");else d=a.$name,Object.isUndefined(a.$namespace)?(a.$namespace="window",e=window):e=$JSKK.namespace(a.$namespace);e[d]=function(){throw['Interface "'+d+'" cannot be initiated because interfaces'," are abstract classes which cannot be directly initiated."].join("");};a.$type="interface";e[d].prototype.$reflect=
+function(b){switch(b){case "type":return a.$type;case "namespace":return a.$namespace;case "name":return a.$name;case "extends":return a.$extends;case "implements":return a.$implements}};return function(b){if(!Object.isUndefined(a.$extends))if(a.$extends.definition.$type=="trait")throw Error("Interfaces cannot extend Traits.");else if(a.$extends.definition.$type=="class")throw Error("Interfaces cannot extend Classes.");else e[d].prototype=Object.extend(e[d].prototype,a.$extends.prototype);if(!Object.isUndefined(a.$implements))throw Error("Interfaces cannot implement other Interfaces. Interfaces can only extend other Interfaces.");
+for(var c in b)if(Object.isFunction(b[c])&&b[c]!=$JSKK.Interface.METHOD)throw Error("Interfaces may only contain empty functions. Use $JSKK.Interface.METHOD.");else e[d].prototype[c]=b[c]}},PROPERTY:function(){},METHOD:function(){},validate:function(a){if(Object.isUndefined(a))throw Error("Unable to implement interface. Interface to implement is undefined.");else if(a.$type=="class")throw Error(['Unable to implement interface. Interface to implement is a "$JSKK.Class".',' An interface must be a "$JSKK.Interface".']);
+else if(a.$type=="trait")throw Error(['Unable to implement interface. Interface to implement is a "$JSKK.Trait".',' An interface must be a "$JSKK.Interface".']);else if(a.$type=="interface")throw Error('Unable to implement interface. Interface to implement is not an instance of "$JSKK.Interface".');return true},add:function(a,e,d,c){for(var b in c.prototype)if(b!="interfaceName"){if(c.prototype[b]==$JSKK.Interface.METHOD&&!Object.isFunction(e[b])&&(!d||!Object.isFunction(d.prototype[b])))throw Error(['The implementation of interface "'+
+c.prototype.interfaceName+'" requires',' the method "'+b+'" be implemented.'].join(""));a.prototype[b]=Object.isAssocArray(c.prototype[b])?Object.clone(c.prototype[b]):c.prototype[b]}}};
+$JSKK.Trait={create:function(a){if(typeof a=="string"){var e=window,b=a,d={};d.$name=a;d.$namespace="window";a=d}else if(typeof a.$name=="undefined")throw Error("Trait name must be defined.");else b=a.$name,typeof a.$namespace=="undefined"?(a.$namespace="window",e=window):e=$JSKK.namespace(a.$namespace);e[b]=function(){throw['Trait "'+b+'" cannot be initiated because traits'," are abstract classes which cannot be directly initiated."].join("");};a.$type="trait";e[b].prototype.$reflect=function(b){switch(b){case "type":return a.$type;
+case "namespace":return a.$namespace;case "name":return a.$name;case "extends":return a.$extends;case "implements":return a.$implements;case "uses":return a.$uses}};return function(d){var g=false;if(!Object.isUndefined(a.$uses)){if(!Object.isArray(a.$uses))a.$uses=[a.$uses];g=$JSKK.Trait.normalize(a.$uses,true)}if(!Object.isUndefined(a.$implements)){if(!Object.isArray(a.$implements))a.$implements=[a.$implements];for(var f=0,h=a.$implements.length;f<h;f++)$JSKK.Interface.validate(a.$implements[f])&&
+$JSKK.Interface.add(e[b],d,g,a.$implements[f])}Object.isUndefined(a.$uses)||$JSKK.Trait.validate(g)&&$JSKK.Trait.add(e[b],g);delete g;for(var c in d)if(typeof d[c]!="function")throw Error("A trait may only contain methods.");else e[b].prototype[c]=d[c]}},normalize:function(a,e){Object.isArray(a)||(a=[a]);var b={};Object.isFunction(a[a.length-1])||(b=a[a.length-1],delete a[a.length-1]);var d=function(){};d.prototype.traitName="Normalized";for(var i=[],g=[],f=0,h=a.length;f<h;f++)if(Object.isFunction(a[f]))for(var c in a[f].prototype)if(Object.isFunction(a[f].prototype[c])&&
+(c!="init"||e))i.inArray(c)?g.inArray(c)||(Object.isUndefined(b[c])?delete d.prototype[c]:d.prototype[c]=b[c].prototype[c],g.push(c)):(i.push(c),d.prototype[c]=a[f].prototype[c]);return d},validate:function(a){if(Object.isUndefined(a))throw Error("Unable to add trait. Trait to add is undefined.");else if(Object.isUndefined(a.prototype.className))if(Object.isUndefined(a.prototype.instanceName)){if(Object.isUndefined(a.prototype.traitName))throw Error('Unable to add trait. Trait to add is not an instance of "$JSKK.Trait".');
+}else throw Error(['Unable to add trait. Trait to add is an instance of "$JSKK.Interface".',' A trait must be an instance of "$JSKK.Trait".']);else throw Error(['Unable to add trait. Trait to add is an instance of "$JSKK.Class".',' A trait must be an instance of "$JSKK.Trait".']);return true},add:function(a,e){for(var b in e.prototype)if(b!="traitName"){if(!Object.isFunction(e.prototype[b]))throw Error("Attempt to add trait to class instance failed because trait contained an entity that was not a method. Traits may only contain methods.");
+a.prototype[b]=e.prototype[b]}}};
+$JSKK.Class={create:function(a){if(typeof a=="string"){var d=window,b=a,j={};j.$name=a;j.$namespace="window";a=j}else if(Object.isUndefined(a.$name))throw Error("Class name must be defined.");else b=a.$name,Object.isUndefined(a.$namespace)?(a.$namespace="window",d=window):d=$JSKK.namespace(a.$namespace);a.$type="class";d[b]=function(){if(a.$abstract)throw'"'+b+'" is an abstract class and cannot be directly initiated.';var h=Object.clone(d[b].prototype),e=$JSKK.toArray(arguments);if(d[b].prototype.__behaviors.length)for(var f=
+0,g=d[b].prototype.__behaviors.length;f<g;f++){var i=e.shift();d[b].prototype.__behaviors[f].call(this,i)}d[b].prototype=h;h=function(a,b){var d=function(a,b,c,e,f){var g=a[b].$parent;a[b].$parent=function(a,c){return function(){var f=null;if(!Object.isUndefined(e.definition.$extends))for(var g=e.definition.$extends,h=false;;)if(Object.isFunction(g.prototype[b])&&a[b]!==g.prototype[b]){h=true;f=d(a,b,c,g,arguments);break}else if(Object.isUndefined(g.definition.$extends))break;else g=g.definition.$extends;
+h||(f=c.apply(a,arguments));return f}}(a,e.prototype[b]);c=c.apply(a,f);a[b].$parent=g;return c},f=function(a,b,c){var e=a[b];a[b]=function(){a[b].$parent=function(a,e){return function(){var f=null;if(!Object.isUndefined(c.definition.$extends))for(var g=c.definition.$extends,h=false;;)if(Object.isFunction(g.prototype[b])&&a[b]!==g.prototype[b]){h=true;f=d(a,b,e,g,arguments);break}else if(Object.isUndefined(g.definition.$extends))break;else g=g.definition.$extends;h||(f=e.apply(a,arguments));return f}}(a,
+c.prototype[b]);return e.apply(a,arguments)}};if(!Object.isUndefined(b.$extends))for(object in b.$extends.prototype)if(Object.isFunction(a[object])&&Object.isFunction(b.$extends.prototype[object])&&a[object]!==b.$extends.prototype[object])f(a,object,b.$extends);else if(Object.isFunction(a[object]))for(var e=b.$extends;;)if(Object.isFunction(e.prototype[object])&&a[object]!==e.prototype[object]){f(a,object,e);break}else if(Object.isUndefined(e.definition.$extends))break;else e=e.definition.$extends};
+Object.isUndefined(d[b].definition.$extends)||h(this,d[b].definition);delete h;Object.isFunction(this.init)&&this.init.apply(this,e)};return function(h,e){if(Object.isDefined(a.$extends))if(Object.isUndefined(a.$extends))throw Error("Unable to extend class. Class to extend from is undefined.");else if(a.$extends.definition.$type=="interface")throw Error("Unable to extend class from interface. Use $implements followed by interface.");else if(a.$extends.definition.$type=="trait")throw Error("Unable to extend class from trait. Use $uses followed by the trait or an array of traits.");
+else if(Object.isFunction(a.$extends.prototype.$reflect))if(Object.isDefined(a.$extends.definition.$final)&&a.$extends.definition.$final)throw Error("Unable to extend class. Class to extend from is declared as final.");else{for(var f in a.$extends)if(a.$extends.definition.$statics.methods.inArray(f)||a.$extends.definition.$statics.properties.inArray(f))d[b][f]=a.$extends[f];a.$statics=Object.extend(a.$statics,a.$extends.definition.$statics);d[b].prototype=Object.extend(d[b].prototype,a.$extends.prototype)}else throw Error('Unable to extend class. Class to extend from is not an instance of "$JSKK.Class".');
+f=false;if(!Object.isArray(d[b].prototype.__behaviors))d[b].prototype.__behaviors=[];if(!Object.isUndefined(a.$uses)){if(!Object.isArray(a.$uses))a.$uses=[a.$uses];f=$JSKK.Trait.normalize(a.$uses);for(var g=0,i=a.$uses.length;g<i;g++)Object.isFunction(a.$uses[g])&&Object.isFunction(a.$uses[g].prototype.init)&&d[b].prototype.__behaviors.push(a.$uses[g].prototype.init);if(!Object.isArray(a.$uses))a.$uses=[a.$uses]}if(!Object.isUndefined(a.$implements)){if(!Object.isArray(a.$implements))a.$implements=
+[a.$implements];g=0;for(i=a.$implements.length;g<i;g++)$JSKK.Interface.validate(a.$implements[g])&&$JSKK.Interface.add(d[b],e,f,a.$implements[g])}Object.isUndefined(a.$uses)||$JSKK.Trait.validate(f)&&$JSKK.Trait.add(d[b],f);delete f;d[b].prototype.$reflect=function(c){switch(c){case "type":return a.$type;case "namespace":return a.$namespace;case "name":return a.$name;case "extends":return a.$extends;case "implements":return a.$implements;case "uses":return a.$uses;case "abstract":return a.$abstract||
+false;case "final":return a.$final||false;case "self":return d[b]}};if(Object.isUndefined(a.$statics))a.$statics={properties:[],methods:[]};for(var c in h)Object.isFunction(h[c])?a.$statics.methods.push(c):a.$statics.properties.push(c),d[b][c]=Object.clone(h[c]);for(c in e)if(Object.isFunction(e[c])){if(e[c]===$JSKK.Class.ABSTRACT_METHOD)if(a.$abstract)d[b].prototype[c]=Object.clone(e[c]);else throw'"'+b+'" contains one or more abstract methods and must be declared as abstract.';Object.isFunction(d[b].prototype[c])?
+(f=d[b].prototype[c],d[b].prototype[c]=e[c],d[b].prototype[c].$parent=f):d[b].prototype[c]=Object.isAssocArray(e[c])?Object.clone(e[c]):e[c]}else d[b].prototype[c]=Object.isAssocArray(e[c])?Object.clone(e[c]):e[c];for(c in d[b].prototype)if(Object.isFunction(d[b].prototype[c])&&d[b].prototype[c]===$JSKK.Class.ABSTRACT_METHOD&&!a.$abstract)throw['"'+c+'" is an abstract method and so must either be defined or the class ',' "'+b+'" must be declared as abstract by defining'," $abstract:true in the class definition."].join("");
+d[b].toString=function(){return"[JSKK Class ("+a.$namespace+"."+a.$name+")]"};d[b].definition=a}},ABSTRACT_METHOD:function(){}};
+$JSKK.Class.create({$namespace:"$JSKK",$name:"When"})({},{timer:null,items:{length:0},init:function(){this.timer=null;this.startTimer()},startTimer:function(){if(Object.isNull(this.timer))this.timer=window.setInterval(function(){for(var a in this.items)if(a!="length")try{this[this.items[a].condition](this.items[a])}catch(c){throw this.removeItem(this.items[a].id),c;}}.bind(this),100)},stopTimer:function(){window.clearInterval(this.timer);this.timer=null},captureCondition:function(a,c,b){b=$JSKK.toArray(b);
+b.length?(this.items[c].condition=a,this.items[c].callback=b.shift(),this.items[c].args=b):this.removeItem(c)},addItem:function(a,c){var b=Math.round(Math.random()*1E6);this.items[b]={id:b,scope:a,object:c,condition:null,callback:$JSKK.emptyFunction,args:null};this.items.length++;this.items.length&&this.startTimer();return b},removeItem:function(a){delete this.items[a];this.items.length--;this.items.length||this.stopTimer()},assert:function(a,c){a&&(c.callback.apply(c.callback,c.args),this.removeItem(c.id))},
+isDefined:function(a){this.assert(Object.isDefined(a.scope[a.object]),a)},isUndefined:function(a){this.assert(Object.isUndefined(a.scope[a.object]),a)},isTrue:function(a){Object.isFunction(a.scope)?this.assert(a.scope()===true,a):this.assert(a.scope[a.object]===true,a)},isFalse:function(a){Object.isFunction(a.scope)?this.assert(a.scope()===false,a):this.assert(a.scope[a.object]===false,a)},isBoolean:function(a){this.assert(Object.isBoolean(a.scope[a.object]),a)},isFunction:function(a){this.assert(Object.isFunction(a.scope[a.object]),
+a)},isArray:function(a){this.assert(Object.isArray(a.scope[a.object]),a)},isAssocArray:function(a){this.assert(Object.isAssocArray(a.scope[a.object]),a)},isString:function(a){this.assert(Object.isString(a.scope[a.object]),a)},isNumber:function(a){this.assert(Object.isNumber(a.scope[a.object]),a)},isElement:function(a){this.assert(Object.isElement(a.scope[a.object]),a)},isNull:function(a){this.assert(Object.isNull(a.scope[a.object]),a)},isEqualTo:function(a){this.assert(a.scope[a.object.object]==a.object.value,
+a)},isNotEqualTo:function(a){this.assert(a.scope[a.object.object]!=a.object.value,a)}});$JSKK.When=new $JSKK.When;
+$JSKK.when=function(a,c){var b=$JSKK.When.addItem(a,c),e=arguments.callee,d={andWhen:function(){return arguments.length?e(arguments[0],arguments[1]):e(a,c)}};return{isDefined:function(){$JSKK.When.captureCondition("isDefined",b,arguments);return d},isUndefined:function(){$JSKK.When.captureCondition("isUndefined",b,arguments);return d},isTrue:function(){$JSKK.When.captureCondition("isTrue",b,arguments);return d},isFalse:function(){$JSKK.When.captureCondition("isFalse",b,arguments);return d},isBoolean:function(){$JSKK.When.captureCondition("isBoolean",
+b,arguments);return d},isFunction:function(){$JSKK.When.captureCondition("isFunction",b,arguments);return d},isArray:function(){$JSKK.When.captureCondition("isArray",b,arguments);return d},isAssocArray:function(){$JSKK.When.captureCondition("isAssocArray",b,arguments);return d},isString:function(){$JSKK.When.captureCondition("isString",b,arguments);return d},isNumber:function(){$JSKK.When.captureCondition("isNumber",b,arguments);return d},isElement:function(){$JSKK.When.captureCondition("isElement",
+b,arguments);return d},isNull:function(){$JSKK.When.captureCondition("isNull",b,arguments);return d},isEqualTo:function(){$JSKK.When.captureCondition("isEqualTo",b,arguments);return d},isNotEqualTo:function(){$JSKK.When.captureCondition("isNotEqualTo",b,arguments);return d}}};
+$JSKK.Interface.create({$namespace:"$JSKK.iface",$name:"Configurable"})({config:{}});
+$JSKK.Interface.create({$namespace:"$JSKK.iface",$name:"Observable"})({events:[],observe:$JSKK.Interface.METHOD,unobserve:$JSKK.Interface.METHOD,fireEvent:$JSKK.Interface.METHOD});
+$JSKK.Trait.create({$namespace:"$JSKK.trait",$name:"Configurable",$implements:$JSKK.iface.Configurable})({init:function(a){Object.extend(this.config,a)}});
+$JSKK.Trait.create({$namespace:"$JSKK.trait",$name:"Observable",$implements:$JSKK.iface.Observable})({init:function(a){for(var b in a)if(!Object.isFunction(a[b])&&Object.isAssocArray(a[b]))if(Object.isDefined(a[b].callback))Object.isDefined(a[b].times)?this.observeTimes(a[b].times,b,a[b]):this.observe(b,a[b]);else throw Error('Invalid observer. Observers defined as objects must specify "callback" as the callback function.');else if(Object.isFunction(a[b]))this.observe(b,a[b]);else throw Error("Invalid observer. Observers can only be functions.");
+},observe:function(a,b){Object.isArray(this.events[a])||(this.events[a]=[]);Object.isArray(a)||(a=[a]);for(var c=0,e=a.length;c<e;c++)this.events[a[c]].push(b),this.events[a[c]].last().times=0;return this},observeOnce:function(a,b){return this.observeTimes.call(this,1,a,b)},observeTimes:function(a,b,c){Object.isArray(this.events[b])||(this.events[b]=[]);Object.isArray(b)||(b=[b]);for(var e=0,d=b.length;e<d;e++)this.events[b[e]].push(c),this.events[b[e]].last().times=a;return this},unobserve:function(a,
+b){Object.isArray(a)||(a=[a]);for(var c=0,e=a.length;c<e;c++){if(!Object.isUndefined(this.events[a[c]]))for(var d=[],f=0,g=this.events[a[c]].length;f<g;f++)this.events[a[c]][f]==b?delete this.events[a[c]][f]:d.push(this.events[a[c]][f]);this.events[a[c]]=d;this.events[a[c]].length||(this.events[a[c]]=true)}return this},fireEvent:function(){var a=$JSKK.toArray(arguments),b=a.shift();Object.isArray(b)||(b=[b]);for(var c=0,e=b.length;c<e;c++)if(!Object.isUndefined(this.events[b[c]])&&Object.isArray(this.events[b[c]]))for(var d=
+0,f=this.events[b[c]].length;d<f;d++)if(Object.isFunction(this.events[b[c]][d])){if(this.events[b[c]][d].apply(this,a)===false)return false;Object.isDefined(this.events[b[c]][d])&&this.events[b[c]][d].times!==0&&--this.events[b[c]][d].times===0&&this.unobserve(b[c],this.events[b[c]][d])}return true},clearEvent:function(a){Object.isUndefined(this.events[a])||(this.events[a]=true);return this}});
+$JSKK.Trait.create({$namespace:"$JSKK.trait",$name:"Timeable",$traits:$JSKK.trait.Observable})({startTimer:function(){if(this.config.timeout)this.timeout=this.config.timeout,window.clearInterval(this.timer),this.timer=window.setInterval(function(){this.timeout--;this.fireEvent("onTimerInterval",this,this.getElapsedTime());this.timeout<=0&&(window.clearInterval(this.timer),this.fireEvent("onTimeout",this))}.bind(this),1E3)},restartTimer:function(){this.startTimer()},pauseTimer:function(){window.clearInterval(this.timer)},
+resumeTimer:function(){this.startTimer()},stopTimer:function(){window.clearInterval(this.timer);this.timeout=this.config.timeout},resetTimer:function(){this.timeout=this.config.timeout},getElapsedTime:function(){return this.config.timeout-this.timeout},getRemainingTime:function(){return this.timeout}});
View
103 examples/basic/static/app.js
@@ -35,7 +35,68 @@ $JSKK.Class.create
}
)
(
- {},
+ {
+ //Constants
+ FOO2: 'foo2',
+ BAR2: 'bar2',
+ BAZ2: 'baz2',
+
+ //Static methods. These don't hold scope.
+ someStaticMethod2: function()
+ {
+ document.body.innerHTML='Hello World';
+ console.debug(this);
+ }
+ },
+ {}
+);
+$JSKK.Class.create
+(
+ {
+ $namespace: 'application',
+ $name: 'Main3',
+ $extends: application.Main2
+ }
+)
+(
+ {
+ //Constants
+ FOO3: 'foo3',
+ BAR3: 'bar3',
+ BAZ3: 'baz3',
+
+ //Static methods. These don't hold scope.
+ someStaticMethod3: function()
+ {
+ document.body.innerHTML='Hello World';
+ console.debug(this);
+ }
+ },
+ {}
+);
+
+$JSKK.Class.create
+(
+ {
+ $namespace: 'application',
+ $name: 'Main4',
+ $extends: application.Main3
+ }
+)
+(
+ {
+ //Constants
+ FOO: 'foo4',
+ BAR: 'bar4',
+ BAZ: 'baz4',
+
+ //Static methods. These don't hold scope.
+ someStaticMethod: function()
+ {
+ document.body.innerHTML='override!';
+ console.debug(this);
+ }
+ },
{}
);
@@ -47,10 +108,48 @@ console.debug(application.Main.BAZ);
application.Main.someStaticMethod();
+
$application2=new application.Main2();
console.debug(application.Main2.FOO);
console.debug(application.Main2.BAR);
console.debug(application.Main2.BAZ);
-application.Main2.someStaticMethod();
+application.Main2.someStaticMethod();
+
+console.debug(application.Main2.FOO2);
+console.debug(application.Main2.BAR2);
+console.debug(application.Main2.BAZ2);
+
+application.Main2.someStaticMethod2();
+
+
+$application3=new application.Main3();
+
+console.debug(application.Main3.FOO);
+console.debug(application.Main3.BAR);
+console.debug(application.Main3.BAZ);
+
+application.Main3.someStaticMethod();
+
+console.debug(application.Main3.FOO2);
+console.debug(application.Main3.BAR2);
+console.debug(application.Main3.BAZ2);
+
+application.Main3.someStaticMethod2();
+
+console.debug(application.Main3.FOO3);
+console.debug(application.Main3.BAR3);
+console.debug(application.Main3.BAZ3);
+
+application.Main3.someStaticMethod3();
+
+
+
+$application4=new application.Main4();
+
+console.debug(application.Main4.FOO);
+console.debug(application.Main4.BAR);
+console.debug(application.Main4.BAZ);
+
+application.Main4.someStaticMethod();
View
5 examples/basic/static/index.html
@@ -4,8 +4,9 @@
<title></title>
</head>
<body>
- <script type="text/javascript" src="../../../src/extension/object.js"> </script>
- <script type="text/javascript" src="../../../src/extension/function.js"> </script>
+ <script type="text/javascript" src="../../../src/extension/Object.js"> </script>
+ <script type="text/javascript" src="../../../src/extension/Function.js"> </script>
+ <script type="text/javascript" src="../../../src/extension/Array.js"> </script>
<script type="text/javascript" src="../../../src/Core.js"> </script>
<script type="text/javascript" src="../../../src/Interface.js"> </script>
View
21 src/Class.js
@@ -244,6 +244,15 @@ $JSKK.Class=
}
else
{
+ for (var prop in definition.$extends)
+ {
+ if (definition.$extends.definition.$statics.methods.inArray(prop)
+ || definition.$extends.definition.$statics.properties.inArray(prop))
+ {
+ namespace[className][prop]=definition.$extends[prop];
+ }
+ }
+ definition.$statics=Object.extend(definition.$statics,definition.$extends.definition.$statics);
namespace[className].prototype=Object.extend(namespace[className].prototype,definition.$extends.prototype);
}
}
@@ -305,8 +314,20 @@ $JSKK.Class=
}
//Add the static stuff to the class.
+ if (Object.isUndefined(definition.$statics))
+ {
+ definition.$statics={properties:[],methods:[]};
+ }
for (var item in classStatics)
{
+ if (Object.isFunction(classStatics[item]))
+ {
+ definition.$statics.methods.push(item);
+ }
+ else
+ {
+ definition.$statics.properties.push(item);
+ }
namespace[className][item]=Object.clone(classStatics[item]);
}
Please sign in to comment.
Something went wrong with that request. Please try again.