Skip to content

Instantly share code, notes, and snippets.

@khalid-s
Created October 31, 2016 20:16
Show Gist options
  • Select an option

  • Save khalid-s/418d24523679f6036175807ea8c35b72 to your computer and use it in GitHub Desktop.

Select an option

Save khalid-s/418d24523679f6036175807ea8c35b72 to your computer and use it in GitHub Desktop.
Single selectable checkbox snippet
/**
* Created by iKNSA.
* Author: Khalid Sookia <khalidsookia@gmail.com>
* Date: 31/10/16
* Time: 20:36
*/
'use strict';
var SINGLE_SELECTABLE_CHECKBOX = {
manageCheckboxSelection: function (event) {
$(event.target).siblings().attr('checked', false);
},
init: function () {
$('body').on('singleSelectableCheckboxChange', function () {
var activeCheckbox = $('.single-selectable-checkbox:checked');
if (activeCheckbox.length) {
$('body').trigger('singleSelectableCheckboxIsChecked');
} else {
$('body').trigger('singleSelectableCheckboxIsNotChecked');
}
});
$('.single-selectable-checkbox').change(function (event) {
SINGLE_SELECTABLE_CHECKBOX.manageCheckboxSelection(event);
$('body').trigger('singleSelectableCheckboxChange');
});
}
};
SINGLE_SELECTABLE_CHECKBOX.init();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment