Benutzer:J*/lib/wiki.js: Unterschied zwischen den Versionen

aus Kamelopedia, der wüsten Enzyklopädie
Zur Navigation springen Zur Suche springen
Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
 
(3 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 66: Zeile 66:
                 data: 'action=parse&format=xml&text='+encodeURIComponent(args.wiki.source)+"&title="+encodeURIComponent(args.wiki.title),
                 data: 'action=parse&format=xml&text='+encodeURIComponent(args.wiki.source)+"&title="+encodeURIComponent(args.wiki.title),
datatype: "xml",
datatype: "xml",
                 success: function( transport ) { args.wiki.HTML = transport; wiki.parse.continue(args) },
                 success: function( transport ) { console.log("wiki.parse:success", args); args.wiki.HTML = jQuery(transport).find("api parse text").text(); wiki.parse.continue(args); },
                 error: function() { args.wiki.HTML = null; wiki.parse.continue( args ) }
                 error: function() { args.wiki.HTML = null; wiki.parse.continue( args ) }
             })
             })

Aktuelle Version vom 22. Mai 2015, 07:12 Uhr

var 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)
     * objekt.wiki.args = Seitenargumente
     */
    getSource: new Async([
        function ( args ) { 
            if (args == null)
                args = {};
            if (args.wiki == null)
                args.wiki = {};

            jQuery.ajax( {
                url: wgServer+wgScript,
                data: 'action=raw&title='+encodeURIComponent(args.wiki.title)+'&'+args.wiki.args,
                dataType: "text",
                success: function( transport ) { args.wiki.source = transport; wiki.getSource.continue(args) },
                error: 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)
     * objekt.wiki.args = Seitenargumente
     */
    getHTML: new Async([
        function ( args ) { 
            if (args == null)
                args = {};
            if (args.wiki == null)
                args.wiki = {};

            jQuery.ajax( {
                url: wgServer+wgScript,
                data: 'action=render&title='+encodeURIComponent(args.wiki.title)+'&'+args.wiki.args,
                dataType: "html",
                success: function( transport ) { args.wiki.HTML = transport; wiki.getHTML.continue(args) },
                error: 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 = {};

            jQuery.ajax( {
                url: wgServer+"/api.php",
                data: 'action=parse&format=xml&text='+encodeURIComponent(args.wiki.source)+"&title="+encodeURIComponent(args.wiki.title),
		datatype: "xml",
                success: function( transport ) { console.log("wiki.parse:success", args); args.wiki.HTML = jQuery(transport).find("api parse text").text(); wiki.parse.continue(args); },
                error: function() { args.wiki.HTML = null; wiki.parse.continue( args ) }
            })
        },
        null
    ])
};