jquery.mjs.nestedSortable.js
4 years ago
jquery.ui.touch-punch.min.js
11 years ago
nestedpages-factory.js
3 years ago
nestedpages.bulk-actions.js
4 years ago
nestedpages.check-all.js
9 years ago
nestedpages.clone.js
3 years ago
nestedpages.confirm-delete.js
8 years ago
nestedpages.dropdowns.js
8 years ago
nestedpages.formatter.js
3 years ago
nestedpages.hidden-item-count.js
9 years ago
nestedpages.manual-sync.js
9 years ago
nestedpages.menu-links.js
3 years ago
nestedpages.menu-search.js
4 days ago
nestedpages.menu-toggle.js
8 years ago
nestedpages.modals.js
8 years ago
nestedpages.move-post.js
8 years ago
nestedpages.nesting.js
3 years ago
nestedpages.new-post.js
6 years ago
nestedpages.page-toggle.js
4 years ago
nestedpages.post-search.js
9 years ago
nestedpages.quickedit-link.js
8 years ago
nestedpages.quickedit-post.js
3 years ago
nestedpages.settings-admin-customization.js
6 years ago
nestedpages.settings-reset.js
6 years ago
nestedpages.settings.js
3 years ago
nestedpages.sync-menu-setting.js
8 years ago
nestedpages.tabs.js
6 years ago
nestedpages.trash-with-children.js
6 years ago
nestedpages.trash.js
8 years ago
nestedpages.userprefs-reset.js
7 years ago
nestedpages.wpml.js
8 years ago
nestedpages.check-all.js
91 lines
| 1 | var NestedPages = NestedPages || {}; |
| 2 | |
| 3 | /** |
| 4 | * Check All functionality for Nested Pages |
| 5 | * @package Nested Pages |
| 6 | * @author Kyle Phillips - https://github.com/kylephillips/wp-nested-pages |
| 7 | */ |
| 8 | NestedPages.CheckAll = function() |
| 9 | { |
| 10 | var plugin = this; |
| 11 | var $ = jQuery; |
| 12 | |
| 13 | plugin.activeCheckbox = ""; |
| 14 | |
| 15 | plugin.selectors = { |
| 16 | checkbox : '[data-np-check-all]', |
| 17 | } |
| 18 | |
| 19 | plugin.bindEvents = function() |
| 20 | { |
| 21 | $(document).on('change', plugin.selectors.checkbox, function(){ |
| 22 | plugin.activeCheckbox = $(this); |
| 23 | plugin.toggleCheckboxes(); |
| 24 | }); |
| 25 | $(document).on('change', 'input[type=checkbox]', function(){ |
| 26 | plugin.checkAllStatus($(this)); |
| 27 | }); |
| 28 | } |
| 29 | |
| 30 | plugin.init = function() |
| 31 | { |
| 32 | plugin.bindEvents(); |
| 33 | } |
| 34 | |
| 35 | plugin.toggleCheckboxes = function() |
| 36 | { |
| 37 | var checked = ( $(plugin.activeCheckbox).is(':checked') ) ? true : false; |
| 38 | var name = $(plugin.activeCheckbox).attr('data-np-check-all'); |
| 39 | |
| 40 | var checkboxes = $('*[name="' + name + '"]'); |
| 41 | $.each(checkboxes, function(){ |
| 42 | var row = $(this).parents(NestedPages.selectors.rows); |
| 43 | $(this).prop('checked', checked); |
| 44 | // Uncheck any hidden checkboxes |
| 45 | if ( $(row).hasClass('np-hide') && !$(row).is(':visible') ) { |
| 46 | $(row).find(NestedPages.selectors.bulkActionsCheckbox).prop('checked', false) |
| 47 | }; |
| 48 | }); |
| 49 | |
| 50 | plugin.toggleCheckAll(); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Toggle the "Partial" class for the checkall checkbox |
| 55 | */ |
| 56 | plugin.toggleCheckAll = function() |
| 57 | { |
| 58 | var name = $(plugin.activeCheckbox).attr('data-np-check-all'); |
| 59 | |
| 60 | var checkboxes_total = $('*[name="' + name + '"]').length; |
| 61 | var hidden_checkboxes = $('.np-hide').find(NestedPages.selectors.bulkActionsCheckbox).length; |
| 62 | var hidden_checkboxes_visible = $('.np-hide:visible').find(NestedPages.selectors.bulkActionsCheckbox).length; |
| 63 | |
| 64 | checkboxes_total = ( checkboxes_total - hidden_checkboxes ) + hidden_checkboxes_visible; |
| 65 | |
| 66 | var checkboxes_checked = $('*[name="' + name + '"]:checked').length; |
| 67 | |
| 68 | if ( checkboxes_total == checkboxes_checked ){ |
| 69 | $(plugin.activeCheckbox).prop('checked', true); |
| 70 | $(plugin.activeCheckbox).removeClass('check-all-partial'); |
| 71 | return; |
| 72 | } |
| 73 | if ( checkboxes_checked > 0 ){ |
| 74 | $(plugin.activeCheckbox).addClass('check-all-partial'); |
| 75 | return; |
| 76 | } |
| 77 | $(plugin.activeCheckbox).attr('checked', false); |
| 78 | $(plugin.activeCheckbox).removeClass('check-all-partial'); |
| 79 | } |
| 80 | |
| 81 | plugin.checkAllStatus = function(checkbox) |
| 82 | { |
| 83 | var name = $(checkbox).attr('name'); |
| 84 | var toggleAllCheckbox = $('*[data-np-check-all="' + name + '"]'); |
| 85 | if ( toggleAllCheckbox.length === 0 ) return; |
| 86 | plugin.activeCheckbox = $(toggleAllCheckbox)[0]; |
| 87 | plugin.toggleCheckAll(); |
| 88 | } |
| 89 | |
| 90 | return plugin.init(); |
| 91 | } |