Jump to content

User:Jrajav/myskin.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Jrajav (talk | contribs) at 15:22, 25 April 2012 (Created page with ' String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); }; var hintText = "Search"; var focusedClass = "searchFocused"; var blurredClass = ...'). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); };

var hintText = "Search";
var focusedClass = "searchFocused";
var blurredClass = "searchBlurred";

function initSearchHint() {
  var searchbox = document.getElementById('searchInput');
  searchbox.value = hintText;
  searchbox.className = blurredClass;
  searchbox.onfocus = onSearchFocus;
  searchbox.onblur = onSearchBlur;
}

function onSearchFocus() {
  var searchbox = this;
  if (searchbox.value.trim()==hintText) {
    searchbox.value = "";
    searchbox.className = focusedClass;
  }
}

function onSearchBlur() {
  var searchbox = this;
  if (searchbox.value.trim().length==0) {
    searchbox.value = hintText;
    searchbox.className = blurredClass;
  }
}

window.onload = initSearchHint;