Slipsnisse.se

SearchPlay the Prototype way

22nd of November, 2007

A re-write of Dustin Diaz’s searchPlay but uses Prototype Object for class-based OOP.
Hides the form elements default value onFocus
and restores it onBlur unless you change the value.

/* Requirement: Prototype.js

 Usage:
 * new SearchPlay(“search_q”);
 * new SearchPlay(“search_within”);
	

*/

var SearchPlay = Class.create();
SearchPlay.prototype = {

initialize: function(element) { this.element = $(element); this.original_value = this.element.defaultValue; this.element.observe(“focus”, this.focus.bindAsEventListener(this)); this.element.observe(“blur”, this.blur.bindAsEventListener(this)); }, focus: function(event) { if ($F(this.element) == this.original_value) { this.element.value = ‘’; } }, blur: function() { if (!this.element.present()) { this.element.value = this.original_value; } }
};
Comment
  • Mats Lindblad
  • +46 (70) 249 11 24
  • Stockholm, Sweden
  • Geo: +59° 16' 12.53", +18° 7' 26.98"