Kamel:J*/Ka-Mel-Oh/Testgelände/Notizzettel: Unterschied zwischen den Versionen

aus Kamelopedia, der wüsten Enzyklopädie
Zur Navigation springen Zur Suche springen
Die Seite wurde neu angelegt.
 
K Textersetzung - „http://kamelopedia.mormo.org/“ durch „http://kamelopedia.net/“
 
(8 dazwischenliegende Versionen von einem anderen Benutzer werden nicht angezeigt)
Zeile 1: Zeile 1:
// Entwurf 1 für das Framework
__NOTOC__
__NEWSECTIONLINK__
==Framework: Array.prototype und Async==
ab jetzt im Verzeichnis [[Kamel:J*/lib|lib]] zu finden!


==Klassenarchitektur der Karten==
<!--
function X ()
{
    this.constructor(1,2,3,4)
}
X.prototype = new Card()


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!)


/* +-----------------------------------------------------------+
function add(a,b,c,d)
* |                                                          |
{
* |  Modul 1: Erweiterungen von Datentypen mittels prototype |
    a = new Function( "this.constructor(" +
* |                                                          |
        parseInt(a) + "," +
* +-----------------------------------------------------------+
        parseInt(b) + "," +
*/
        parseInt(c) + "," +
        parseInt(d) + ")"
    );
    a.prototype = new Card();
    return a;
}
 


/*
* 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;
}


/* +-------------------------------------------------------------------------+
fkt1 = add(1,2,3,4);
* |                                                                        |
fkt2 = add(2,7,8,9);
* |  Modul 2: Die Async-Klasse, um asynchrone Vorgänge behandeln zu können  |
fkt2.prototype.hooks.bla =
* |          mehr Erklärung gibt's woanders ... vielleicht ...            |
* |                                                                        |
* +-------------------------------------------------------------------------+
*/


function Async ( arr, ondone )
c = new fkt2();
{
c instanceof fkt2
    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 ) {
== Wiki-Klasse ==
        if (ond != null)
Achtung, wichtig: Umstellen auf api.php und JSON:
        {
http://kamelopedia.net/api.php?format=jsonfm&indexpageids&action=query&prop=revisions&titles=Hauptseite&rvprop=ids|flags|timestamp|user|content|comment
            this.ondone = ond;
... und dann den Timestamp zum Schreiben benutzen (vorher .replace(/[^0-9]/g, "")!)
        }
        this.pointer = 0;
        this._control( obj );
    };


    this.continue = function ( obj ) {
Aktuelle version läuft aber schon im lib-Verzeichnis.
        this.pointer++;
        this._control( obj );
    };


    this._control = function ( obj ) {
== UI ==
        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")
<!--
dragger = {
    item: null,
    const: {pickupPrecision: 10, dropPrecision: 30},
    object: {
        original: {x: NaN, y: NaN},
        current: {x: NaN, y:NaN}
    },
    pointer: {
        original: {x: NaN, y:NaN},
        current: {x: NaN, y:NaN}
    },
    handler: { klick: null, drag: null, drop: null },
    dropzones: [ ],
    pickup: function (e) {
         if (dragger.item != null)
            return;
        dragger.object.original.x = this.offsetLeft;
        dragger.object.original.y = this.offsetTop;
        dragger.pointer.original.x = dragger.pointer.current.x;
        dragger.pointer.original.y = dragger.pointer.current.y;
        dragger.item=this;
        return false;
    },
    mouseMove: function (e) {
        dragger.pointer.current.x = document.all ? window.event.clientX : e.pageX;
        dragger.pointer.current.y = document.all ? window.event.clientY : e.pageY;
        if (dragger.item != null)
         {
         {
             this.continue( this[this.pointer]( obj, this ) );
             dragger.drag();
            return
         }
         }
         if (this[this.pointer] instanceof Async)
    },
    drag: function () {
        dragger.object.current.y = dragger.object.original.y + dragger.pointer.current.y - dragger.pointer.original.y;
        dragger.object.current.x = dragger.object.original.x + dragger.pointer.current.x - dragger.pointer.original.x;
        dragger.item.style.top = dragger.object.current.y + "px";
        dragger.item.style.left = dragger.object.current.x + "px";
    },
    drop: function () {
         if ( Math.abs(dragger.object.original.x - dragger.object.current.x) < dragger.const.pickupPrecision &&
            Math.abs(dragger.object.original.y - dragger.object.current.y) < dragger.const.pickupPrecision )
         {
         {
             this[this.pointer].start( obj, this );
             dragger.item.style.top = dragger.object.original.y + "px";
            return
            dragger.item.style.left = dragger.object.original.x + "px";
            var d = dragger.item;
            dragger.item = null;
            if ( dragger.handler.klick != null )
                dragger.handler.klick( d ) 
         }
         }
          
          
     };
        dragger.item = null;
     }
}


document.onmousemove = dragger.mouseMove;
document.onmouseup = dragger.drop;
for(c=0;c<(l=document.getElementsByClassName("handcard").length);c++)
{
    document.getElementsByClassName("handcard")[c].onmousedown = dragger.pickup;
}
}
-->


Async.prototype = new Array ();
== Hat nix mit Ka-Mel-Oh zu tun, aber weils so schön ist ==


// -----------------------------------------------------------------------------------------
<!--
//document.getElementById("bodyContent").innerHTML += "<iframe id='bw'></iframe>";
//document.getElementById("bw").style.width="100%"
//document.getElementById("bw").style.height="400px"
//document.getElementById("bw").style.border="1px transparent solid"


ready = function (w) { alert(w.blubb) }
var histTitle= "Hauptseite";
ready2 = function (w) { alert(w.blubb+"..") }
var histRevQuery="{{#dpl: titlematch=Hauptseite|skipthispage=no|namespace=|firstrevisionsince=20040101|format=,%REVISION%}}"


x = new Async([
hist = new Async( [
     function(t) { t.blubb ++; return t },
     function () { return { wiki: {source: histRevQuery, title: histTitle}}; },
    function(t) { this.nextElement().push( function(u) { t.blubb = u.blubb + 7; return u; } ); return t},
     wiki.parse,
     new Async([
    function (e) { a = (parseInt("0"+e.wiki.HTML.replace(/[^0-9]/g,""))); document.getElementById("bw").href=wgServer+wgScript+"/" }
        function(t) { t.blubb = t.blubb * 10; return t }
])
    ]),
    function(z) { z.w = z.blubb; return z }
],ready);




x.start( { blubb:5 } );
hist.start();
-->

Aktuelle Version vom 3. Januar 2014, 02:43 Uhr


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.net/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, "")!)

Aktuelle version läuft aber schon im lib-Verzeichnis.

UI

Hat nix mit Ka-Mel-Oh zu tun, aber weils so schön ist