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.menu-toggle.js
97 lines
| 1 | var NestedPages = NestedPages || {}; |
| 2 | |
| 3 | /** |
| 4 | * Toggles Menu Elements |
| 5 | * @package Nested Pages |
| 6 | * @author Kyle Phillips - https://github.com/kylephillips/wp-nested-pages |
| 7 | */ |
| 8 | NestedPages.MenuToggle = function() |
| 9 | { |
| 10 | var plugin = this; |
| 11 | var $ = jQuery; |
| 12 | |
| 13 | plugin.formatter = new NestedPages.Formatter; |
| 14 | |
| 15 | plugin.bindEvents = function() |
| 16 | { |
| 17 | $(document).on('click', NestedPages.selectors.childToggleLink, function(e){ |
| 18 | e.preventDefault(); |
| 19 | plugin.toggleSingleMenu($(this)); |
| 20 | }); |
| 21 | $(document).on('click', NestedPages.selectors.toggleAll, function(e){ |
| 22 | e.preventDefault(); |
| 23 | plugin.toggleAllMenus(); |
| 24 | }); |
| 25 | } |
| 26 | |
| 27 | |
| 28 | // Toggle individual submenus |
| 29 | plugin.toggleSingleMenu = function(button) |
| 30 | { |
| 31 | var submenu = $(button).parent(NestedPages.selectors.childToggle).parent(NestedPages.selectors.row).siblings('ol'); |
| 32 | $(button).toggleClass('open'); |
| 33 | $(submenu).toggle(); |
| 34 | plugin.formatter.setBorders(); |
| 35 | plugin.formatter.setNestedMargins(); |
| 36 | plugin.syncUserToggles(); |
| 37 | } |
| 38 | |
| 39 | |
| 40 | // Toggle All Submenus |
| 41 | plugin.toggleAllMenus = function() |
| 42 | { |
| 43 | var button = NestedPages.selectors.toggleAll; |
| 44 | if ( $(button).attr('data-toggle') === 'closed' ){ |
| 45 | $(NestedPages.selectors.lists).show(); |
| 46 | $(button).attr('data-toggle', 'opened').text(NestedPages.jsData.collapseText); |
| 47 | $(NestedPages.selectors.childToggle + ' a').addClass('open'); |
| 48 | plugin.formatter.setBorders(); |
| 49 | plugin.syncUserToggles(); |
| 50 | return; |
| 51 | } |
| 52 | |
| 53 | $(NestedPages.selectors.lists).not($(NestedPages.selectors.lists)[0]).hide(); |
| 54 | $(button).attr('data-toggle', 'closed').text(NestedPages.jsData.expandText); |
| 55 | $(NestedPages.selectors.childToggle + ' a').removeClass('open'); |
| 56 | plugin.formatter.setBorders(); |
| 57 | plugin.syncUserToggles(); |
| 58 | } |
| 59 | |
| 60 | |
| 61 | // Get an array of visible rows |
| 62 | plugin.visibleRowIDs = function() |
| 63 | { |
| 64 | var visible_ids = []; |
| 65 | var visible = $(NestedPages.selectors.rows + ':visible'); |
| 66 | $.each(visible, function(i, v){ |
| 67 | var id = $(this).attr('id'); |
| 68 | visible_ids.push(id.replace("menuItem_", "")); |
| 69 | }); |
| 70 | return visible_ids; |
| 71 | } |
| 72 | |
| 73 | |
| 74 | // Save the user's toggled menus |
| 75 | plugin.syncUserToggles = function() |
| 76 | { |
| 77 | $.ajax({ |
| 78 | url: NestedPages.jsData.ajaxurl, |
| 79 | type: 'post', |
| 80 | datatype: 'json', |
| 81 | data: { |
| 82 | action : NestedPages.formActions.syncToggles, |
| 83 | nonce : NestedPages.jsData.nonce, |
| 84 | ids : plugin.visibleRowIDs(), |
| 85 | posttype : NestedPages.jsData.posttype |
| 86 | }, |
| 87 | success: function(data){ |
| 88 | if ( data.status !== 'success' ){ |
| 89 | console.log('There was an error saving toggled pages.'); |
| 90 | } |
| 91 | } |
| 92 | }); |
| 93 | } |
| 94 | |
| 95 | |
| 96 | return plugin.bindEvents(); |
| 97 | } |