Last active
January 18, 2016 18:29
-
-
Save ABM-Dan/595be28c5b3e28bb8070 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Implements a works-as-you-expect version of .change on radio buttons | |
(function ($) { | |
$.fn.onTrueChange = function (callable) { | |
return this.each(function () { | |
var caller = $(this); | |
caller.data('cached-value', caller.is(':checked')); | |
return caller.closest('form').find('input[name="' + caller.attr('name') + '"]').change(function(){ | |
if (caller.is(':checked') != caller.data('cached-value')){ | |
caller.data('cached-value', caller.is(':checked')); | |
callable.call(caller); | |
} | |
}); | |
}); | |
}; | |
}(jQuery)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment