Created
April 25, 2015 14:35
-
-
Save horaciod/47bdb231e9208074675d to your computer and use it in GitHub Desktop.
boton borrado de campos bootstrap
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
$ = jQuery | |
$.fn.inputClear = (options={}) -> | |
@each (i, input) -> | |
input = $(input) | |
clearButton = input.data("clear-button") | |
init = -> | |
icon = options.icon ? "glyphicon-remove" | |
iconHtml = if icon | |
"""<span class="glyphicon #{icon}"></span>""" | |
else | |
"" | |
html = options.html || "" | |
html = " #{html}" if icon && options.html | |
clearButton = $("""<a href="#">#{iconHtml}#{html}</a>""") | |
.css | |
display: "inline" | |
cursor: "pointer" | |
color: "#888" | |
position: "absolute" | |
top: input.position().top | |
left: input.position().left + input.outerWidth() | |
margin: "8px 0px 0px -20px" | |
.on "click", (e) -> | |
e.preventDefault() | |
input | |
.val("") | |
.trigger "change" | |
.focus() | |
showHideButton() | |
input.data("clear-button", clearButton) | |
.on("keyup", showHideButton) | |
.after(clearButton) | |
showHideButton() | |
showHideButton = -> | |
clearButton.toggle(input.val() != "") | |
init() unless clearButton? | |
this |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment