Sha256: 89b46fa46949bfa6e5f68e73b7ea2de31d92e067d8ada2ec8a4d0c861a825997
Contents?: true
Size: 1.32 KB
Versions: 22
Compression:
Stored size: 1.32 KB
Contents
class CheckboxToggler { constructor(options, container){ this.options = options; this.container = container; this._init(); this._bind(); } option(_key, _value) { } _init() { if (!this.container) { throw new Error('Container element not found'); } else { this.$container = $(this.container); } if (!this.$container.find('.toggle_all').length) { throw new Error('"toggle all" checkbox not found'); } else { this.toggle_all_checkbox = this.$container.find('.toggle_all'); } this.checkboxes = this.$container.find(':checkbox').not(this.toggle_all_checkbox); } _bind() { this.checkboxes.change(event => this._didChangeCheckbox(event.target)); this.toggle_all_checkbox.change(() => this._didChangeToggleAllCheckbox()); } _didChangeCheckbox(_checkbox){ const numChecked = this.checkboxes.filter(':checked').length; const allChecked = numChecked === this.checkboxes.length; const someChecked = (numChecked > 0) && (numChecked < this.checkboxes.length); this.toggle_all_checkbox.prop({ checked: allChecked, indeterminate: someChecked }); } _didChangeToggleAllCheckbox() { const setting = this.toggle_all_checkbox.prop('checked'); this.checkboxes.prop({ checked: setting }); return setting; } } export default CheckboxToggler;
Version data entries
22 entries across 22 versions & 2 rubygems