Created
October 25, 2012 05:23
-
-
Save arkadylukashov/3950536 to your computer and use it in GitHub Desktop.
input clearize (a11.fixed)
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
/** > inputClearize (Умная очистка инпутов) [применяется для всех инпутов, у которых есть аттрибут rel, равный 'cleared'][Также должен рядом по DOM быть расположен элемент с классом 'clearInput' для опустошения value инпута] @link https://gist.github.com/3950536 */ | |
(function($){ | |
var $e = $('input[rel~="cleared"]') | |
$e.on('keyup', function(){ | |
var proxy = this, | |
value = this.value, | |
isPlace = $(this).data('placeholder') || false, | |
onClicker = $( $(this).siblings('.clearInput') ), | |
visibilityValue = ((value.length > 0 && !isPlace) || (value.length !== isPlace.length)) ? 'visible' : 'hidden'; | |
onClicker.css({visibility: visibilityValue}) | |
onClicker.on('click', function() { | |
$(proxy).val('').trigger('blur') | |
$(this).css({visibility: 'hidden'}) | |
}) | |
}); | |
$e.trigger('keyup') | |
})(jQuery) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment