Created
February 12, 2012 13:49
-
-
Save mrnugget/1808651 to your computer and use it in GitHub Desktop.
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
$(function() { | |
// Writes to 'target' how many chars are left to type in 'input' | |
function text_counter(input, target) { | |
var max = input.attr("maxlength"); | |
input.focus(function() { | |
target.removeClass('invisible'); | |
var left = max - this.value.length; | |
target.text("You have " + left + " characters remaining"); | |
}); | |
input.blur(function() { | |
target.addClass('invisible'); | |
}); | |
input.keyup(function() { | |
var left = max - this.value.length; | |
target.text("You have " + left + " characters remaining"); | |
}); | |
}; | |
// Toggles all checkboxes on the current page | |
var toggleCheckboxes = function { | |
var checkboxes = $("input[type=checkbox]"); | |
checkboxes.each(function() { | |
this.checked = !this.checked; | |
}); | |
}; | |
// Sessions#new - Bind the toggleCheckboxes function to the | |
// "Check-all" checkbox. | |
$("#check-all").change(function() { | |
this.checked = !this.checked; | |
toggleCheckboxes(); | |
}); | |
// Songs#show | |
text_counter($("#tag_name"), $("#tag-input-help")); | |
// When a new tag is submitted, clear and unfocus the input | |
$("#new_tag").live("ajax:beforeSend", function(event,xhr,status){ | |
$('#tag_name').val(''); | |
$('#tag_name').blur(); | |
}); | |
// Users#new and Users#edit | |
text_counter($("#user_name"), $("#user-name-input-help")); | |
text_counter($("#user_password"), $("#user-password-input-help")); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment