Skip to content

Commit

Permalink
Fixed deselectable radio buttons to eliminate the double clicking nee…
Browse files Browse the repository at this point in the history
…ded to select a radio button in certain scenarios.
  • Loading branch information
Paul Jackson authored and Paul Jackson committed Oct 16, 2012
1 parent 98ca3e7 commit 704c938
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
2 changes: 1 addition & 1 deletion build/js/pe-ap-min.js

Large diffs are not rendered by default.

Empty file.
43 changes: 31 additions & 12 deletions src/js/workers/deselectradio.js
Expand Up @@ -16,23 +16,42 @@
type : 'plugin',
depends : [],
_exec : function (elm) {
var radio = $('input[type="radio"]:not(.deselectable, .deselect-off)').attr('role', 'radio').attr('aria-checked', 'false').addClass('deselectable');
radio.filter(':checked').attr('aria-checked', 'true');
radio.closest('fieldset').attr('role', 'radiogroup');
radio.on("click vclick", function () {
var $this = $(this);
if ($this.attr('aria-checked') === 'true') {
$this.prop('checked', false).attr('aria-checked', 'false');
} else {
$this.closest('fieldset').find('input[type="radio"]').prop('checked', false).attr('aria-checked', 'false');
$this.prop('checked', true).attr('aria-checked', 'true');
var inputs = document.getElementsByTagName('input'),
inputs_len = inputs.length,
input;
// Functionality can be disabled by applying deselect-off to the radio button
while (inputs_len--) {
input = inputs[inputs_len];
if (input.type === 'radio' && input.className.indexOf('deselect-off') === -1) {
input.className += ' deselectable' + (input.checked ? ' checked' : '');
}
}
$(document).on('click vclick', 'input[type="radio"].deselectable', function () {
if (this.className.indexOf(' checked') !== -1) { // Already selected so deselect and remember that it is no longer selected
this.checked = false;
this.className = this.className.replace(' checked', '');
} else { // Not selected previously so remember that it is now selected
var name = this.getAttribute('name'),
inputs,
input,
inputs_len;
if (name !== undefined) {
inputs = document.getElementsByName(name);
inputs_len = inputs.length;
while (inputs_len--) {
input = inputs[inputs_len];
if (input.className.indexOf(' checked') !== -1) {
input.className = input.className.replace(' checked', '');
}
}
this.className += ' checked';
}
}
});

return elm;
} // end of exec
};
window.pe = _pe;
return _pe;
}
(jQuery));
(jQuery));

0 comments on commit 704c938

Please sign in to comment.