Upgraded infield labels plugin to the latest version. Updated invocation to opt-in to pollling at the same duration you were using before, 100ms
This commit is contained in:
parent
2a48aa322d
commit
b8c1a4da3e
|
@ -1,13 +1,14 @@
|
||||||
/**
|
/*
|
||||||
* @license In-Field Label jQuery Plugin
|
* jquery.infieldlabel
|
||||||
* http://fuelyourcoding.com/scripts/infield.html
|
* A simple jQuery plugin for adding labels that sit over a form field and fade away when the fields are populated.
|
||||||
*
|
*
|
||||||
* Copyright (c) 2009-2010 Doug Neiner
|
* Copyright (c) 2009 - 2013 Doug Neiner <doug@dougneiner.com> (http://code.dougneiner.com)
|
||||||
* Dual licensed under the MIT and GPL licenses.
|
* Source: https://github.com/dcneiner/In-Field-Labels-jQuery-Plugin
|
||||||
* Uses the same license as jQuery, see:
|
* Dual licensed MIT or GPL
|
||||||
* http://docs.jquery.com/License
|
* MIT (http://www.opensource.org/licenses/mit-license)
|
||||||
|
* GPL (http://www.opensource.org/licenses/gpl-license)
|
||||||
*
|
*
|
||||||
* @version 0.1.6
|
* @version 0.1.3
|
||||||
*/
|
*/
|
||||||
(function ($) {
|
(function ($) {
|
||||||
|
|
||||||
|
@ -27,6 +28,8 @@
|
||||||
base.showing = true;
|
base.showing = true;
|
||||||
|
|
||||||
base.init = function () {
|
base.init = function () {
|
||||||
|
var initialSet;
|
||||||
|
|
||||||
// Merge supplied options with default options
|
// Merge supplied options with default options
|
||||||
base.options = $.extend({}, $.InFieldLabels.defaultOptions, options);
|
base.options = $.extend({}, $.InFieldLabels.defaultOptions, options);
|
||||||
|
|
||||||
|
@ -36,6 +39,9 @@
|
||||||
if (base.$field.val() !== "") {
|
if (base.$field.val() !== "") {
|
||||||
base.$label.hide();
|
base.$label.hide();
|
||||||
base.showing = false;
|
base.showing = false;
|
||||||
|
} else {
|
||||||
|
base.$label.show();
|
||||||
|
base.showing = true;
|
||||||
}
|
}
|
||||||
}, 200);
|
}, 200);
|
||||||
|
|
||||||
|
@ -47,23 +53,28 @@
|
||||||
// Use of a namespace (.infieldlabel) allows us to
|
// Use of a namespace (.infieldlabel) allows us to
|
||||||
// unbind just this method later
|
// unbind just this method later
|
||||||
base.hideOnChange(e);
|
base.hideOnChange(e);
|
||||||
}).bind('paste', function (e) {
|
}).bind('paste', function () {
|
||||||
// Since you can not paste an empty string we can assume
|
// Since you can not paste an empty string we can assume
|
||||||
// that the fieldis not empty and the label can be cleared.
|
// that the fieldis not empty and the label can be cleared.
|
||||||
base.setOpacity(0.0);
|
base.setOpacity(0.0);
|
||||||
}).change(function (e) {
|
}).change(function () {
|
||||||
base.checkForEmpty();
|
base.checkForEmpty();
|
||||||
}).bind('onPropertyChange', function () {
|
}).bind('onPropertyChange', function () {
|
||||||
base.checkForEmpty();
|
base.checkForEmpty();
|
||||||
}).bind('keyup.infieldlabel', function () {
|
}).bind('keyup.infieldlabel', function () {
|
||||||
base.checkForEmpty()
|
base.checkForEmpty();
|
||||||
});
|
});
|
||||||
setInterval(function(){
|
|
||||||
if(base.$field.val() != ""){
|
if ( base.options.pollDuration > 0 ) {
|
||||||
base.$label.hide();
|
initialSet = setInterval( function () {
|
||||||
base.showing = false;
|
if (base.$field.val() !== "") {
|
||||||
};
|
base.$label.hide();
|
||||||
},100);
|
base.showing = false;
|
||||||
|
clearInterval( initialSet );
|
||||||
|
}
|
||||||
|
}, base.options.pollDuration );
|
||||||
|
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// If the label is currently showing
|
// If the label is currently showing
|
||||||
|
@ -92,7 +103,7 @@
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
base.prepForShow = function (e) {
|
base.prepForShow = function () {
|
||||||
if (!base.showing) {
|
if (!base.showing) {
|
||||||
// Prepare for a animate in...
|
// Prepare for a animate in...
|
||||||
base.$label.css({opacity: 0.0}).show();
|
base.$label.css({opacity: 0.0}).show();
|
||||||
|
@ -127,37 +138,39 @@
|
||||||
|
|
||||||
$.InFieldLabels.defaultOptions = {
|
$.InFieldLabels.defaultOptions = {
|
||||||
fadeOpacity: 0.5, // Once a field has focus, how transparent should the label be
|
fadeOpacity: 0.5, // Once a field has focus, how transparent should the label be
|
||||||
fadeDuration: 300 // How long should it take to animate from 1.0 opacity to the fadeOpacity
|
fadeDuration: 300, // How long should it take to animate from 1.0 opacity to the fadeOpacity
|
||||||
|
pollDuration: 0, // If set to a number greater than zero, this will poll until content is detected in a field
|
||||||
|
enabledInputTypes: [ "text", "search", "tel", "url", "email", "password", "number", "textarea" ]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
$.fn.inFieldLabels = function (options) {
|
$.fn.inFieldLabels = function (options) {
|
||||||
|
var allowed_types = options && options.enabledInputTypes || $.InFieldLabels.defaultOptions.enabledInputTypes;
|
||||||
|
|
||||||
return this.each(function () {
|
return this.each(function () {
|
||||||
// Find input or textarea based on for= attribute
|
// Find input or textarea based on for= attribute
|
||||||
// The for attribute on the label must contain the ID
|
// The for attribute on the label must contain the ID
|
||||||
// of the input or textarea element
|
// of the input or textarea element
|
||||||
var for_attr = $(this).attr('for'), $field;
|
var for_attr = $(this).attr('for'), field, restrict_type;
|
||||||
if (!for_attr) {
|
if (!for_attr) {
|
||||||
return; // Nothing to attach, since the for field wasn't used
|
return; // Nothing to attach, since the for field wasn't used
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find the referenced input or textarea element
|
// Find the referenced input or textarea element
|
||||||
$field = $(
|
field = document.getElementById( for_attr );
|
||||||
"input#" + for_attr + "[type='text']," +
|
if ( !field ) {
|
||||||
"input#" + for_attr + "[type='search']," +
|
return; // No element found
|
||||||
"input#" + for_attr + "[type='tel']," +
|
}
|
||||||
"input#" + for_attr + "[type='url']," +
|
|
||||||
"input#" + for_attr + "[type='email']," +
|
|
||||||
"input#" + for_attr + "[type='password']," +
|
|
||||||
"textarea#" + for_attr
|
|
||||||
);
|
|
||||||
|
|
||||||
if ($field.length === 0) {
|
// Restrict input type
|
||||||
|
restrict_type = $.inArray( field.type, allowed_types );
|
||||||
|
|
||||||
|
if ( restrict_type === -1 && field.nodeName !== "TEXTAREA" ) {
|
||||||
return; // Again, nothing to attach
|
return; // Again, nothing to attach
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only create object for input[text], input[password], or textarea
|
// Only create object for matched input types and textarea
|
||||||
(new $.InFieldLabels(this, $field[0], options));
|
(new $.InFieldLabels(this, field, options));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -643,7 +643,9 @@ $(document).ready(function(){
|
||||||
$('#pass2').showPassword();
|
$('#pass2').showPassword();
|
||||||
|
|
||||||
//use infield labels
|
//use infield labels
|
||||||
$("label.infield").inFieldLabels();
|
$("label.infield").inFieldLabels({
|
||||||
|
pollDuration: 100
|
||||||
|
});
|
||||||
|
|
||||||
var checkShowCredentials = function() {
|
var checkShowCredentials = function() {
|
||||||
var empty = false;
|
var empty = false;
|
||||||
|
|
Loading…
Reference in New Issue