Relevant links Edit
For Faethin to copy Edit
/*
Makes the image on the search form, if one is present, point to the search page
instead of the Wikia main page.
*/
function rewriteSearchFormLink() {
if( $('#searchform').length == 0 ) {
return;
}
var links = document.getElementById('searchform').getElementsByTagName('a');
if( links.length > 0 ) {
links[0].href = wgScriptPath + '/index.php?title=Special:Search&adv=1';
}
}
importScript('MediaWiki:Functions.js');
var firstRun = true;
function loadFunc() {
if( firstRun )
firstRun = false;
else
return;
rewriteSearchFormLink();
fixSearch();
}
function fixSearch() {
var button = document.getElementById('searchSubmit');
if( button )
button.name = 'go';
}
addOnloadHook( loadFunc );
// Search icons
function replaceSearchIcon() {
$("#searchBody").find("form").wrapInner('<div />')
var innerDiv;
var searchbox = document.getElementById( 'searchBody' );
if( searchbox ) {
innerDiv = searchbox.getElementsByTagName('div')[0];
var link = innerDiv.getElementsByTagName('a')[0];
if( link ) {
innerDiv.removeChild( link );
}
}
onSearchIconsArrival( innerDiv );
}
function rand( n ) {
return Math.round( Math.random() * n );
}
// silly legacy name :P
// Please note that defining the array here prevents us from having to fetch the article
// and so is much faster. Plus, JS files are cached, which makes it even faster. Yay!
// --TOR <tor@wikia-inc.com>
function onSearchIconsArrival( searchDiv ) {
var lines = new Array(
"http://images2.wikia.nocookie.net/__cb20110517173142/finalfantasy/images/3/3b/BahamutFFSearchbar.png Bahamut",
"http://images1.wikia.nocookie.net/__cb20110517173141/finalfantasy/images/1/1f/ArtemicionSearchbar.png Artemicion"
);
var line = lines[rand( lines.length - 1 )];
var pos = line.indexOf(' ');
var link = document.createElement( 'div' );
link.id = 'search-icon-wrapper';
var img = document.createElement( 'img' );
img.alt = 'Search';
img.src = ( pos == -1 ) ? line : line.substring( 0, pos );
link.appendChild( img );
searchDiv.insertBefore( link, searchDiv.firstChild );
var div = document.createElement( 'div' );
div.id = 'search-popup';
div.style.display = 'none';
var ul = document.createElement( 'ul' );
var li;
var a;
li = document.createElement( 'li' );
a = document.createElement( 'a' );
a.href = wgScriptPath + '/index.php?title=Special:Search&adv=1';
a.appendChild( document.createTextNode( 'Advanced search' ) );
li.appendChild( a );
ul.appendChild( li );
li = document.createElement( 'li' );
a = document.createElement( 'a' );
a.href = ( pos == -1 ) ? 'javascript:emptySearchDesc()' : '/wiki/' + line.substring( pos + 1 );
a.appendChild( document.createTextNode( "What's this? (" + ( ( pos == -1 ) ? 'NO DESCRIPTION' : line.substring( pos + 1 ) ) + ')' ) );
li.appendChild( a );
ul.appendChild( li );
li = document.createElement( 'li' );
a = document.createElement( 'a' );
a.href = 'javascript:closeSearchPopup()';
a.appendChild( document.createTextNode( 'Close' ) );
li.appendChild( a );
ul.appendChild( li );
var container = document.getElementById( 'globalWrapper' );
if( !container ) {
container = document.getElementById( 'container' );
}
div.appendChild( ul );
container.appendChild( div );
link.onclick = openSearchPopup;
}
function openSearchPopup( event ) {
var div = document.getElementById( 'search-popup' );
var e = event || window.event;
div.style.display = ( div.style.display == 'none' ) ? 'block' : 'none';
div.style.left = e.clientX + 'px';
div.style.top = ( e.clientY + document.documentElement.scrollTop ) + 'px';
}
function closeSearchPopup() {
document.getElementById( 'search-popup' ).style.display = 'none';
}
function emptySearchDesc() {
alert( 'No description exists for this search icon. Please contact the administrators to resolve this problem.' );
}
addOnloadHook( replaceSearchIcon );