Difference between revisions of "MediaWiki:Common.js/search.js"

From Ref
Jump to: navigation, search
(New page: //<source lang="JavaScript"> /** Change Special:Search to use a drop-down menu ******************************************************* * * Description: Change Special:Search to use a...)
 
(No difference)

Latest revision as of 22:12, 19 November 2008

//<source lang="JavaScript">

/** Change Special:Search to use a drop-down menu *******************************************************
  *
  *  Description: Change Special:Search to use a drop-down menu, with the default being
  *               the internal MediaWiki engine. This script is copied from a similar script at Wikipedia, located at
  *               http://en.wikipedia.org/wiki/MediaWiki:Common.js/search.js, and is thereby released under the same license terms (GNU Free Documentation License, Version 1.2). 
  *  The original script was ceated and maintained by: [[Wikipedia:User:Gracenotes]]
  */

function SpecialSearchEnhanced() {
    var createOption = function(site, action, mainQ, addQ, addV) {
        var opt = document.createElement('option');
        opt.appendChild(document.createTextNode(site));
        searchEngines[searchEngines.length] = [action, mainQ, addQ, addV];
        return opt;
    }

    if (document.forms['powersearch'])
        var searchForm = document.forms['powersearch'];
    if (document.forms['search'])
        var searchForm = document.forms['search'];

    if (searchForm.lsearchbox) {
        var searchBox = searchForm.lsearchbox;
    } else {
        var searchBox = searchForm.search;
    }
    var selectBox = document.createElement('select');
    selectBox.id = 'searchEngine';
    searchForm.onsubmit = function() {
        var optSelected = searchEngines[document.getElementById('searchEngine').selectedIndex];
        searchForm.action = optSelected[0];
        searchBox.name = optSelected[1];
        searchForm.title.value = optSelected[3];
        searchForm.title.name = optSelected[2];
    }
    selectBox.appendChild(createOption('Search Ref', wgScriptPath + '/index.php', 'search', 'title', 'Special:Search'));
    selectBox.appendChild(createOption('Groupprops', 'http://groupprops.subwiki.org/w', 'search', 'title', 'Special:Search'));
    selectBox.appendChild(createOption('Topospaces', 'http://topospaces.subwiki.org/w', 'search', 'title', 'Special:Search'));
    selectBox.appendChild(createOption('Commalg', 'http://commalg.subwiki.org/w', 'search', 'title', 'Special:Search'));
    selectBox.appendChild(createOption('Diffgeom', 'http://diffgeom.subwiki.org/w', 'search', 'title', 'Special:Search'));
    selectBox.appendChild(createOption('Companal', 'http://companal.subwiki.org/w', 'search', 'title', 'Special:Search'));
    searchBox.style.marginLeft = '0px';
    if (document.getElementById('loadStatus')) {
        var lStat = document.getElementById('loadStatus');
    } else {
        var lStat = searchForm.fulltext;
    }
    lStat.parentNode.insertBefore(selectBox, lStat);
}

var searchEngines = [];
addOnloadHook(SpecialSearchEnhanced);

//</source>