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-factory.js
276 lines
| 1 | /** |
| 2 | * Primary Nested Pages Initialization |
| 3 | * @package Nested Pages |
| 4 | * @author Kyle Phillips - https://github.com/kylephillips/wp-nested-pages |
| 5 | */ |
| 6 | |
| 7 | jQuery(document).ready(function(){ |
| 8 | new NestedPages.Factory; |
| 9 | }); |
| 10 | |
| 11 | var NestedPages = NestedPages || {}; |
| 12 | |
| 13 | |
| 14 | // DOM Selectors |
| 15 | NestedPages.selectors = { |
| 16 | childToggle : '.child-toggle', // Child Toggle Buttons |
| 17 | childToggleLink : '.child-toggle a', // Actual link in button |
| 18 | toggleAll : '.nestedpages-toggleall', // Toggle All Button |
| 19 | toggleHidden : '.np-toggle-hidden', // Toggle Hidden Pages |
| 20 | toggleStatus : '.np-toggle-publish', // Toggle Published Pages |
| 21 | lists : '.nplist', // OL elements |
| 22 | rows : '.page-row', // Page Row, |
| 23 | row : '.row', // Inner row div element |
| 24 | sortable : '.sortable', // Sortable List |
| 25 | notSortable : '.no-sort', // Unsortable List |
| 26 | handle : '.handle', // Sortable Handle |
| 27 | published : '.published', // Published Rows |
| 28 | hiddenRows : '.np-hide', // Hidden Rows |
| 29 | errorDiv : '#np-error', // Error Alert |
| 30 | loadingIndicator : '#nested-loading', // Loading Indicator, |
| 31 | syncCheckbox : '.np-sync-menu', // Sync menu checkbox |
| 32 | syncForm: '.np-sync-menu-cont', // The form/container for the sync menu element |
| 33 | ajaxError : '[data-nestedpages-error]', // AJAX error notification |
| 34 | trashWithChildrenButton : '[data-nestedpages-trash-children]', |
| 35 | |
| 36 | // Responsive Toggle |
| 37 | toggleEditButtons : '.np-toggle-edit', // Button that toggles responsive buttons |
| 38 | |
| 39 | // Bulk Actions |
| 40 | bulkActionsHeader : '.nestedpages-list-header', |
| 41 | bulkActionsForm : '[data-np-bulk-form]', |
| 42 | bulkActionsCheckbox : '[data-np-bulk-checkbox]', |
| 43 | bulkActionsIds : '[data-np-bulk-ids]', |
| 44 | bulkActionRedirectIds : '[data-np-bulk-redirect-ids]', |
| 45 | hiddenItemCount : '[data-np-hidden-count]', |
| 46 | hiddenItemCountParent : '[data-np-hidden-count-parent]', |
| 47 | bulkEditForm : '[data-np-bulk-edit-form]', // The primary bulk edit form |
| 48 | bulkEditTitles : '[data-np-bulk-titles]', // Titles to perform bulk edits on (includes hidden ids), |
| 49 | bulkEditRemoveItem : '[data-np-remove-bulk-item]', // Remove an item from bulk edit |
| 50 | bulkEditCancel : '[data-np-cancel-bulk-edit]', // Cancel button in bulk edit form |
| 51 | bulkEditLinkCount : '[data-bulk-edit-link-count]', // Count of selected links in bulk edit |
| 52 | |
| 53 | // Quick Edit |
| 54 | quickEditOverlay : '.np-inline-overlay', // The inline modal |
| 55 | quickEditLoadingIndicator : '.np-qe-loading', // Loading indicator in Quick Edit |
| 56 | quickEditErrorDiv : '.np-quickedit-error', // Error Div in Quick Edit |
| 57 | quickEditCancel : '.np-cancel-quickedit', // Cancel button in quick edit |
| 58 | |
| 59 | // Quick Edit - Links |
| 60 | quickEditButtonLink : '.np-quick-edit-redirect', // Button to open link quick edit |
| 61 | quickEditLinkForm : '.quick-edit-form-redirect', // Form for link quick edits |
| 62 | quickEditLinkSaveButton : '.np-save-quickedit-redirect', // Save button in link quick edit form |
| 63 | |
| 64 | // Quick Edit - Posts |
| 65 | quickEditOpen : '.np-quick-edit', // Button to open post quick edit |
| 66 | quickEditPostForm : '.quick-edit-form', // Form container |
| 67 | quickEditSaveButton : '.np-save-quickedit', // Save button in quick edit (posts) |
| 68 | |
| 69 | // Link Items |
| 70 | openLinkModal : '.open-redirect-modal', // Opens new link modal |
| 71 | linkModal : 'np-link-modal', // The add a link modal |
| 72 | saveLink : '.np-save-link', // Save Link Button |
| 73 | linkLoadingIndicator : '.np-link-loading', // Loading Indicator in Link Modal |
| 74 | linkErrorDiv : '.np-new-link-error', // Error Div in Link Modal |
| 75 | linkForm : '.np-new-link-form', // The form element for a new link |
| 76 | |
| 77 | // Link Deletion |
| 78 | linkDeleteButton : '[data-np-confirm-delete]', |
| 79 | linkDeleteConfirmationButton : '[data-delete-confirmation]', |
| 80 | linkDeleteConfirmationModal : 'np-delete-confirmation-modal', |
| 81 | linkDeleteConfirmationModalText : '[data-np-link-delete-text]', |
| 82 | |
| 83 | // New Page Items |
| 84 | openPageModal : '.open-bulk-modal', // Opens the new page(s) modal |
| 85 | newPageModal : '#np-bulk-modal', // The modal with the new page form |
| 86 | newPageFormContainer : '.new-child-form', // The new page form container |
| 87 | newPageForm : '.np-new-child-form', // The form element |
| 88 | newPageSubmitButton : '.np-save-newchild', // Submit button in new page form |
| 89 | newPageTitle : '.add-new-child-row', // Button to add a new page title field to the form |
| 90 | newPageRemoveTitle : '.np-remove-child', // Button to remove a title field in the form |
| 91 | addChildButton : '.add-new-child', // Button to add child page(s) |
| 92 | newChildError : '.np-newchild-error', // Error div in new child quick edit |
| 93 | cancelNewChildButton : '.np-cancel-newchild', // Cancel button in new child quick edit |
| 94 | newBeforeButton : 'data-insert-before', // Add new post(s) before a post |
| 95 | newAfterButton : 'data-insert-after', // Add new post(s) after a post |
| 96 | |
| 97 | // Clone |
| 98 | cloneButton : '.clone-post', // Button to clone a post |
| 99 | confirmClone : '[data-confirm-clone]', // Button in modal to confirm clone |
| 100 | cloneModal : 'np-clone-modal', // Modal with clone options |
| 101 | cloneQuantity : '[data-clone-quantity]', // Quantity to Clone |
| 102 | cloneStatus : '[data-clone-status]', // Clone Status |
| 103 | cloneAuthor : '[data-clone-author]', // Clone Author |
| 104 | cloneChildren : '[data-clone-children]', // Checkbox to clone children |
| 105 | |
| 106 | // Tabs |
| 107 | tabButtonParent : '[data-np-tabs]', // Tab Parent |
| 108 | tabButton : '[data-np-tab]', // Tab Link |
| 109 | tabContent : '[data-np-tab-pane]', // Tab Pane |
| 110 | |
| 111 | // Thumbnails |
| 112 | thumbnailContainer : '.np-thumbnail', // Container for Thumbnail |
| 113 | thumbnailContainerLink : '.np-thumbnail.link', // Link Thumbnail Container |
| 114 | |
| 115 | // Manual Sync Buttons |
| 116 | manualMenuSync : '[data-np-manual-menu-sync]', // Button for Triggering Manual Menu Sync |
| 117 | manualOrderSync : '[data-np-manual-order-sync]', // Button for Triggering Manual Order Sync |
| 118 | |
| 119 | } |
| 120 | |
| 121 | |
| 122 | // CSS Classes |
| 123 | NestedPages.cssClasses = { |
| 124 | noborder : 'no-border' |
| 125 | } |
| 126 | |
| 127 | |
| 128 | // JS Data |
| 129 | NestedPages.jsData = { |
| 130 | ajaxurl : ajaxurl, |
| 131 | nonce : nestedpages.np_nonce, |
| 132 | allPostTypes : nestedpages.post_types, // Localized data with all post types |
| 133 | syncmenu : 'nosync', // Whether to sync the menu |
| 134 | posttype : '', // current Screen's post type |
| 135 | nestable : true, // boolean - whether post type is nestable |
| 136 | sortable : true, // boolean - whether post type is sortable |
| 137 | hierarchical : true, // boolean - whether post type is hierarchical |
| 138 | expandText : nestedpages.expand_text, // Expand all button text |
| 139 | collapseText : nestedpages.collapse_text, // Collapse all button text |
| 140 | showHiddenText : nestedpages.show_hidden, // Show Hidden Pages Link Text |
| 141 | hideHiddenText : nestedpages.hide_hidden, // Hide Hidden Pages Link Text |
| 142 | quickEditText : nestedpages.quick_edit, // Quick Edit Button Text |
| 143 | hiddenText : nestedpages.hidden, // Localized "Hidden" |
| 144 | titleText : nestedpages.title, // Localized "Title" |
| 145 | } |
| 146 | |
| 147 | |
| 148 | // Form Actions |
| 149 | NestedPages.formActions = { |
| 150 | syncToggles : 'npnestToggle', |
| 151 | syncNesting : 'npsort', |
| 152 | syncMenu : 'npsyncMenu', |
| 153 | newPage : 'npnewChild', |
| 154 | newBeforeAfter : 'npnewBeforeAfter', |
| 155 | quickEditLink : 'npquickEditLink', |
| 156 | getTaxonomies : 'npgetTaxonomies', |
| 157 | quickEditPost : 'npquickEdit', |
| 158 | clonePost : 'npclonePost', |
| 159 | search : 'npmenuSearch', |
| 160 | newMenuItem : 'npnewMenuItem', |
| 161 | manualMenuSync : 'npmanualMenuSync', |
| 162 | postSearch: 'nppostSearch', |
| 163 | wpmlTranslations : 'npWpmlTranslations', |
| 164 | resetSettings : 'npresetSettings', |
| 165 | resetUserPrefs : 'npresetUserPreferences', |
| 166 | resetAdminMenuSettings : 'npresetAdminMenuSettings', |
| 167 | trashWithChildren : 'nptrashWithChildren', |
| 168 | toggleStatusDisplay : 'nptoggleStatusDisplay' |
| 169 | } |
| 170 | |
| 171 | |
| 172 | /** |
| 173 | * Primary Nested Pages Class |
| 174 | */ |
| 175 | NestedPages.Factory = function() |
| 176 | { |
| 177 | var plugin = this; |
| 178 | var $ = jQuery; |
| 179 | |
| 180 | plugin.formatter = new NestedPages.Formatter; |
| 181 | plugin.dropdowns = new NestedPages.Dropdowns; |
| 182 | plugin.modals = new NestedPages.Modals; |
| 183 | plugin.checkAll = new NestedPages.CheckAll; |
| 184 | plugin.bulkActions = new NestedPages.BulkActions; |
| 185 | plugin.menuToggle = new NestedPages.MenuToggle; |
| 186 | plugin.pageToggle = new NestedPages.PageToggle; |
| 187 | plugin.nesting = new NestedPages.Nesting; |
| 188 | plugin.syncMenuSetting = new NestedPages.SyncMenuSetting; |
| 189 | plugin.newPage = new NestedPages.NewPost; |
| 190 | plugin.quickEditLink = new NestedPages.QuickEditLink; |
| 191 | plugin.quickEditPost = new NestedPages.QuickEditPost; |
| 192 | plugin.clone = new NestedPages.Clone; |
| 193 | plugin.tabs = new NestedPages.Tabs; |
| 194 | plugin.menuLinks = new NestedPages.MenuLinks; |
| 195 | plugin.hiddenItemCount = new NestedPages.HiddenItemCount; |
| 196 | plugin.confirmDelete = new NestedPages.ConfirmDelete; |
| 197 | plugin.manualSync = new NestedPages.ManualSync; |
| 198 | plugin.postSearch = new NestedPages.PostSearch; |
| 199 | plugin.postMove = new NestedPages.MovePost; |
| 200 | plugin.wpml = new NestedPages.Wpml; |
| 201 | plugin.trashWithChildren = new NestedPages.TrashWithChildren; |
| 202 | |
| 203 | plugin.init = function() |
| 204 | { |
| 205 | if ( nestedpages.settings_page ) return; |
| 206 | plugin.bindEvents(); |
| 207 | plugin.setPostType(); |
| 208 | plugin.setMenuSync(); |
| 209 | plugin.setNestable(); |
| 210 | plugin.setSortable(); |
| 211 | plugin.formatter.updateSubMenuToggle(); |
| 212 | plugin.formatter.setBorders(); |
| 213 | plugin.formatter.setNestedMargins(); |
| 214 | plugin.nesting.initializeSortable(); |
| 215 | } |
| 216 | |
| 217 | |
| 218 | plugin.bindEvents = function() |
| 219 | { |
| 220 | $(document).on('click', NestedPages.selectors.quickEditOverlay, function(e){ |
| 221 | plugin.formatter.removeQuickEdit(); |
| 222 | plugin.newPage.cancelNewPage(); |
| 223 | }); |
| 224 | $(document).ready(function(){ |
| 225 | plugin.formatter.hideAjaxError(); |
| 226 | plugin.formatter.sizeLinkThumbnails(); |
| 227 | }); |
| 228 | } |
| 229 | |
| 230 | |
| 231 | // Set whether or not post type is nestable |
| 232 | plugin.setNestable = function() |
| 233 | { |
| 234 | var nestable = false; |
| 235 | $.each(NestedPages.jsData.allPostTypes, function(i, v){ |
| 236 | if ( v.name !== NestedPages.jsData.posttype ) return; |
| 237 | if ( v.hierarchical === true ) nestable = true; |
| 238 | if ( v.disable_nesting === true ) nestable = false; |
| 239 | }); |
| 240 | NestedPages.jsData.nestable = nestable; |
| 241 | } |
| 242 | |
| 243 | |
| 244 | // Set whether or not post type is sortable |
| 245 | plugin.setSortable = function() |
| 246 | { |
| 247 | var sortable = true; |
| 248 | $.each(NestedPages.jsData.allPostTypes, function(i, v){ |
| 249 | if ( v.name !== NestedPages.jsData.posttype ) return; |
| 250 | if ( typeof v.disable_sorting === 'undefined' || v.disable_sorting === '' ) return; |
| 251 | if ( v.disable_sorting === "true" ) sortable = false; |
| 252 | }); |
| 253 | NestedPages.jsData.sortable = sortable; |
| 254 | } |
| 255 | |
| 256 | |
| 257 | // Set the Screen's Post Type |
| 258 | plugin.setPostType = function() |
| 259 | { |
| 260 | NestedPages.jsData.posttype = nestedpages.current_post_type; |
| 261 | if ( typeof NestedPages.jsData.posttype === 'undefined' || NestedPages.jsData.posttype === '' ){ |
| 262 | NestedPages.jsData.posttype = $(NestedPages.selectors.sortable).attr('id').substring(3); |
| 263 | } |
| 264 | NestedPages.jsData.hierarchical = NestedPages.jsData.allPostTypes[NestedPages.jsData.posttype].hierarchical; |
| 265 | } |
| 266 | |
| 267 | |
| 268 | // Set menu sync |
| 269 | plugin.setMenuSync = function() |
| 270 | { |
| 271 | NestedPages.jsData.syncmenu = ( nestedpages.syncmenu === '1' ) ? 'sync' : 'nosync'; |
| 272 | } |
| 273 | |
| 274 | |
| 275 | return plugin.init(); |
| 276 | } |