diff --git a/Docs/Delegators/Delegator.CheckAllOrNone.md b/Docs/Delegators/Delegator.CheckAllOrNone.md index c079108..64f5dfa 100644 --- a/Docs/Delegators/Delegator.CheckAllOrNone.md +++ b/Docs/Delegators/Delegator.CheckAllOrNone.md @@ -1,9 +1,11 @@ -Delegator Triggers: checkAll, checkNone +Delegator Triggers: checkAll, checkNone, checkToggleAll ======================= Provides click event delegators for selecting or deselecting a group of checkboxes. -### Example +### checkAll, checkNone + +#### Example
checkAll @@ -16,9 +18,49 @@ Provides click event delegators for selecting or deselecting a group of checkbox
-### Options +#### Options + +* targets - (*string*; **required**) a selector that will return the inputs to check/uncheck. + +### checkToggle + +#### Example +
+ + + + + + +
+ +#### Options * targets - (*string*; **required**) a selector that will return the inputs to check/uncheck. +* class - (*string*; **optional**) a class to apply to the targets' classTarget. +* classTarget - (*string*; **optional**) a selector relative to the targets to apply *class* to. ### See Also diff --git a/Source/Delegators/Delegator.CheckAllOrNone.js b/Source/Delegators/Delegator.CheckAllOrNone.js index 63fbdd7..8b71dfb 100644 --- a/Source/Delegators/Delegator.CheckAllOrNone.js +++ b/Source/Delegators/Delegator.CheckAllOrNone.js @@ -27,6 +27,34 @@ Delegator.register('click', { if (targets.length) targets.set('checked', false); else api.warn('There were no inputs found to uncheck.'); } + }, + + 'checkToggleAll': { + require: ['targets'], + handler: function(event, link, api){ + var classTarget = api.get('classTarget'); + var classForTarget = api.get('class'); + var targets = link.getElements(api.get('targets')); + if (targets.length) { + if (link.get('data-state') == undefined) api.error('Must specify an initial state as data-state.'); + if (link.get('data-state') == '1') { + targets.set('checked', false); + link.set('data-state', '0'); + if (classTarget && classForTarget) { + if (!targets.getElement(classTarget)) api.fail('Could not find classTarget: ' + classTarget) + targets.getElement(classTarget).removeClass(classForTarget); + } + } else { + targets.set('checked', true); + link.set('data-state', '1'); + if (classTarget && classForTarget) { + if (!targets.getElement(classTarget)) api.fail('Could not find classTarget: ' + classTarget) + targets.getElement(classTarget).addClass(classForTarget); + } + } + } + else api.warn('There were no inputs found to uncheck.'); + } } }); \ No newline at end of file