|
|
| Zeile 2: |
Zeile 2: |
| __NEWSECTIONLINK__ | | __NEWSECTIONLINK__ |
| ==Framework: Array.prototype und Async== | | ==Framework: Array.prototype und Async== |
| <!--
| | ab jetzt im Verzeichnis [[Kamel:J*/lib|lib]] zu finden! |
|
| |
|
| Test = function (a) {
| |
| var x = this;
| |
| a.each( function(e) { x.push(e) } );
| |
| this.info="abc";
| |
| };
| |
| // Achtung! geht nur mit der Prototype-Library (Prototype.js - nicht verwechseln mit irgendwas.prototype!)
| |
|
| |
| /* +-----------------------------------------------------------+
| |
| * | |
| |
| * | Modul 1: Erweiterungen von Datentypen mittels prototype |
| |
| * | |
| |
| * +-----------------------------------------------------------+
| |
| */
| |
|
| |
| /*
| |
| * Erweiterung von Array: Array.where erlaubt die Filterung von Objekten mittels Vergleichsfunktion
| |
| *
| |
| * Das benutze Array.each ist übrigens der for...in-Ersatz von Prototype
| |
| * (for...in funktionert nicht 100% ordentlich, wenn man prototype in Arrays benutzt)
| |
| *
| |
| * Beispiel für Array.where:
| |
| * var a = [1,2,3];
| |
| * a.where( function(e) { return(e>1) } )
| |
| * -> gibt zurück: [2,3]
| |
| */
| |
|
| |
| Array.prototype.where = function ( fkt ) {
| |
| var out = [];
| |
| this.each( function (e) {
| |
| if ( fkt(e) )
| |
| out.push(e)
| |
| } );
| |
| return out;
| |
| }
| |
|
| |
| /* +-------------------------------------------------------------------------+
| |
| * | |
| |
| * | Modul 2: Die Async-Klasse, um asynchrone Vorgänge behandeln zu können |
| |
| * | mehr Erklärung gibt's woanders ... vielleicht ... |
| |
| * | |
| |
| * +-------------------------------------------------------------------------+
| |
| */
| |
|
| |
| function Async ( arr, ondone )
| |
| {
| |
| var asyncobj = this;
| |
| arr.each( function(d) { asyncobj.push(d); } );
| |
| this.pointer = 0;
| |
| this.ondone = ondone;
| |
| this.nextElement = function() { return this[this.pointer+1]; };
| |
| this.currentElement = function() { return this[this.pointer]; };
| |
|
| |
| this.start = function ( obj, ond ) {
| |
| if (ond != null)
| |
| {
| |
| this.ondone = ond;
| |
| }
| |
| this.pointer = 0;
| |
| this._control( obj );
| |
| };
| |
|
| |
| this.continue = function ( obj ) {
| |
| this.pointer++;
| |
| this._control( obj );
| |
| };
| |
|
| |
| this._control = function ( obj ) {
| |
| if (this.pointer >= this.length)
| |
| {
| |
| if (typeof(this.ondone)=="function")
| |
| {
| |
| alert("Return: Function")
| |
| this.ondone( obj, this );
| |
| return
| |
| }
| |
| if (typeof(this.ondone)=="object") // instanceof gibt hier nur ärger
| |
| {
| |
| alert("Return: object")
| |
| this.ondone.continue( obj );
| |
| return
| |
| }
| |
| }
| |
|
| |
| if (typeof(this[this.pointer])=="function")
| |
| {
| |
| this.continue( this[this.pointer]( obj, this ) );
| |
| return
| |
| }
| |
| if (this[this.pointer] instanceof Async)
| |
| {
| |
| this[this.pointer].start( obj, this );
| |
| return
| |
| }
| |
|
| |
| };
| |
|
| |
| }
| |
|
| |
| Async.prototype = new Array ();
| |
|
| |
| // -----------------------------------------------------------------------------------------
| |
|
| |
| ready = function (w) { alert(w.blubb) }
| |
| ready2 = function (w) { alert(w.blubb+"..") }
| |
|
| |
| x = new Async([
| |
| function(t) { t.blubb ++; return t },
| |
| function(t) { this.nextElement().push( function(u) { t.blubb = u.blubb + 7; return u; } ); return t},
| |
| new Async([
| |
| function(t) { t.blubb = t.blubb * 10; return t }
| |
| ]),
| |
| function(z) { z.w = z.blubb; return z }
| |
| ],ready);
| |
|
| |
|
| |
| x.start( { blubb:5 } );
| |
| -->
| |
| ==Klassenarchitektur der Karten== | | ==Klassenarchitektur der Karten== |
| <!-- | | <!-- |
Framework: Array.prototype und Async
ab jetzt im Verzeichnis lib zu finden!
Klassenarchitektur der Karten
Wiki-Klasse
Achtung, wichtig: Umstellen auf api.php und JSON:
http://kamelopedia.mormo.org/api.php?format=jsonfm&indexpageids&action=query&prop=revisions&titles=Hauptseite&rvprop=ids%7Cflags%7Ctimestamp%7Cuser%7Ccontent%7Ccomment
... und dann den Timestamp zum Schreiben benutzen (vorher .replace(/[^0-9]/g, "")!)
UI
Hat nix mit Ka-Mel-Oh zu tun, aber weils so schön ist