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();
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; } }
SearchPlay.prototype = {
};