Skip to content

Commit

Permalink
Some more optimizations thanks to my -ot homies
Browse files Browse the repository at this point in the history
  • Loading branch information
mathiasbynens committed Oct 5, 2010
1 parent bcd5ce4 commit bd6b797
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
38 changes: 19 additions & 19 deletions jquery.placeholder.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
*/
;(function($) {

if ('placeholder' in document.createElement('input')) {
$.fn.placeholder = function() {
return this;
};
return;
}

function args($elem) {
// Get attributes string from outerHTML
var html = $('<div>').append($elem.clone()).html().replace(/<(\w+)\s+(.*)>/, '$2'),
Expand All @@ -29,9 +36,6 @@
}
}

// Made this a function, because we actually need it on two different occasions:
// 1) Once when the DOM is loaded;
// 2) Once every time the focusout() is triggered.
function setPlaceholder(elem) {
var $replacement,
$elem = $(this);
Expand All @@ -52,28 +56,24 @@
}
}

// Look for forms
$('form').bind('submit.placeholder', function() {
// Clear the placeholder values so they don’t get submitted
$('.placeholder', this).val('');
$(function() {
// Look for forms
$('form').bind('submit.placeholder', function() {
// Clear the placeholder values so they don’t get submitted
$('.placeholder', this).val('');
});
});

// Clear placeholder values upon page reload
$(window).bind('unload.placeholder', function() {
$('.placeholder').val('');
});

if ('placeholder' in document.createElement('input')) {
$.fn.placeholder = function() {
return this;
};
} else {
$.fn.placeholder = function() {
return this.filter(':input[placeholder]').bind({
'focus.placeholder': onFocus,
'blur.placeholder': setPlaceholder
}).trigger('blur.placeholder').end();
};
}
$.fn.placeholder = function() {
return this.filter(':input[placeholder]').bind({
'focus.placeholder': onFocus,
'blur.placeholder': setPlaceholder
}).trigger('blur.placeholder').end();
};

})(jQuery);
2 changes: 1 addition & 1 deletion jquery.placeholder.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bd6b797

Please sign in to comment.