/** * copyright © geolabs 2006-2007 * author: Gérald Fenoy gerald [ at ] geolabs [dot] fr * * MetaJS is an Object Oriented Programming Language based on top of the * prototyped JavaScript language. * */ System={}; System.libpath="http://metajs.googlecode.com/svn/trunk/metajs/"; System.shouldStart=true; System.debug=false; System.loaded=false; System.document=document; System.window=window; System.inheritedRequire=false; System.start=function(){}; System.loadScript=function(){ var head = arguments[0].getElementsByTagName("head")[0]; script = arguments[0].createElement('script'); script.id = 'lib.loaded.'+arguments[1]; script.type = 'text/javascript'; script.charset = "utf-8"; script.src = (arguments[2]?arguments[2]:"")+arguments[1]+".js"; head.appendChild(script); }; System.require=function() { var tmp=arguments[0].split('.'); if(tmp.length>1){ this.inherited_require(tmp); this.shouldStart=false; this.ensure_included(); this.shouldStart=true; this.require(tmp[tmp.length-1]); this.inheritedRequire=true; return; } if (eval("self."+arguments[0]) && document.getElementById('lib.loaded.'+arguments[0])) { // Already exists return; } if(!document.getElementById('lib.loaded.'+arguments[0])){ System.loadScript(document,arguments[0],System.libpath); /* var head = document.getElementsByTagName("head")[0]; script = document.createElement('script'); script.id = 'lib.loaded.'+arguments[0]; script.type = 'text/javascript'; script.charset = "utf-8"; script.src = System.libpath+arguments[0]+".js"; head.appendChild(script); */ } }; System.inherited_require=function(){ for(var i=0;i"; eval(toEval); } } } } catch(e){ try{ if(System.debug) System.document.body.innerHTML+="[octometa alert] => "+e; throw("[octometa alert] => "+e); } catch(e){ setTimeout('System.shouldStart='+this.shouldStart+';System.ensure_included();',1000+this.waitForLoad); this.waitForLoad++; return 0; } } if(this.shouldStart && !this.loaded){ this.start(); this.loaded=true; if(this.inheritedRequire) document.location+="#app"; } return 1; }; /** * MetaClass Class. * * Class is the metaclass for all classes defined later. * */ function Class(){ }; Class.isDefined=true; /** * Function used to define new classes. * * The mechanism used there imply the you must have a method called "_init" in * the class created. * * You could use an object as first argument to be able to define static * properties(represented by object property name). * * Exemple : * {@code MyClass = Class.create({list: new Array()}); } * In this exemple we define MyClass with a static attribute called list which * is (for all the instances of MyClass) on the intialisation an empty Array. * */ Class.create=function(){ return Class.extend(arguments[0]); }; Class.append=function(){ for(i in arguments[1]){ arguments[0][i]=arguments[1][i]; } }; /** * Function used to define the properties of the created class. * * You must use this function when you want to add properties to the created * class. It must be called with one parameter which must be a javascript object * where the properties names are the method an attributes name and the values * are the attribute values or the functions body. * * This function has the particualarity to append to a _super namespace the * overloaded functions in subclasses. The choice has been made to let devs * use the _super method definition, this could be very usefull in reusable * software development. * * Exemple : * {@code * MyClass.define({ * _init: function([args]){[body]}[, * other: function([args]){[body]}, * ... ] * }); * } * */ Class.define=function(def){ for(var i in def){ if(this.prototype[i]){ /** * be carfull modified on 2007/01/03 * before we use this.prototype._super[i] and it works in most case * but I've just seen that you couldn't use it when you want to define a * function which is allready a Class function so I've removed it. * this.prototype._super[i]=this.prototype[i]; */ this.prototype._super[i]=this.prototype[i]; } this.prototype[i]=def[i]; } }; /** * Function used to call superClass method * * Exemple: * {@code this.superCall("",[arguments]); } * */ Class.superCall=function(){ var args=new Array(); if(arguments.length>1) args=arguments[1]; var top=1; if(this._super[arguments[0]]) this._super[arguments[0]].apply(this,args); else{ toEval="this.prototype"; while(eval(toEval)){ if(eval(toEval)._super && eval(toEval)._super[arguments[0]]){ eval(toEval)._super[arguments[0]].apply(this,args); return; } toEval+=".prototype"; } } }; Class.dump=function(){ var tmp=""; for(i in this){ tmp+=i+"\n"; if(typeof this[i]=="object"){ //this[i].dump(); for(var j in this[i]){ tmp+=" + "+j+"\n"; if(typeof this[i][j]=="object"){ //tmp+=this[i][j].dump() for(var k in this[i][j]) tmp+=" + "+k+" => "+this[i][j][k]+"\n"; } else tmp+=" + "+j+" => "+this[i][j]+"\n"; } } else tmp+=" + "+i+" => "+this[i]+"\n"; } //return tmp; document.body.appendChild(document.createTextNode(tmp)); }; /** * Function used to extend from a class * * Exemple : * {@code * A=Class.create(); * A.define({ * message: "test", * _init: function(){}, * print: function(){document.write("A => "+this.message);} * }); * B=A.extend(); * B.define({ * message: "test", * _init: function(){}, * print: function(){ * this.superCall("print"); * document.write("B => "+this.message); * } * }); * } */ Class.extend=function(staticDef){ var newClass=function(){ this._init.apply(this,arguments); } if(typeof staticDef=='object'){ for(i in staticDef){ newClass[i]=staticDef[i]; } } var proto=new this(); for(var property in this){ var tmp=this[property]; if(this[property]!==Class.create){ proto[property]=tmp; } } newClass.prototype=proto; newClass._super={};//proto; newClass.define=this.define; newClass.extend=this.extend; newClass.dump=this.dump; newClass.isDefined=false; //newClass._name="Octo_"+this.name; return newClass; }; /** * Function used to keep track on the object reference from an object * method. * * The bind function was inspired by this work : * @see http://www.brockman.se/writing/method-references.html.utf8 * @see http://la.ma.la/misc/js/delicious.html */ Class.append(Function.prototype,{ bind: function(){ var myFunction=this; var object=arguments[0]; return function(){ var pargs=new Array(); for(i=0;i