MediaWiki:Skin/Commons:Kugel.js: Unterschied zwischen den Versionen

aus Kamelopedia, der wüsten Enzyklopädie
Zur Navigation springen Zur Suche springen
Keine Bearbeitungszusammenfassung
K limit: 12,
Zeile 41: Zeile 41:
     currentQuery = {
     currentQuery = {
    search:qs,
    search:qs,
    limit: 10,
    limit: 12,
    page: 0
    page: 0
     };
     };

Version vom 8. November 2010, 16:43 Uhr

addJS("MediaWiki:Skin/Commons:Kugel/simple.js");
addJS("MediaWiki:Skin/Commons:Kugel/api.js");
addJS("MediaWiki:Skin/Commons:Kugel/dpl.js");

var form = null;
 
addOnloadHook( function () {
	jQuery("#bs_form").empty();
	form = jQuery("<form></form>");
	form.appendTo("#bs_form");
	form.append("<input name='q' type='text' style='width:50%'/>");
	form.append("<input type='submit' value='Suchen'><br>");
	form.append('<input type="radio" value="API" checked="checked" name="mode" id="bs_mode_api">');
	form.append('<label for="bs_mode_api">API</label>');
	form.append('<input type="radio" value="DPL" name="mode" id="bs_mode_dpl">');
	form.append('<label for="bs_mode_dpl">DPL</label>&emsp;');
	form.append("<a style='font-size:80%;' href='/index.php/Commons:Kugel/Hilfe'>Tipps &amp; Tricks</a>");
}); 

var currentQuery = {};
var currentEngine = null;
 
/*
 * Analysiert den Suchstring qs und wählt eine passende Suchmaschine aus.
 * Rückgabewert ist ein Object {engine:…, render:…, params:…, error:…}
 *   - engine: Pointer auf die Suchfunktion
 *   - params: Parameter-Objekt
 *         - page: Seitennummer, beginnend mit 0
 *         - optional weitere Parameter
 *   - error: im Erfolgsfall null, sonst Fehlerstring
 *   - render: Pointer auf die Renderfunktion
 */
function parseQuery (qs) {
    var mode = jQuery(form).find("input:radio:checked").val();
 
    if (mode == "API")
        currentEngine = bs_API.defaultSearch;
    if (mode == "DPL")
        currentEngine = bs_DPL.defaultSearch;

    currentQuery = {
	    search:qs,
	    limit: 12,
	    page: 0
    };

    currentEngine(currentQuery);
 
}

addOnloadHook( function () { 
	form.bind('submit', function () {
	    try {
		jQuery("#bs_logo, #bs_controls, #bs_results").fadeOut('slow');
	 
		parseQuery(this.q.value);
	 
		jQuery("#bs_controls, #bs_results").fadeIn('slow');
	    }
	    catch(e)
	    {
		if (console && console.log)
		    console.log(e)
	    }
	    finally
	    {
		return false;
	    }
	});
	 
	jQuery("#bs_controls span").attr("class","pseudolink");
	jQuery("#bs_controls span").each(function (num,obj) {
	    jQuery(obj).bind("click", function () {
		currentQuery.page = num - 1;
		currentEngine(currentQuery);
	    });
	});
	 
	jQuery("#bs_controls span:first").each(function (num,obj) {
	    jQuery(obj).unbind("click")
	    jQuery(obj).bind("click", function () {
		currentQuery.page -= 1;
		if (currentQuery.page < 0)
		    currentQuery.page = 0
		currentEngine(currentQuery);
	    });
	});
	 
	jQuery("#bs_controls span:last").each(function (num,obj) {
	    jQuery(obj).unbind("click")
	    jQuery(obj).bind("click", function () {
		currentQuery.page += 1;
	    currentEngine(currentQuery);
	    });
	});
});