User:Writ Keeper/Scripts/SearchNamespace.js
// Allows the user to select a namespace to search in from the corner search bar
prefixString =
"<option >Article:</option>\n <option>Article talk:</option>\n <option>Wikipedia:</option>\n <option>Wikipedia talk:</option>\n <option>User:</option>\n <option>User talk:</option>\n<option>WikiProject:</option>\n <option>WikiProject talk:</option>\n<option>Category:</option>\n <option>Category talk:</option>\n<option>Template:</option>\n <option>Template talk:</option>\n <option>Book:</option>\n <option>Book talk:</option>\n<option>Help:</option>\n <option>Special:</option>";
$(document).ready(function()
{
//retrieve existing elements that we're going to use
searchBar = document.getElementById("searchInput");
searchButton = document.getElementById("searchButton");
searchForm = document.getElementById("searchform");
searchDiv = document.getElementById("simpleSearch");
if ( !searchDiv || !searchBar ) return; // mobile skin.
//create new elements that we're going to insert
prefixList = document.createElement("select");
hiddenInput = document.createElement("input");
//initialize new elements
prefixList.id = "prefixList";
prefixList.innerHTML = prefixString;
hiddenInput.id = "hiddenInput";
hiddenInput.name = "search";
hiddenInput.type = "hidden";
//insert new elements
searchBar.parentNode.insertBefore(hiddenInput, searchBar);
searchDiv.parentNode.insertBefore(prefixList, searchDiv);
//modify old ones
searchForm.onsubmit = createSearchTerm;
searchForm.style.marginTop = "0px";
searchBar.removeAttribute("name"); //since we're no longer using the search bar to submit the search terms directly
searchDiv.style.display = "inline-block";
prefixList.style.marginTop = ".8em";
prefixList.tabIndex = searchBar.tabIndex;
});
//onsubmit handler; concatenates prefixList and searchBar and inserts into hidden input prior to submission
function createSearchTerm(e)
{
//retrieve used elements
hiddenInput = document.getElementById("hiddenInput");
prefixList = document.getElementById("prefixList");
searchBar = document.getElementById("searchInput");
//do the work (handling special cases)
if(prefixList.value == "Article:")
{
hiddenInput.value = "" + searchBar.value;
}
else if(prefixList.value == "Article talk:")
{
hiddenInput.value = "" + "Talk:" + searchBar.value;
}
else if(prefixList.value == "WikiProject:")
{
hiddenInput.value = "" + "Wikipedia:WikiProject " + searchBar.value;
}
else if(prefixList.value == "WikiProject talk:")
{
hiddenInput.value = "" + "Wikipedia talk:WikiProject " + searchBar.value;
}
else
{
hiddenInput.value = "" + prefixList.value + searchBar.value;
}
}
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.