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.settings-admin-customization.js
179 lines
| 1 | var NestedPages = NestedPages || {}; |
| 2 | |
| 3 | /** |
| 4 | * Admin Customization Settings |
| 5 | * @package Nested Pages |
| 6 | * @author Kyle Phillips - https://github.com/kylephillips/wp-nested-pages |
| 7 | */ |
| 8 | NestedPages.AdminCustomizationSettings = function() |
| 9 | { |
| 10 | var plugin = this; |
| 11 | var $ = jQuery; |
| 12 | |
| 13 | plugin.selectors = { |
| 14 | navItemCheckbox : 'data-nestedpages-admin-nav-item-checkbox', |
| 15 | adminNavList : 'data-np-sortable-admin-nav', |
| 16 | adminNavRoleSelect : 'data-np-nav-menu-user-role-select', |
| 17 | adminNavRoleMenu : 'data-np-nav-menu-customization', |
| 18 | adminNavDetails : 'data-np-extra-options', |
| 19 | adminNavDetailsToggle : 'data-np-extra-options-button', |
| 20 | adminSubNavList : 'data-np-sortable-admin-subnav', |
| 21 | submenuToggle : 'data-np-nav-menu-customization-submenu-toggle', |
| 22 | separatorRow : 'data-np-separator-row', |
| 23 | separatorRemoveButton : 'data-np-remove-separator-button', |
| 24 | separatorAddButton : 'data-np-add-separator-button' |
| 25 | } |
| 26 | |
| 27 | plugin.bindEvents = function() |
| 28 | { |
| 29 | $(document).ready(function(){ |
| 30 | plugin.enableSortableAdminSorting(); |
| 31 | plugin.defaultAdminMenuRoleSelect(); |
| 32 | }); |
| 33 | $(document).on('change', '[' + plugin.selectors.navItemCheckbox + ']', function(e){ |
| 34 | plugin.toggleNavItemVisibility($(this)); |
| 35 | }); |
| 36 | $(document).on('change', '[' + plugin.selectors.adminNavRoleSelect + ']', function(e){ |
| 37 | var menu = $(this).val(); |
| 38 | plugin.toggleNavRoleMenu(menu); |
| 39 | }); |
| 40 | $(document).on('click', '[' + plugin.selectors.adminNavDetailsToggle + ']', function(e){ |
| 41 | e.preventDefault(); |
| 42 | plugin.toggleNavExtraOptions($(this)); |
| 43 | }); |
| 44 | $(document).on('click', '[' + plugin.selectors.submenuToggle + ']', function(e){ |
| 45 | e.preventDefault(); |
| 46 | plugin.toggleSubmenu($(this)); |
| 47 | }); |
| 48 | $(document).on('click', '[' + plugin.selectors.separatorRemoveButton + ']', function(e){ |
| 49 | e.preventDefault(); |
| 50 | plugin.removeSeparator($(this)); |
| 51 | }); |
| 52 | $(document).on('click', '[' + plugin.selectors.separatorAddButton + ']', function(e){ |
| 53 | e.preventDefault(); |
| 54 | plugin.addSeparator(); |
| 55 | }); |
| 56 | } |
| 57 | |
| 58 | plugin.enableSortableAdminSorting = function() |
| 59 | { |
| 60 | $('[' + plugin.selectors.adminNavList + ']').sortable({ |
| 61 | handle: '.handle', |
| 62 | items: '.np-nav-preview', |
| 63 | stop : function(event, ui){ |
| 64 | var items = $('[' + plugin.selectors.adminNavList + '] li'); |
| 65 | $.each(items, function(){ |
| 66 | $(this).find('[data-np-menu-order]').val($(this).index()); |
| 67 | }); |
| 68 | } |
| 69 | }); |
| 70 | |
| 71 | $('[' + plugin.selectors.adminSubNavList + ']').sortable({ |
| 72 | handle: '.handle', |
| 73 | items: '.submenu-item', |
| 74 | stop : function(event, ui){ |
| 75 | var items = $('[' + plugin.selectors.adminSubNavList + '] li'); |
| 76 | $.each(items, function(){ |
| 77 | $(this).find('[data-np-submenu-order]').val($(this).index()); |
| 78 | }); |
| 79 | } |
| 80 | }); |
| 81 | } |
| 82 | |
| 83 | plugin.defaultAdminMenuRoleSelect = function() |
| 84 | { |
| 85 | $('[' + plugin.selectors.adminNavRoleSelect + ']').find('option:eq(0)').prop('selected', true); |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Toggle the Menu Item visibility under admin menu options (hide from menu) |
| 90 | */ |
| 91 | plugin.toggleNavItemVisibility = function(checkbox) |
| 92 | { |
| 93 | var item = $(checkbox).closest('li.np-nav-preview'); |
| 94 | var checked = ( $(checkbox).is(':checked') ) ? true : false; |
| 95 | if ( checked ){ |
| 96 | $(item).addClass('disabled'); |
| 97 | return; |
| 98 | } |
| 99 | $(item).removeClass('disabled'); |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Toggle which role's menu to edit |
| 104 | */ |
| 105 | plugin.toggleNavRoleMenu = function(menu) |
| 106 | { |
| 107 | $('[' + plugin.selectors.adminNavRoleMenu + ']').hide(); |
| 108 | var visibleMenu = $('[' + plugin.selectors.adminNavRoleMenu + '="' + menu + '"]'); |
| 109 | $('[' + plugin.selectors.adminNavRoleSelect + ']').val(menu); |
| 110 | $(visibleMenu).show(); |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Toggle the extra options for a nav menu item |
| 115 | */ |
| 116 | plugin.toggleNavExtraOptions = function(button) |
| 117 | { |
| 118 | var options = $(button).parents('.np-nav-preview').find('[' + plugin.selectors.adminNavDetails + ']'); |
| 119 | $(button).parents('.np-nav-preview').toggleClass('options-open'); |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Toggle an admin submenu |
| 124 | */ |
| 125 | plugin.toggleSubmenu = function(button) |
| 126 | { |
| 127 | $(button).toggleClass('active'); |
| 128 | $(button).parents('li').toggleClass('submenu-open'); |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * Remove a separator |
| 133 | */ |
| 134 | plugin.removeSeparator = function(button) |
| 135 | { |
| 136 | $(button).closest('[' + plugin.selectors.separatorRow + ']').fadeOut(function(){ |
| 137 | $(this).remove(); |
| 138 | }); |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * Add a separator |
| 143 | */ |
| 144 | plugin.addSeparator = function() |
| 145 | { |
| 146 | var currentList = $('[' + plugin.selectors.adminNavList + ']:visible'); |
| 147 | var separatorCount = $(currentList).find('[' + plugin.selectors.separatorRow + ']').length + 1; |
| 148 | var currentRole = $('[' + plugin.selectors.adminNavRoleSelect + ']').val(); |
| 149 | currentRole = currentRole.replace('menu_role_', ''); |
| 150 | |
| 151 | var html = '<li class="np-nav-preview separator" data-np-separator-row>'; |
| 152 | html += '<div class="menu-item">'; |
| 153 | html += '<div class="submenu-toggle"></div>'; |
| 154 | html += '<div class="handle"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" class=" np-icon-menu"><path d="M0 0h24v24H0z" fill="none" /><path d="M3 18h18v-2H3v2zm0-5h18v-2H3v2zm0-7v2h18V6H3z" class="bars" /></svg></div>'; |
| 155 | html += '<div class="title"><div class="menu-icon dashicons-before dashicons-admin-post"></div><p>Separator<button class="button button-small details-button" data-np-remove-separator-button="">Remove</button></p></div><!-- .title -->'; |
| 156 | html += '</div><!-- .menu-item -->' |
| 157 | html += '<input type="hidden" name="nestedpages_admin[nav_menu_options][' + currentRole + '][custom_sep' + separatorCount + ']" value="true">'; |
| 158 | html += '<input type="hidden" name="nestedpages_admin[nav_menu_options][' + currentRole + '][custom_sep' + separatorCount + '][order]" value="" data-np-menu-order>'; |
| 159 | html += '</li>'; |
| 160 | $(currentList).prepend(html); |
| 161 | plugin.resetNavOrder($(currentList)); |
| 162 | } |
| 163 | |
| 164 | /** |
| 165 | * Reset Orders |
| 166 | */ |
| 167 | plugin.resetNavOrder = function(list) |
| 168 | { |
| 169 | var orderFields = $(list).find('[data-np-menu-order]'); |
| 170 | $.each(orderFields, function(i, v){ |
| 171 | $(this).val(i); |
| 172 | }); |
| 173 | plugin.enableSortableAdminSorting(); |
| 174 | } |
| 175 | |
| 176 | return plugin.bindEvents(); |
| 177 | } |
| 178 | |
| 179 | new NestedPages.AdminCustomizationSettings; |