User:Od1n/MediaWiki:SpecialSearch.js

/** Change Special:Search to use a radio menu ******************************************************* * * Description: Change Special:Search to use a radio menu, with the default being *              the internal MediaWiki engine * Created by: fr:User:Pmartin */

if ((wgNamespaceNumber == -1) && (wgCanonicalSpecialPageName == "Search")) { var searchEngines = { mediawiki: { ShortName: "MediaWiki search", Template: wgScript+"?search={searchTerms}" },       google: { ShortName: "Google", Template: "http://www.google.com/search?hl=" + wgUserLanguage + "&q={searchTerms}&as_sitesearch=" + wgServer.replace(/^.*?\/\//, '') },       wikiwix: { ShortName: "Wikiwix", Template: "http://www.wikiwix.com/index.php?action={searchTerms}&disp=dict" },       live: { ShortName: "Bing", Template: "http://search.live.com/results.aspx?q={searchTerms}&q1=site:" + wgServer.replace(/^.*?\/\//, '') },       yahoo: { ShortName: "Yahoo", Template: "http://search.yahoo.com/search?p={searchTerms}&vs=" + wgServer.replace(/^.*?\/\//, '') }   };    $(externalSearchEngines); }

function externalSearchEngines {

if (typeof SpecialSearchEnhanced2Disabled != 'undefined') return;

var mwSearchTopTable = document.getElementById('mw-search-top-table'); if (!mwSearchTopTable) return;

var firstEngine = "mediawiki";

var lsearchbox = document.getElementById("searchText"); var initValue = lsearchbox.value;

var space = "";

var choices = newNode('div', {id: "searchengineChoices", style: "clear:left; padding-top:0.3em"})

for (var id in searchEngines) { var engine = searchEngines[id]; if(engine.ShortName) {           if (space) choices.appendChild(space); space = document.createTextNode(" ");

choices.appendChild( newNode('span', newNode('input',                    {type: "radio",                      name: "searchengineselect",                      value: id,                      onFocus: "changeSearchEngine('"+id+"');",                      id: "searchengineRadio-"+id}                ) ) );

choices.appendChild( newNode('label', {"for":"searchengineRadio-"+id}, engine.ShortName) ) }   }

choices.appendChild(newNode('input', {id: "searchengineextraparam", type: "hidden"})); $(choices).insertAfter(mwSearchTopTable);

changeSearchEngine(firstEngine, initValue); }

function changeSearchEngine(selectedId) {

var currentId = document.getElementById("searchengineChoices").currentChoice; if (selectedId == currentId) return;

document.getElementById("searchengineChoices").currentChoice = selectedId; var radio = document.getElementById('searchengineRadio-' + selectedId); radio.checked = "checked";

var engine = searchEngines[selectedId]; var p = engine.Template.indexOf('?'); var params = engine.Template.substr(p+1);

var form; if (document.forms["search"]) { form = document.forms["search"]; } else { form = document.getElementById("powersearch"); }   form.setAttribute("action", engine.Template.substr(0,p));

var l = ("" + params).split("&"); for (var i in l) { var p = l[i].split("="); var pValue = p[1];

if (pValue == "{language}") { } else if (pValue == "{searchTerms}") { var input; if (document.forms["search"]) { input = document.getElementById("searchText"); } else { input = document.getElementById("powerSearchText"); }

if (input.tagName.toUpperCase != "INPUT") { input = input.getElementsByTagName("input")[0]; }

input.name = p[0]; } else { var input = document.getElementById("searchengineextraparam");

input.name = p[0]; input.value = pValue; }   } }

/*

Drop-down language preload menu for MediaWiki:Searchmenu-new
*/

function addNogoPreloadMenu { var preloadGuide = document.getElementById('preloadGuide'); if (preloadGuide) { preloadGuide.style.display = 'inline-block'; var menu = ""; menu += " English "; menu += " American Sign Language "; menu += " Spanish "; menu += " Swedish "; menu += " "; var menuDiv = document.getElementById('entryTemplateMenu'); menuDiv.innerHTML = menu; showPreloads(0); } } $(addNogoPreloadMenu);

function showPreloads(selectedIndex) { var languageOptions = document.getElementById('preloadGuide').getElementsByTagName('table'); for (var i = 0; i < languageOptions.length ; i++) { if (languageOptions[i].className == "language") { languageOptions[i].style.display = i == selectedIndex ? 'block' : 'none'; } } }