Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions src/placeholder_polyfill.jquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,21 @@
animId;
function showPlaceholderIfEmpty(input,options) {
if( input.val() === '' ){
log('placeholder is shown by showPlaceholderIfEmpty()');
input.data('placeholder').removeClass(options.hideClass);
}else{
log('placeholder is hidden by showPlaceholderIfEmpty()');
input.data('placeholder').addClass(options.hideClass);
}
}
function hidePlaceholder(input,options){
log('placeholder is hidden by hidePlaceholder()');
input.data('placeholder').addClass(options.hideClass);
}
function showPlaceholder(input,options){
log('placeholder is shown by showPlaceholder()');
input.data('placeholder').removeClass(options.hideClass);
}
function positionPlaceholder(placeholder,input){
var ta = input.is('textarea');
var pt = parseFloat(input.css('padding-top'));
Expand All @@ -48,10 +55,9 @@
}).offset(offset);
}
function startFilledCheckChange(input,options){
var val = input.val();
(function checkloop(){
animId = requestAnimationFrame(checkloop);
if(input.val() !== val){
if(input.val()){
hidePlaceholder(input,options);
stopCheckChange();
startEmptiedCheckChange(input,options);
Expand All @@ -61,7 +67,11 @@
function startEmptiedCheckChange(input,options){
(function checkloop(){
animId = requestAnimationFrame(checkloop);
showPlaceholderIfEmpty(input,options);
if(!input.val()){
showPlaceholder(input,options);
stopCheckChange();
startFilledCheckChange(input,options);
}
}());
}
function stopCheckChange(){
Expand Down Expand Up @@ -146,8 +156,9 @@
});
input.focusin(onFocusIn);
input.focusout(function(){
showPlaceholderIfEmpty($(this),o.options);
if(!o.options.hideOnFocus){
if(o.options.hideOnFocus){
showPlaceholderIfEmpty($(this),o.options);
} else {
stopCheckChange();
}
});
Expand Down