User:TheFearow/suggest.js

/* author: Inez Korczynski ( lastname at gmail dot com ) Modifications by TheFearow from en.wikipedia.org

function dw($s) { document.write($s); }

dw("\\");

dw("\\");

dw("\\");

dw("\\");

dw("\\");

dw("\\");

dw("\");

var nsShowed = false; var sExpand = false; function initSuggest { if(skin != 'monobook') { return; // currently that script works only with monobook skin }

if(!YAHOO.util.Dom.get('searchInput') || !YAHOO.util.Dom.get('searchGoButton')) { return; // missing HTML elements }

var suggestDiv = document.createElement('div'); suggestDiv.id = 'searchSuggest'; YAHOO.util.Dom.get('searchInput').parentNode.insertBefore(suggestDiv, YAHOO.util.Dom.get('searchGoButton'));

YAHOO.example.SuggestFunction = new function{ this.oDS = new YAHOO.widget.DS_XHR(wgScriptPath + "/api.php", ["query.allpages","title"]); this.oDS.scriptQueryAppend = "action=query&list=allpages&format=json"; this.oDS.scriptQueryParam = "apfrom"; this.oDS.queryMatchCase = false; this.oDS.queryMatchContains = true;

this.oAutoComp = new YAHOO.widget.AutoComplete('searchInput', 'searchSuggest', this.oDS); this.oAutoComp.autoHighlight = false; this.oAutoComp.typeAhead = true; this.oAutoComp.queryDelay = 0; this.oAutoComp.doBeforeSendQuery = function(sQuery){ if(sQuery.indexOf('%20') > 0 ) { sQuery = sQuery.replace("%20", "_"); }			sExpand = true; return sQuery.charAt(0).toUpperCase + sQuery.substr(1); }

this.oAutoComp.doBeforeExpandContainer = function(oTextbox, oContainer, sQuery, aResults ) { return sExpand; }	}; } addOnloadHook(initSuggest); //window.onload = initSuggest;