MediaWiki:Common.js: Difference between revisions

From MediaWiki
Jump to navigationJump to search
m Maybe if I actually got the names right...
mNo edit summary
Line 16: Line 16:


   // Throwing all the various fragments together.
   // Throwing all the various fragments together.
   var searchfieldentry = document.searchform.searchInput;
   var searchfieldentry = document.getElementById('searchInput').value;
   searchbox.innerHTML = searchicon + searchbox.innerHTML;
   searchbox.innerHTML = searchicon + searchbox.innerHTML;
   document.searchform.searchInput = searchfieldentry;
   document.getElementById('searchInput').value = searchfieldentry;


   // Finally, removing the redundant "search" title at the top.
   // Finally, removing the redundant "search" title at the top.

Revision as of 03:50, 21 April 2008

function loadsearchstuff() {
  // If you're reading this, I'm sorry. Messy code lies ahead.

  if (document.implementation && document.implementation.createDocument)
       xmlDoc=document.implementation.createDocument("","",null);
  else 
       xmlDoc=new ActiveXObject("Microsoft.XMLDOM");

  xmlDoc.async=false;
  xmlDoc.load("/index.php?title=Template:Searchicons&action=raw");

  // Establishing the various fragments of the search box.
  var randindex = Math.floor(Math.random()*xmlDoc.getElementsByTagName("item").length);
  var searchicon = "<a href='/wiki/" + xmlDoc.getElementsByTagName("name")[randindex].childNodes[0].nodeValue + "'><img src='" + xmlDoc.getElementsByTagName("url")[randindex].childNodes[0].nodeValue + "' style='margin-left: -15px; margin-top:-6px;' /></a>";
  var searchbox = document.getElementById('searchBody');

  // Throwing all the various fragments together.
  var searchfieldentry = document.getElementById('searchInput').value;
  searchbox.innerHTML = searchicon + searchbox.innerHTML;
  document.getElementById('searchInput').value = searchfieldentry;

  // Finally, removing the redundant "search" title at the top.
  searchbox.parentNode.removeChild(searchbox.parentNode.getElementsByTagName("h5")[0]);
}

// This needs to be written from the ground up, since it doesn't work.
function advancedsearch(fulltext) {
  // This is what drives the advanced search. The URL is rewritten, since the parameters
  // do not actually match what the form expects. This should be fixed if there's a better
  // way of doing it, and there probably is.

  var advancedform = document.realform;
  var searchform = document.searchform;
  advancedform.action = "/wiki/Special:Search";
  
  advancedform.action += "?search=" + searchform.search.value;
  
  if (fulltext)  advancedform.action += "&fulltext=Search";
  else advancedform.action += "&go=Go";

  if (searchform.all.checked || searchform.categories.checked || searchform.templates.checked || searchform.talk.checked) searchform.action += "&searchx=Search";
  // This parameter isn't normally passed in the searchbox, but it seems to
  // make the checkboxes retain their values on the advanced search page.

  if (searchform.all.checked)
     for (var i=0; i<15; i++) advancedform.action += "&ns" + i + "=1";
  else { // No need to look at the rest if "all" is checked
     if (searchform.categories.checked) advancedform.action += "&ns14=1";
     if (searchform.templates.checked) advancedform.action += "&ns10=1";
     if (searchform.talk.checked) advancedform.action += "&ns1=1&ns3=1&ns5=1&ns7=1&ns9=1&ns11=1&ns13=1&ns15=1";
  }

  advancedform.submit();

  return false;
}

addOnloadHook(loadsearchstuff);