jquery.mjs.nestedSortable.js
11 years ago
jquery.ui.touch-punch.min.js
11 years ago
nestedpages-factory.js
8 years ago
nestedpages.bulk-actions.js
8 years ago
nestedpages.check-all.js
9 years ago
nestedpages.clone.js
8 years ago
nestedpages.confirm-delete.js
8 years ago
nestedpages.dropdowns.js
8 years ago
nestedpages.formatter.js
8 years ago
nestedpages.hidden-item-count.js
9 years ago
nestedpages.manual-sync.js
9 years ago
nestedpages.menu-links.js
8 years ago
nestedpages.menu-search.js
11 years ago
nestedpages.menu-toggle.js
8 years ago
nestedpages.modals.js
8 years ago
nestedpages.move-post.js
8 years ago
nestedpages.nesting.js
8 years ago
nestedpages.new-post.js
8 years ago
nestedpages.page-toggle.js
9 years ago
nestedpages.post-search.js
9 years ago
nestedpages.quickedit-link.js
8 years ago
nestedpages.quickedit-post.js
8 years ago
nestedpages.settings-reset.js
8 years ago
nestedpages.settings.js
8 years ago
nestedpages.sync-menu-setting.js
8 years ago
nestedpages.tabs.js
11 years ago
nestedpages.trash.js
8 years ago
nestedpages.wpml.js
8 years ago
nestedpages.nesting.js
159 lines
| 1 | var NestedPages = NestedPages || {}; |
| 2 | |
| 3 | /** |
| 4 | * Enables and Saves Nesting |
| 5 | * @package Nested Pages |
| 6 | * @author Kyle Phillips - https://github.com/kylephillips/wp-nested-pages |
| 7 | */ |
| 8 | NestedPages.Nesting = function() |
| 9 | { |
| 10 | var plugin = this; |
| 11 | var $ = jQuery; |
| 12 | |
| 13 | plugin.formatter = new NestedPages.Formatter; |
| 14 | |
| 15 | // Make the Menu sortable |
| 16 | plugin.initializeSortable = function() |
| 17 | { |
| 18 | if ( !NestedPages.jsData.nestable ) return plugin.initializeSortableFlat(); |
| 19 | |
| 20 | $(NestedPages.selectors.sortable).not(NestedPages.selectors.notSortable).nestedSortable({ |
| 21 | items : NestedPages.selectors.rows, |
| 22 | toleranceElement: '> .row', |
| 23 | handle: NestedPages.selectors.handle, |
| 24 | placeholder: "ui-sortable-placeholder", |
| 25 | tabSize : 56, |
| 26 | isAllowed: function(placeholder, placeholderParent, currentItem){ |
| 27 | return ( $(placeholderParent).hasClass('post-type-np-redirect') && !$(currentItem).hasClass('post-type-np-redirect') ) ? false : true; |
| 28 | }, |
| 29 | start: function(e, ui){ |
| 30 | ui.placeholder.height(ui.item.height()); |
| 31 | }, |
| 32 | sort: function(e, ui){ |
| 33 | plugin.formatter.updatePlaceholderWidth(ui); |
| 34 | }, |
| 35 | stop: function(e, ui){ |
| 36 | setTimeout( |
| 37 | function(){ |
| 38 | plugin.formatter.updateSubMenuToggle(); |
| 39 | plugin.formatter.setBorders(); |
| 40 | plugin.formatter.setNestedMargins(); |
| 41 | }, 100 |
| 42 | ); |
| 43 | plugin.syncNesting(); |
| 44 | }, |
| 45 | }); |
| 46 | } |
| 47 | |
| 48 | // Initialize Flat Sortable (Non-Hierarchical Post Types) |
| 49 | plugin.initializeSortableFlat = function() |
| 50 | { |
| 51 | var lists = $(NestedPages.selectors.lists).not(NestedPages.selectors.notSortable); |
| 52 | $.each(lists, function(){ |
| 53 | $(this).sortable({ |
| 54 | items : '>' + NestedPages.selectors.rows, |
| 55 | handle: NestedPages.selectors.handle, |
| 56 | placeholder: "ui-sortable-placeholder", |
| 57 | forcePlaceholderSize: true, |
| 58 | start: function(e, ui){ |
| 59 | ui.placeholder.height(ui.item.height()); |
| 60 | }, |
| 61 | sort: function(e, ui){ |
| 62 | plugin.formatter.updatePlaceholderWidth(ui); |
| 63 | }, |
| 64 | stop: function(e, ui){ |
| 65 | setTimeout( |
| 66 | function(){ |
| 67 | plugin.formatter.updateSubMenuToggle(); |
| 68 | plugin.formatter.setBorders(); |
| 69 | plugin.formatter.setNestedMargins(); |
| 70 | }, 100 |
| 71 | ); |
| 72 | plugin.syncNesting(); |
| 73 | }, |
| 74 | }); |
| 75 | }); |
| 76 | } |
| 77 | |
| 78 | // Disable Nesting |
| 79 | plugin.disableNesting = function() |
| 80 | { |
| 81 | $(NestedPages.selectors.sortable).sortable('destroy'); |
| 82 | } |
| 83 | |
| 84 | |
| 85 | // Sync Nesting |
| 86 | plugin.syncNesting = function(manual, callback) |
| 87 | { |
| 88 | var list; |
| 89 | |
| 90 | if ( nestedpages.manual_order_sync === '1' && !manual) return; |
| 91 | $(NestedPages.selectors.errorDiv).hide(); |
| 92 | $(NestedPages.selectors.loadingIndicator).show(); |
| 93 | if ( NestedPages.jsData.nestable ){ |
| 94 | list = $(NestedPages.selectors.sortable).nestedSortable('toHierarchy', {startDepthCount: 0}); |
| 95 | } else { |
| 96 | list = plugin.setNestingArray(); |
| 97 | } |
| 98 | |
| 99 | plugin.disableNesting(); |
| 100 | |
| 101 | var syncmenu = NestedPages.jsData.syncmenu; |
| 102 | if ( nestedpages.manual_menu_sync === '1' ) syncmenu = 'nosync'; |
| 103 | |
| 104 | $.ajax({ |
| 105 | url: ajaxurl, |
| 106 | type: 'post', |
| 107 | datatype: 'json', |
| 108 | data: { |
| 109 | action : NestedPages.formActions.syncNesting, |
| 110 | nonce : NestedPages.jsData.nonce, |
| 111 | list : list, |
| 112 | post_type : NestedPages.jsData.posttype, |
| 113 | syncmenu : syncmenu |
| 114 | }, |
| 115 | success: function(data, callback){ |
| 116 | plugin.initializeSortable(); |
| 117 | if (data.status === 'error'){ |
| 118 | $(NestedPages.selectors.errorDiv).text(data.message).show(); |
| 119 | $(NestedPages.selectors.loadingIndicator).hide(); |
| 120 | } else { |
| 121 | if ( callback && typeof callback === 'function') { |
| 122 | callback(); |
| 123 | return; |
| 124 | } |
| 125 | $(NestedPages.selectors.loadingIndicator).hide(); |
| 126 | } |
| 127 | } |
| 128 | }); |
| 129 | } |
| 130 | |
| 131 | plugin.setNestingArray = function(list) |
| 132 | { |
| 133 | ret = []; |
| 134 | $(NestedPages.selectors.lists).first().children('li.page-row').each(function() { |
| 135 | var level = plugin.recursiveNesting(this); |
| 136 | ret.push(level); |
| 137 | }); |
| 138 | return ret; |
| 139 | } |
| 140 | |
| 141 | plugin.recursiveNesting = function(item) { |
| 142 | var id = $(item).attr('id'); |
| 143 | var currentItem; |
| 144 | if (id) { |
| 145 | id = id.replace('menuItem_', ''); |
| 146 | currentItem = { |
| 147 | "id": id |
| 148 | }; |
| 149 | if ($(item).children(NestedPages.selectors.lists).children(NestedPages.selectors.rows).length > 0) { |
| 150 | currentItem.children = []; |
| 151 | $(item).children(NestedPages.selectors.lists).children(NestedPages.selectors.rows).each(function() { |
| 152 | var level = plugin.recursiveNesting(this); |
| 153 | currentItem.children.push(level); |
| 154 | }); |
| 155 | } |
| 156 | return currentItem; |
| 157 | } |
| 158 | } |
| 159 | } |