-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make .placeholder classname configurable #39
Closed
Closed
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1f9ea0e
Adds custom placeholder className option.
cheeaun cfb623f
Fixes silly scoping and uses $.fn.placeholder.className for config.
cheeaun d396b51
Use $.fn.placeholder.className wherever possible.
cheeaun 79bf24d
Only bind domready and unload event (once) when placeholder is called.
cheeaun 5e9201f
Assume the dom is ready by the time .placeholder is called.
cheeaun d35af81
Move and cache some variables.
cheeaun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,31 +15,33 @@ | |
} else { | ||
|
||
$.fn.placeholder = function() { | ||
|
||
$().one('ready', function() { | ||
// Look for forms | ||
$('form').bind('submit.placeholder', function() { | ||
// Clear the placeholder values so they don’t get submitted | ||
var $inputs = $('.' + $.fn.placeholder.className, this).each(clearPlaceholder); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. …so you can use it here… |
||
setTimeout(function() { | ||
$inputs.each(setPlaceholder); | ||
}, 10); | ||
}); | ||
}); | ||
|
||
// Clear placeholder values upon page reload | ||
$(window).one('unload.placeholder', function() { | ||
$('.' + $.fn.placeholder.className).val(''); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could chain these together: |
||
|
||
return this.filter((isInputSupported ? 'textarea' : ':input') + '[placeholder]') | ||
.bind('focus.placeholder', clearPlaceholder) | ||
.bind('blur.placeholder', setPlaceholder) | ||
.trigger('blur.placeholder').end(); | ||
}; | ||
|
||
$.fn.placeholder.className = 'placeholder'; | ||
$.fn.placeholder.input = isInputSupported; | ||
$.fn.placeholder.textarea = isTextareaSupported; | ||
|
||
$(function() { | ||
// Look for forms | ||
$('form').bind('submit.placeholder', function() { | ||
// Clear the placeholder values so they don’t get submitted | ||
var $inputs = $('.placeholder', this).each(clearPlaceholder); | ||
setTimeout(function() { | ||
$inputs.each(setPlaceholder); | ||
}, 10); | ||
}); | ||
}); | ||
|
||
// Clear placeholder values upon page reload | ||
$(window).bind('unload.placeholder', function() { | ||
$('.placeholder').val(''); | ||
}); | ||
|
||
} | ||
|
||
function args(elem) { | ||
|
@@ -55,12 +57,13 @@ | |
} | ||
|
||
function clearPlaceholder() { | ||
var $input = $(this); | ||
if ($input.val() === $input.attr('placeholder') && $input.hasClass('placeholder')) { | ||
var $input = $(this), | ||
placeholderClassName = $.fn.placeholder.className; | ||
if ($input.val() === $input.attr('placeholder') && $input.hasClass(placeholderClassName)) { | ||
if ($input.data('placeholder-password')) { | ||
$input.hide().next().show().focus().attr('id', $input.removeAttr('id').data('placeholder-id')); | ||
} else { | ||
$input.val('').removeClass('placeholder'); | ||
$input.val('').removeClass(placeholderClassName); | ||
} | ||
} | ||
} | ||
|
@@ -69,7 +72,8 @@ | |
var $replacement, | ||
$input = $(this), | ||
$origInput = $input, | ||
id = this.id; | ||
id = this.id, | ||
placeholderClassName = $.fn.placeholder.className; | ||
if ($input.val() === '') { | ||
if ($input.is(':password')) { | ||
if (!$input.data('placeholder-textinput')) { | ||
|
@@ -91,9 +95,9 @@ | |
} | ||
$input = $input.removeAttr('id').hide().prev().attr('id', id).show(); | ||
} | ||
$input.addClass('placeholder').val($input.attr('placeholder')); | ||
$input.addClass(placeholderClassName).val($input.attr('placeholder')); | ||
} else { | ||
$input.removeClass('placeholder'); | ||
$input.removeClass(placeholderClassName); | ||
} | ||
} | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cache
var className = $.fn.placeholder.className;
here please (since it’s used twice in this scope).