Created
January 30, 2013 17:01
-
-
Save DominicFinn/4674680 to your computer and use it in GitHub Desktop.
A basic check box manager that lets you switch all the checkboxes with a class of 'checkboxElementsClass' on or off.
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
| var checkBoxManager = { | |
| allSelected: false, | |
| checkBoxes: null, | |
| init: function ($checkBoxes) { | |
| var that = this; | |
| that.checkBoxes = $checkBoxes; | |
| }, | |
| toggleSelect: function () { | |
| var that = this; | |
| var changeCheckBoxAttribute = function (checked) { | |
| that.checkBoxes.each(function () { | |
| $(this).attr('checked', checked); | |
| }); | |
| }; | |
| if (that.allSelected) { | |
| changeCheckBoxAttribute(false); | |
| that.allSelected = false; | |
| } else { | |
| changeCheckBoxAttribute(true); | |
| that.allSelected = true; | |
| } | |
| } | |
| } | |
| //example of using | |
| $('document').ready(function () { | |
| checkBoxManager.init($('.checkboxElementsClass')); | |
| $('.selectAllCheckBox').click(function (e) { | |
| checkBoxManager.toggleSelect(); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment