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
K Textersetzung - „http://kamelopedia.mormo.org/“ durch „http://kamelopedia.net/“
 
(4 dazwischenliegende Versionen von einem anderen Benutzer werden nicht angezeigt)
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==
<!--
<!--
Zeile 155: Zeile 38:
== Wiki-Klasse ==
== Wiki-Klasse ==
Achtung, wichtig: Umstellen auf api.php und JSON:
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|flags|timestamp|user|content|comment
  http://kamelopedia.net/api.php?format=jsonfm&indexpageids&action=query&prop=revisions&titles=Hauptseite&rvprop=ids|flags|timestamp|user|content|comment
... und dann den Timestamp zum Schreiben benutzen (vorher .replace(/[^0-9]/g, "")!)
... und dann den Timestamp zum Schreiben benutzen (vorher .replace(/[^0-9]/g, "")!)
Aktuelle version läuft aber schon im lib-Verzeichnis.
== UI ==
<!--
<!--
wiki = {
dragger = {
     /*
     item: null,
    * getSource: fragt wiki nach Seitenquelltexten
    const: {pickupPrecision: 10, dropPrecision: 30},
    * Argumente und Rückgabewerte als Objekt:
    object: {
    * objekt.wiki.title = Seitentitel (benötigtes Argument)
        original: {x: NaN, y: NaN},
    * objekt.wiki.source = Seitenquelltext (Rückgabewert)
        current: {x: NaN, y:NaN}
    */
    },
     getSource: new Async([
    pointer: {
         function ( args ) {  
        original: {x: NaN, y:NaN},
            if (args == null)
        current: {x: NaN, y:NaN}
                args = {};
    },
             if (args.wiki == null)
    handler: { klick: null, drag: null, drop: null },
                 args.wiki = {};
    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)
        {
            dragger.drag();
        }
     },
    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 )
        {
            dragger.item.style.top = dragger.object.original.y + "px";
            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;
    }
}


            new Ajax.Request( wgServer+wgScript, {
document.onmousemove = dragger.mouseMove;
                method:'get',
document.onmouseup = dragger.drop;
                parameters: 'action=raw&title='+escape(args.wiki.title),
                onSuccess: function( transport ) { args.wiki.source = transport.responseText; wiki.getSource.continue(args) },
                onFailure: function() { args.wiki.source = null; wiki.getSource.continue( args ) }
            })
        },
        null
    ]),
    /*
    * getHTML: fragt wiki nach gerenderten Seiten
    * Argumente und Rückgabewerte als Objekt:
    * objekt.wiki.title = Seitentitel (benötigtes Argument)
    * objekt.wiki.HTML = SeitenHTML (Rückgabewert)
    */
    getHTML: new Async([
        function ( args ) {
            if (args == null)
                args = {};
            if (args.wiki == null)
                args.wiki = {};


            new Ajax.Request( wgServer+wgScript, {
for(c=0;c<(l=document.getElementsByClassName("handcard").length);c++)
                method:'get',
{
                parameters: 'action=render&title='+escape(args.wiki.title),
    document.getElementsByClassName("handcard")[c].onmousedown = dragger.pickup;
                onSuccess: function( transport ) { args.wiki.HTML = transport.responseText; wiki.getHTML.continue(args) },
}
                onFailure: function() { args.wiki.HTML = null; wiki.getHTML.continue( args ) }
-->
            })
 
        },
== Hat nix mit Ka-Mel-Oh zu tun, aber weils so schön ist ==
        null
 
    ]),
<!--
    /*
//document.getElementById("bodyContent").innerHTML += "<iframe id='bw'></iframe>";
    * parse: lässt Wiki beliebigen Wiki-Quelltext rendern
//document.getElementById("bw").style.width="100%"
    * Argumente und Rückgabewerte als Objekt:
//document.getElementById("bw").style.height="400px"
    * objekt.wiki.source = Quelltext (benötigtes Argument)
//document.getElementById("bw").style.border="1px transparent solid"
    * objekt.wiki.title = Seitentitel (für {{PAGENAME}} oder ähnliches)
    * objekt.wiki.HTML = SeitenHTML (Rückgabewert)
    */
    parse: new Async([
        function ( args ) {
            if (args == null)
                args = {};
            if (args.wiki == null)
                args.wiki = {};


            filter1='<div id="wikilibajaxfilterdiv1"></div>';
var histTitle= "Hauptseite";
            filter2='<div id="wikilibajaxfilterdiv2"></div>';
var histRevQuery="{{#dpl: titlematch=Hauptseite|skipthispage=no|namespace=|firstrevisionsince=20040101|format=,%REVISION%}}"


            new Ajax.Request( wgServer+wgScript, {
hist = new Async( [
                method:'post',
    function () { return { wiki: {source: histRevQuery, title: histTitle}}; },
                parameters: 'action=submit&wpPreview=true&live=true&title='+escape(args.wiki.title)+'&wpTextbox1='+escape(filter1+args.wiki.source+filter2),
    wiki.parse,
                onSuccess: function( transport ) { args.wiki.HTML = transport.responseText.replace(/&lt;/gi, "<").replace(/&gt;/gi, ">").replace(/&quot;/gi, "\"").replace(/&amp;/gi,"&").replace(new RegExp("^(.|\n)*"+filter1),"").replace(new RegExp(filter2+"(.|\n)*$"),""); wiki.parse.continue(args) },
    function (e) { a = (parseInt("0"+e.wiki.HTML.replace(/[^0-9]/g,""))); document.getElementById("bw").href=wgServer+wgScript+"/" }
                onFailure: function() { args.wiki.HTML = null; wiki.parse.continue( args ) }
])
            })
        },
        null
    ])
};


ready = function ( a ) { alert("->"+String(a.wiki.HTML) ) };


wiki.parse.start( { wiki: {title:"Test", source:"{{Bild}}"} }, ready )
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