Permalink
Browse files

jQuery 1.3 support and fix for onblur not clearing field

The function event map isn't available in jq 1.3, so change it to a chain. The field should be considered unchanged if the value is empty, so the placeholder will appear, and vice versa.
  • Loading branch information...
1 parent 61b741a commit 73f4d1e55c1a851de131b32ad291792d4deae8b0 @scarlac scarlac committed with danbentley Jul 5, 2011
Showing with 7 additions and 11 deletions.
  1. +7 −11 js/jquery.placeholder.js
View
@@ -31,17 +31,13 @@
var placeholderText = input.attr('placeholder');
setPlaceholderOrFlagChanged(input, placeholderText);
- input.bind({
- focus: function(e) {
- if (input.data('changed') === true) return;
- if (input.val() === placeholderText) input.val('');
- },
- blur: function(e) {
- if (input.val() === '') input.val(placeholderText);
- },
- change: function(e) {
- if (input.val() !== '') input.data('changed', true);
- }
+ input.focus(function(e) {
+ if (input.data('changed') === true) return;
+ if (input.val() === placeholderText) input.val('');
+ }).blur(function(e) {
+ if (input.val() === '') input.val(placeholderText);
+ }).change(function(e) {
+ input.data('changed', input.val() !== '');
});
}

0 comments on commit 73f4d1e

Please sign in to comment.