PluginProbe ʕ •ᴥ•ʔ
Nested Pages / 3.2.14
Nested Pages v3.2.14
3.3.1 3.2.15 3.2.14 3.1.8 3.1.9 3.2.0 3.2.1 3.2.10 3.2.11 3.2.12 3.2.13 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 trunk 1.0 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.3.0 1.3.1 1.3.10 1.3.11 1.3.12 1.3.13 1.3.14 1.3.15 1.3.2 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.3.1 1.6.3.2 1.6.4 1.6.5 1.6.5.1 1.6.5.2 1.6.6 1.6.7 1.6.8 1.7.0 1.7.1 2.0.1 2.0.2 2.0.3 2.0.4 3.0.1 3.0.10 3.0.11 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.17 3.1.18 3.1.19 3.1.2 3.1.20 3.1.21 3.1.22 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7
wp-nested-pages / assets / js / lib / nestedpages.bulk-actions.js
wp-nested-pages / assets / js / lib Last commit date
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 5 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 4 years ago nestedpages.menu-search.js 1 month 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 4 years ago nestedpages.settings-admin-customization.js 7 years ago nestedpages.settings-reset.js 7 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.bulk-actions.js
222 lines
1 var NestedPages = NestedPages || {};
2
3 /**
4 * Bulk Actions for Nested View
5 * @package Nested Pages
6 * @author Kyle Phillips - https://github.com/kylephillips/wp-nested-pages
7 */
8 NestedPages.BulkActions = function()
9 {
10 var plugin = this;
11 var $ = jQuery;
12
13 plugin.selectedNumber = 0;
14 plugin.selectedLinks = [];
15 plugin.selectedPosts = []; // array
16
17 plugin.bindEvents = function()
18 {
19 $(document).on('change', NestedPages.selectors.bulkActionsCheckbox, function(){
20 plugin.toggleBulkForm();
21 });
22 $(document).on('submit', NestedPages.selectors.bulkActionsForm, function(e){
23 if ( $('select[name=np_bulk_action]').val() === 'edit' ){
24 e.preventDefault();
25 plugin.toggleBulkEdit(true);
26 }
27 });
28 $(document).on('click', NestedPages.selectors.bulkEditRemoveItem, function(e){
29 e.preventDefault();
30 var id = $(this).siblings('input[type=hidden]').val();
31 plugin.uncheckBulkItem(id);
32 });
33 $(document).on('click', NestedPages.selectors.bulkEditCancel, function(e){
34 e.preventDefault();
35 plugin.uncheckAllBulkItems();
36 });
37 }
38
39 /**
40 * Toggle the Bulk Actions Form & Populate the Hidden ID Fields for posts and redirects
41 */
42 plugin.toggleBulkForm = function()
43 {
44 var checked = false;
45 var checked_ids = '';
46 var checked_redirect_ids = '';
47 plugin.selectedPosts = [];
48 plugin.selectedLinks = [];
49 $.each($(NestedPages.selectors.bulkActionsCheckbox), function(){
50 if ( $(this).is(':checked') ) {
51 var row = $(this).parents(NestedPages.selectors.rows);
52 checked = true;
53 if ( !$(this).parent('div').hasClass('np-check-all') && !$(row).hasClass('post-type-np-redirect') ) checked_ids += $(this).val() + ',';
54 if ( $(row).hasClass('post-type-np-redirect') ) {
55 checked_redirect_ids += $(this).val() + ',';
56 plugin.selectedLinks.push($(this).val());
57 }
58 if ( $(this).attr('data-np-post-type') !== 'np-redirect' && !$(this).parent('div').hasClass('np-check-all') ){
59 var post = [];
60 post['title'] = $(this).attr('data-np-bulk-checkbox');
61 post['id'] = $(this).val();
62 plugin.selectedPosts.push(post);
63 }
64 }
65 });
66 plugin.setBulkEditPosts();
67 plugin.toggleEditOption();
68 plugin.toggleLinkCountAlert();
69 if ( checked ){
70 $(NestedPages.selectors.bulkActionsForm).show();
71 $(NestedPages.selectors.bulkActionsIds).val(checked_ids);
72 $(NestedPages.selectors.bulkActionRedirectIds).val(checked_redirect_ids);
73 plugin.setSelectedNumber();
74 return;
75 }
76 $(NestedPages.selectors.bulkActionsIds).val('');
77 $(NestedPages.selectors.bulkActionsForm).hide();
78 }
79
80 /**
81 * Set the Posts for Bulk Edit
82 */
83 plugin.setBulkEditPosts = function()
84 {
85 var html = '';
86 for ( var i = 0; i < plugin.selectedPosts.length; i++ ){
87 html += '<li><a href="#" class="np-remove" data-np-remove-bulk-item>&times;</a>';
88 html += plugin.selectedPosts[i].title;
89 html += '<input type="hidden" name="post_ids[]" value="' + plugin.selectedPosts[i].id + '"></li>';
90 }
91 $(NestedPages.selectors.bulkEditTitles).html(html);
92 }
93
94 /**
95 * Uncheck a bulk item
96 */
97 plugin.uncheckBulkItem = function(id)
98 {
99 $.each($(NestedPages.selectors.bulkActionsCheckbox), function(){
100 if ( $(this).val() == id ) {
101 $(this).prop('checked', false).change();
102 }
103 });
104 // Hide the form if all posts are removed
105 if ( $(NestedPages.selectors.bulkEditRemoveItem).length === 0 ){
106 plugin.toggleBulkEdit(false);
107 }
108 }
109
110 /**
111 * Uncheck all bulk items
112 */
113 plugin.uncheckAllBulkItems = function()
114 {
115 $.each($(NestedPages.selectors.bulkActionsCheckbox), function(){
116 $(this).prop('checked', false).change();
117 });
118 plugin.toggleBulkEdit(false);
119 }
120
121 /**
122 * Set the number of total selected
123 */
124 plugin.setSelectedNumber = function()
125 {
126 var checkedLength = $(NestedPages.selectors.bulkActionsCheckbox + ':checked').not('.np-check-all input').length;
127 var option = $(NestedPages.selectors.bulkActionsForm).find('select option').first();
128 $(option).text(nestedpages.bulk_actions + ' (' + checkedLength + ')');
129 }
130
131 /**
132 * Toggle the edit option to disabled if no post checkboxes are checked
133 * Prevents opening the bulk edit form with only np-redirects checked
134 */
135 plugin.toggleEditOption = function()
136 {
137 var checkedLength = $(NestedPages.selectors.bulkActionsCheckbox + ':checked').not('.np-check-all input').not('.np-redirect-bulk').length;
138 var option = $(NestedPages.selectors.bulkActionsForm).find('select option[value=edit]');
139 if ( checkedLength === 0 ){
140 $(option).prop('disabled', true);
141 $(NestedPages.selectors.bulkActionsForm).find('select option').first().prop('selected', true);
142 plugin.toggleBulkEdit(false);
143 return;
144 }
145 $(option).prop('disabled', false);
146 }
147
148 /**
149 * Toggle the bulk edit form
150 */
151 plugin.toggleBulkEdit = function(visible)
152 {
153 plugin.toggleLinkCountAlert();
154 if ( visible ){
155 plugin.disableParentOptions();
156 $(NestedPages.selectors.bulkEditForm).show();
157 $(NestedPages.selectors.bulkActionsForm).hide();
158 plugin.setWPSuggest();
159 return;
160 }
161 $(NestedPages.selectors.bulkEditForm).hide();
162 $(NestedPages.selectors.bulkActionsForm).show();
163 $(NestedPages.selectors.bulkEditLinkCount).parent('div').hide();
164 $(NestedPages.selectors.bulkActionsForm).find('select option').first().text(nestedpages.bulk_actions);
165 plugin.resetBulkEditFields();
166 }
167
168 /**
169 * Toggle the bulk edit link count alert
170 */
171 plugin.toggleLinkCountAlert = function()
172 {
173 var selectedLinkCount = plugin.selectedLinks.length;
174 if ( selectedLinkCount === 0 ) {
175 $(NestedPages.selectors.bulkEditLinkCount).parent('div').hide();
176 return;
177 }
178 $(NestedPages.selectors.bulkEditLinkCount).parent('div').show();
179 }
180
181 /**
182 * Set parent options to disabled for selected posts
183 */
184 plugin.disableParentOptions = function()
185 {
186 var selectElement = $(NestedPages.selectors.bulkEditForm).find('select[name=post_parent]');
187 for ( var i = 0; i < plugin.selectedPosts.length; i++ )
188 {
189 $(selectElement).find('option[value=' + plugin.selectedPosts[i].id + ']').attr('disabled', true);
190 }
191 }
192
193 /**
194 * Initialize WP Auto Suggest on Flat Taxonomy fields
195 */
196 plugin.setWPSuggest = function()
197 {
198 var tagfields = $(NestedPages.selectors.bulkEditForm).find('[data-autotag]');
199 $.each(tagfields, function(i, v){
200 var taxonomy = $(this).attr('data-taxonomy');
201 $(this).suggest(ajaxurl + '?action=ajax-tag-search&tax=' + taxonomy , {multiple:true, multipleSep: ","});
202 });
203 }
204
205 /**
206 * Clear out the bulk edit fields
207 */
208 plugin.resetBulkEditFields = function()
209 {
210 var selectFields = $(NestedPages.selectors.bulkEditForm).find('select');
211 $.each(selectFields, function(){
212 $(this).find('option').first().prop('selected', true);
213 $(this).find('option').removeAttr('disabled');
214 });
215 var categoryChecklists = $(NestedPages.selectors.bulkEditForm).find('.cat-checklist');
216 $.each(categoryChecklists, function(){
217 $(this).find('input[type=checkbox]').prop('checked', false);
218 });
219 }
220
221 return plugin.bindEvents();
222 }