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.clone.js
80 lines
| 1 | var NestedPages = NestedPages || {}; |
| 2 | |
| 3 | /** |
| 4 | * Post clone functionality |
| 5 | * @package Nested Pages |
| 6 | * @author Kyle Phillips - https://github.com/kylephillips/wp-nested-pages |
| 7 | */ |
| 8 | NestedPages.Clone = function() |
| 9 | { |
| 10 | var plugin = this; |
| 11 | var $ = jQuery; |
| 12 | |
| 13 | plugin.parent_id = ''; // The parent/source post ID |
| 14 | plugin.parent_title = ''; // The parent title |
| 15 | plugin.parentLi = null; |
| 16 | |
| 17 | plugin.formatter = new NestedPages.Formatter; |
| 18 | |
| 19 | plugin.bindEvents = function() |
| 20 | { |
| 21 | $(document).on('click', NestedPages.selectors.cloneButton, function(e){ |
| 22 | e.preventDefault(); |
| 23 | plugin.parent_id = $(this).attr('data-id'); |
| 24 | plugin.parent_title = $(this).attr('data-parentname'); |
| 25 | plugin.parentLi = $(this).parent('.row').parent('.page-row').parent('.npList'); |
| 26 | plugin.openModal(); |
| 27 | }); |
| 28 | $(document).on('click', NestedPages.selectors.confirmClone, function(e){ |
| 29 | e.preventDefault(); |
| 30 | plugin.clone(); |
| 31 | }); |
| 32 | } |
| 33 | |
| 34 | // Open the modal with clone options |
| 35 | plugin.openModal = function() |
| 36 | { |
| 37 | $('#' + NestedPages.selectors.cloneModal).find('[data-clone-parent]').text(plugin.parent_title); |
| 38 | $(document).trigger('open-modal-manual', NestedPages.selectors.cloneModal); |
| 39 | } |
| 40 | |
| 41 | // Clone the post |
| 42 | plugin.clone = function() |
| 43 | { |
| 44 | var clone_children = ( $(NestedPages.selectors.cloneChildren).is(':checked') ) ? true : false; |
| 45 | plugin.toggleLoading(true); |
| 46 | $.ajax({ |
| 47 | url : NestedPages.jsData.ajaxurl, |
| 48 | type : 'post', |
| 49 | data : { |
| 50 | action : NestedPages.formActions.clonePost, |
| 51 | parent_id : plugin.parent_id, |
| 52 | quantity : $(NestedPages.selectors.cloneQuantity).val(), |
| 53 | status : $(NestedPages.selectors.cloneStatus).val(), |
| 54 | author : $(NestedPages.selectors.cloneAuthor).find('select').val(), |
| 55 | clone_children : clone_children, |
| 56 | nonce : NestedPages.jsData.nonce, |
| 57 | posttype : NestedPages.jsData.posttype |
| 58 | }, |
| 59 | success : function(data){ |
| 60 | plugin.toggleLoading(false); |
| 61 | $(document).trigger('close-modal-manual'); |
| 62 | location.reload(); |
| 63 | } |
| 64 | }); |
| 65 | } |
| 66 | |
| 67 | // Toggle Loading |
| 68 | plugin.toggleLoading = function(loading) |
| 69 | { |
| 70 | if ( loading ){ |
| 71 | $('#' + NestedPages.selectors.cloneModal).find('[data-clone-loading]').show(); |
| 72 | $(NestedPages.selectors.confirmClone).attr('disabled', 'disabled'); |
| 73 | return; |
| 74 | } |
| 75 | $('#' + NestedPages.selectors.cloneModal).find('[data-clone-loading]').hide(); |
| 76 | $(NestedPages.selectors.confirmClone).attr('disabled', false); |
| 77 | } |
| 78 | |
| 79 | return plugin.bindEvents(); |
| 80 | } |