MediaWiki:Common.js/search.js

From OniGalore
Jump to navigation Jump to search
Note: After saving, you may have to bypass your browser's cache to see the changes.
  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Microsoft Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
/** 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
  *  Created and maintained by: [[User:Gracenotes]]
  */

function SpecialSearchEnhanced() {
    var createOption = function(site, action, mainQ, addQ, addV) {
        var opt = document.createElement('option');
        opt.appendChild(document.createTextNode(site));
        searchEngines.push([action, mainQ, addQ, addV]);
        return opt;
    }
    var topline = document.getElementById('contentSub');
    topline.style.color = "blue";
    topline.innerText = "Not finding what you're looking for? Select Google from the dropdown menu below and try again.";
    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('MediaWiki Search', mw.config.get('wgScriptPath') + '/index.php', 'search', 'title', 'Special:Search'));
    selectBox.appendChild(createOption('Google', 'https://www.google.com/search', 'q', 'sitesearch', 'wiki.oni2.net'));
    selectBox.appendChild(createOption('Yahoo!', 'https://search.yahoo.com/search', 'p', 'vs', 'wiki.oni2.net'));
    selectBox.appendChild(createOption('Bing', 'https://www.bing.com/search', 'q', 'q1', 'site:https://wiki.oni2.net'));
    searchBox.style.marginLeft = '0px';
    if (document.getElementById('loadStatus')) {
        var lStat = document.getElementById('loadStatus');
    } else {
        var lStat = searchForm.title;
        if( typeof lStat == 'object'  && typeof lStat.length === 'number' ) lStat = lStat[0];
    }
    lStat.parentNode.insertBefore(selectBox, lStat);
}

var searchEngines = [];

$(SpecialSearchEnhanced);