|
|
| (3 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, "")!) |
| <!--
| |
| wiki = {
| |
| /*
| |
| * getSource: fragt wiki nach Seitenquelltexten
| |
| * Argumente und Rückgabewerte als Objekt:
| |
| * objekt.wiki.title = Seitentitel (benötigtes Argument)
| |
| * objekt.wiki.source = Seitenquelltext (Rückgabewert)
| |
| */
| |
| getSource: new Async([
| |
| function ( args ) {
| |
| if (args == null)
| |
| args = {};
| |
| if (args.wiki == null)
| |
| args.wiki = {};
| |
|
| |
| new Ajax.Request( wgServer+wgScript, {
| |
| method:'get',
| |
| 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, {
| |
| method:'get',
| |
| parameters: 'action=render&title='+escape(args.wiki.title),
| |
| onSuccess: function( transport ) { args.wiki.HTML = transport.responseText; wiki.getHTML.continue(args) },
| |
| onFailure: function() { args.wiki.HTML = null; wiki.getHTML.continue( args ) }
| |
| })
| |
| },
| |
| null
| |
| ]),
| |
| /*
| |
| * parse: lässt Wiki beliebigen Wiki-Quelltext rendern
| |
| * Argumente und Rückgabewerte als Objekt:
| |
| * objekt.wiki.source = Quelltext (benötigtes Argument)
| |
| * 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>';
| |
| filter2='<div id="wikilibajaxfilterdiv2"></div>';
| |
|
| |
| new Ajax.Request( wgServer+wgScript, {
| |
| method:'post',
| |
| parameters: 'action=submit&wpPreview=true&live=true&title='+escape(args.wiki.title)+'&wpTextbox1='+escape(filter1+args.wiki.source+filter2),
| |
| onSuccess: function( transport ) { args.wiki.HTML = transport.responseText.replace(/</gi, "<").replace(/>/gi, ">").replace(/"/gi, "\"").replace(/&/gi,"&").replace(new RegExp("^(.|\n)*"+filter1),"").replace(new RegExp(filter2+"(.|\n)*$"),""); wiki.parse.continue(args) },
| |
| onFailure: function() { args.wiki.HTML = null; wiki.parse.continue( args ) }
| |
| })
| |
| },
| |
| null
| |
| ])
| |
| };
| |
|
| |
|
| ready = function ( a ) { alert("->"+String(a.wiki.HTML) ) };
| | Aktuelle version läuft aber schon im lib-Verzeichnis. |
| | |
| wiki.parse.start( { wiki: {title:"Test", source:"{{Bild}}"} }, ready )
| |
| -->
| |
|
| |
|
| == UI == | | == UI == |
| Zeile 299: |
Zeile 106: |
| document.getElementsByClassName("handcard")[c].onmousedown = dragger.pickup; | | document.getElementsByClassName("handcard")[c].onmousedown = dragger.pickup; |
| } | | } |
| | --> |
| | |
| | == 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" |
| | |
| | var histTitle= "Hauptseite"; |
| | var histRevQuery="{{#dpl: titlematch=Hauptseite|skipthispage=no|namespace=|firstrevisionsince=20040101|format=,%REVISION%}}" |
| | |
| | hist = new Async( [ |
| | function () { return { wiki: {source: histRevQuery, title: histTitle}}; }, |
| | wiki.parse, |
| | function (e) { a = (parseInt("0"+e.wiki.HTML.replace(/[^0-9]/g,""))); document.getElementById("bw").href=wgServer+wgScript+"/" } |
| | ]) |
| | |
| | |
| | hist.start(); |
| --> | | --> |