Last active
December 11, 2015 12:38
-
-
Save nathansmith/4602159 to your computer and use it in GitHub Desktop.
Revisions
-
nathansmith revised this gist
Jan 23, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -42,7 +42,7 @@ var check_all = (function($, window, document, undefined) { // Is this the master checkbox? if (el.hasClass('check-all')) { // Is it checked? if (el.prop('checked')) { // Check all others.prop('checked', true); } -
nathansmith revised this gist
Jan 23, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -37,7 +37,7 @@ var check_all = (function($, window, document, undefined) { } var others = parent.find('input[type="checkbox"]').not('.check-all'); var others_checked = others.filter(':checked'); // Is this the master checkbox? if (el.hasClass('check-all')) { -
nathansmith revised this gist
Jan 23, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -37,7 +37,7 @@ var check_all = (function($, window, document, undefined) { } var others = parent.find('input[type="checkbox"]').not('.check-all'); var others_checked = others.filder(':checked'); // Is this the master checkbox? if (el.hasClass('check-all')) { -
nathansmith revised this gist
Jan 23, 2013 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -44,23 +44,23 @@ var check_all = (function($, window, document, undefined) { // Is it checked? if (el.is(':checked')) { // Check all others.prop('checked', true); } else { // Un-check all others.prop('checked', false); } } // Must be a sibling checkbox else { // Are all siblings checked? if (others.length === others_checked.length) { // Check master master.prop('checked', true); } else { // Un-check master master.prop('checked', false); } } } -
nathansmith revised this gist
Jan 23, 2013 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -55,11 +55,11 @@ var check_all = (function($, window, document, undefined) { else { // Are all siblings checked? if (others.length === others_checked.length) { // Check master master.attr('checked', 'checked'); } else { // Un-check master master.removeAttr('checked'); } } -
nathansmith revised this gist
Jan 23, 2013 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -26,7 +26,7 @@ var check_all = (function($, window, document, undefined) { return { // check_all.init init: function() { // Run on DOM load, and click function determine_checked(el) { var parent = el.closest('dl, ol, table, ul'); var master = parent.find('input[type="checkbox"].check-all'); @@ -41,6 +41,7 @@ var check_all = (function($, window, document, undefined) { // Is this the master checkbox? if (el.hasClass('check-all')) { // Is it checked? if (el.is(':checked')) { // Check all others.attr('checked', 'checked'); -
nathansmith revised this gist
Jan 23, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -28,7 +28,7 @@ var check_all = (function($, window, document, undefined) { init: function() { // Run on DOM load, and click. function determine_checked(el) { var parent = el.closest('dl, ol, table, ul'); var master = parent.find('input[type="checkbox"].check-all'); // Exit, if no "check-all" exists -
nathansmith created this gist
Jan 23, 2013 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,78 @@ /* Use like this (or with <dl>, <ol>, <table>)... <ul> <li> <input type="checkbox" class="check-all" /> </li> <li> <input type="checkbox" /> </li> <li> <input type="checkbox" /> </li> </ul> */ // Module pattern var check_all = (function($, window, document, undefined) { // Kickoff $(document).ready(function() { check_all.init(); }); // Expose publicly return { // check_all.init init: function() { // Run on DOM load, and click. function determine_checked(el) { var parent = el.closest('dl, table, ul'); var master = parent.find('input[type="checkbox"].check-all'); // Exit, if no "check-all" exists if (!master.length) { return; } var others = parent.find('input[type="checkbox"]').not('.check-all'); var others_checked = parent.find('input[type="checkbox"]:checked').not('.check-all'); // Is this the master checkbox? if (el.hasClass('check-all')) { if (el.is(':checked')) { // Check all others.attr('checked', 'checked'); } else { // Un-check all others.removeAttr('checked'); } } // Must be a sibling checkbox else { // Are all siblings checked? if (others.length === others_checked.length) { // Check master checkbox master.attr('checked', 'checked'); } else { // Un-check master checkbox master.removeAttr('checked'); } } } $(document.documentElement).off('click.check_all').on('click.check_all', 'input[type="checkbox"]', function() { var el = $(this); determine_checked(el); }); $('input[type="checkbox"].check-all').each(function() { var el = $(this); determine_checked(el); }); } }; })(jQuery, this, this.document);