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
1 year 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.trash.js
76 lines
| 1 | /** |
| 2 | * Empty Trash Functionality |
| 3 | * @package Nested Pages |
| 4 | * @author Kyle Phillips - https://github.com/kylephillips/wp-nested-pages |
| 5 | */ |
| 6 | jQuery(document).ready(function(){ |
| 7 | new NestedPagesTrash; |
| 8 | }); |
| 9 | |
| 10 | var NestedPagesTrash = function() |
| 11 | { |
| 12 | var plugin = this; |
| 13 | var $ = jQuery; |
| 14 | |
| 15 | // DOM Selectors |
| 16 | plugin.trashButton = '.np-empty-trash'; // Trash Link |
| 17 | plugin.confirmButton = '.np-trash-confirm'; // Confirm button in modal |
| 18 | plugin.warningModal = '#np-trash-modal'; // Modal with empty confirmation |
| 19 | plugin.errorAlert = '#np-error'; // Alert Error Notification |
| 20 | plugin.loadingIndicator = '#nested-loading'; // Loading Indication |
| 21 | plugin.trashLinks = '.np-trash-links'; |
| 22 | plugin.postType = $('#np-trash-posttype').val(); |
| 23 | |
| 24 | // JS Data |
| 25 | plugin.nonce = nestedpages.np_nonce; |
| 26 | plugin.formAction = 'npEmptyTrash'; |
| 27 | |
| 28 | plugin.bindEvents = function(){ |
| 29 | $(document).on('click', plugin.confirmButton, function(e){ |
| 30 | e.preventDefault(); |
| 31 | plugin.confirmEmpty(); |
| 32 | }); |
| 33 | } |
| 34 | |
| 35 | // Confirm Trash Empty |
| 36 | plugin.confirmEmpty = function(){ |
| 37 | plugin.loading(true); |
| 38 | $(document).trigger('close-modal-manual'); |
| 39 | $(plugin.errorAlert).hide(); |
| 40 | plugin.emptyTrash(); |
| 41 | } |
| 42 | |
| 43 | // Empty the Trash |
| 44 | plugin.emptyTrash = function(){ |
| 45 | $.ajax({ |
| 46 | url: ajaxurl, |
| 47 | type: 'post', |
| 48 | datatype: 'json', |
| 49 | data: { |
| 50 | action : plugin.formAction, |
| 51 | nonce : plugin.nonce, |
| 52 | posttype : plugin.postType |
| 53 | }, |
| 54 | success: function(data){ |
| 55 | plugin.loading(false); |
| 56 | if (data.status === 'error'){ |
| 57 | $(plugin.errorAlert).text(data.message).show(); |
| 58 | } else { |
| 59 | $(plugin.trashLinks).hide(); |
| 60 | $('.notice-dismiss').click(); |
| 61 | } |
| 62 | } |
| 63 | }); |
| 64 | } |
| 65 | |
| 66 | // Loading Indication |
| 67 | plugin.loading = function(loading){ |
| 68 | if ( loading ){ |
| 69 | $(plugin.loadingIndicator).show(); |
| 70 | return; |
| 71 | } |
| 72 | $(plugin.loadingIndicator).hide(); |
| 73 | } |
| 74 | |
| 75 | return plugin.bindEvents(); |
| 76 | } |