Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
djanowski committed Mar 9, 2009
0 parents commit 1c9d8d1
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions ui.watermark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* jQuery Form Watermark
*
* Author: Damian Janowski
* E-mail: damian.janowski@citrusbyte.com
*/

$.widget("ui.watermark", {
init: function() {
var watermark = this;

var form = this.element;

this.elements = $("input:text, textarea", form);

this.elements.focus(this.handlerOff);
this.elements.blur(this.handlerOn);

this.refresh();

$(form).submit(function() {
watermark.elements.each(watermark.handlerOff);
return true;
});
},

refresh: function() {
this.elements.each(this.handlerOn);
},

handlerOn: function() {
if (this.value == '' && this.title && this.title != '') {
$(this).addClass("watermark");
this.value = this.title;
}

return true;
},

handlerOff: function() {
if (this.type == 'text' || this.type == 'textarea') {
if (this.value == this.title && this.title && this.title != '') {
this.value = '';
$(this).removeClass("watermark");
}
}

return true;
}
});

0 comments on commit 1c9d8d1

Please sign in to comment.