wp/wp-admin/js/nav-menu.js
author ymh <ymh.work@gmail.com>
Thu, 29 Sep 2022 08:06:27 +0200
changeset 20 7b1b88e27a20
parent 19 3d72ae0968f4
child 21 48c4eec2b7e6
permissions -rw-r--r--
Modified Readme
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
 * WordPress Administration Navigation Menu
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
 * Interface JS functions
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
 * @version 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
 * @package WordPress
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
 * @subpackage Administration
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
     9
 * @output wp-admin/js/nav-menu.js
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    12
/* global menus, postboxes, columns, isRtl, ajaxurl, wpNavMenu */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
(function($) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    16
	var api;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    17
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    18
	/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    19
	 * Contains all the functions to handle WordPress navigation menus administration.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    20
	 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    21
	 * @namespace wpNavMenu
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    22
	 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    23
	api = window.wpNavMenu = {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
		options : {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
			menuItemDepthPerLevel : 30, // Do not use directly. Use depthToPx and pxToDepth instead.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    27
			globalMaxDepth:  11,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    28
			sortableItems:   '> *',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    29
			targetTolerance: 0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
		menuList : undefined,	// Set in init.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
		targetList : undefined, // Set in init.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
		menusChanged : false,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
		isRTL: !! ( 'undefined' != typeof isRtl && isRtl ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
		negateIfRTL: ( 'undefined' != typeof isRtl && isRtl ) ? -1 : 1,
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    37
		lastSearch: '',
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
		// Functions that run on init.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
		init : function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
			api.menuList = $('#menu-to-edit');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
			api.targetList = api.menuList;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
			this.jQueryExtensions();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
			this.attachMenuEditListeners();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    48
			this.attachBulkSelectButtonListeners();
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    49
			this.attachMenuCheckBoxListeners();
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    50
			this.attachMenuItemDeleteButton();
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    51
			this.attachPendingMenuItemsListForDeletion();
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    52
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
			this.attachQuickSearchListeners();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
			this.attachThemeLocationsListeners();
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    55
			this.attachMenuSaveSubmitListeners();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
			this.attachTabsPanelListeners();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
			this.attachUnsavedChangesListener();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
			if ( api.menuList.length )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
				this.initSortables();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
			if ( menus.oneThemeLocationNoMenus )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
				$( '#posttype-page' ).addSelectedToMenu( api.addMenuItemToBottom );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
			this.initManageLocations();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
			this.initAccessibility();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
			this.initToggles();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    72
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    73
			this.initPreviewing();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
		jQueryExtensions : function() {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    77
			// jQuery extensions.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
			$.fn.extend({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
				menuItemDepth : function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
					var margin = api.isRTL ? this.eq(0).css('margin-right') : this.eq(0).css('margin-left');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
					return api.pxToDepth( margin && -1 != margin.indexOf('px') ? margin.slice(0, -2) : 0 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
				},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
				updateDepthClass : function(current, prev) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
					return this.each(function(){
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
						var t = $(this);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
						prev = prev || t.menuItemDepth();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
						$(this).removeClass('menu-item-depth-'+ prev )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
							.addClass('menu-item-depth-'+ current );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
					});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
				},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
				shiftDepthClass : function(change) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
					return this.each(function(){
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
						var t = $(this),
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    94
							depth = t.menuItemDepth(),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    95
							newDepth = depth + change;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    96
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    97
						t.removeClass( 'menu-item-depth-'+ depth )
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    98
							.addClass( 'menu-item-depth-'+ ( newDepth ) );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    99
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   100
						if ( 0 === newDepth ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   101
							t.find( '.is-submenu' ).hide();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   102
						}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
					});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
				},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
				childMenuItems : function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
					var result = $();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
					this.each(function(){
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   108
						var t = $(this), depth = t.menuItemDepth(), next = t.next( '.menu-item' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
						while( next.length && next.menuItemDepth() > depth ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
							result = result.add( next );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   111
							next = next.next( '.menu-item' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
						}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
					});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
					return result;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
				},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
				shiftHorizontally : function( dir ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
					return this.each(function(){
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
						var t = $(this),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
							depth = t.menuItemDepth(),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
							newDepth = depth + dir;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   122
						// Change .menu-item-depth-n class.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
						t.moveHorizontally( newDepth, depth );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
					});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
				},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
				moveHorizontally : function( newDepth, depth ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   127
					return this.each(function(){
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   128
						var t = $(this),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
							children = t.childMenuItems(),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   130
							diff = newDepth - depth,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
							subItemText = t.find('.is-submenu');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   133
						// Change .menu-item-depth-n class.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
						t.updateDepthClass( newDepth, depth ).updateParentMenuItemDBId();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   136
						// If it has children, move those too.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
						if ( children ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   138
							children.each(function() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
								var t = $(this),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
									thisDepth = t.menuItemDepth(),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
									newDepth = thisDepth + diff;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
								t.updateDepthClass(newDepth, thisDepth).updateParentMenuItemDBId();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   143
							});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
						}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   146
						// Show "Sub item" helper text.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
						if (0 === newDepth)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   148
							subItemText.hide();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   149
						else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   150
							subItemText.show();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   151
					});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   152
				},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
				updateParentMenuItemDBId : function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   154
					return this.each(function(){
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   155
						var item = $(this),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
							input = item.find( '.menu-item-data-parent-id' ),
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   157
							depth = parseInt( item.menuItemDepth(), 10 ),
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   158
							parentDepth = depth - 1,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
							parent = item.prevAll( '.menu-item-depth-' + parentDepth ).first();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   161
						if ( 0 === depth ) { // Item is on the top level, has no parent.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
							input.val(0);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
						} else { // Find the parent item, and retrieve its object id.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
							input.val( parent.find( '.menu-item-data-db-id' ).val() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
						}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
					});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
				},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
				hideAdvancedMenuItemFields : function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
					return this.each(function(){
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   170
						var that = $(this);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   171
						$('.hide-column-tog').not(':checked').each(function(){
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
							that.find('.field-' + $(this).val() ).addClass('hidden-field');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
						});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
					});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
				},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   176
				/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
				 * Adds selected menu items to the menu.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
				 *
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   179
				 * @ignore
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   180
				 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   181
				 * @param jQuery metabox The metabox jQuery object.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
				 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
				addSelectedToMenu : function(processMethod) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   184
					if ( 0 === $('#menu-to-edit').length ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
						return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   187
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   188
					return this.each(function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
						var t = $(this), menuItems = {},
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   190
							checkboxes = ( menus.oneThemeLocationNoMenus && 0 === t.find( '.tabs-panel-active .categorychecklist li input:checked' ).length ) ? t.find( '#page-all li input[type="checkbox"]' ) : t.find( '.tabs-panel-active .categorychecklist li input:checked' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   191
							re = /menu-item\[([^\]]*)/;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   192
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
						processMethod = processMethod || api.addMenuItemToBottom;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   195
						// If no items are checked, bail.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
						if ( !checkboxes.length )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
							return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   198
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   199
						// Show the Ajax spinner.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   200
						t.find( '.button-controls .spinner' ).addClass( 'is-active' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   201
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   202
						// Retrieve menu item data.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   203
						$(checkboxes).each(function(){
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
							var t = $(this),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
								listItemDBIDMatch = re.exec( t.attr('name') ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   206
								listItemDBID = 'undefined' == typeof listItemDBIDMatch[1] ? 0 : parseInt(listItemDBIDMatch[1], 10);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   207
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   208
							if ( this.className && -1 != this.className.indexOf('add-to-top') )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   209
								processMethod = api.addMenuItemToTop;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   210
							menuItems[listItemDBID] = t.closest('li').getItemData( 'add-menu-item', listItemDBID );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   211
						});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   212
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   213
						// Add the items.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   214
						api.addItemToMenu(menuItems, processMethod, function(){
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   215
							// Deselect the items and hide the Ajax spinner.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   216
							checkboxes.prop( 'checked', false );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   217
							t.find( '.button-controls .select-all' ).prop( 'checked', false );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   218
							t.find( '.button-controls .spinner' ).removeClass( 'is-active' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   219
						});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   220
					});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   221
				},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   222
				getItemData : function( itemType, id ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   223
					itemType = itemType || 'menu-item';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   224
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   225
					var itemData = {}, i,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   226
					fields = [
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   227
						'menu-item-db-id',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   228
						'menu-item-object-id',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   229
						'menu-item-object',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
						'menu-item-parent-id',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   231
						'menu-item-position',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   232
						'menu-item-type',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
						'menu-item-title',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
						'menu-item-url',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   235
						'menu-item-description',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   236
						'menu-item-attr-title',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   237
						'menu-item-target',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   238
						'menu-item-classes',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   239
						'menu-item-xfn'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   240
					];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   241
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   242
					if( !id && itemType == 'menu-item' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   243
						id = this.find('.menu-item-data-db-id').val();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   244
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   245
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   246
					if( !id ) return itemData;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   248
					this.find('input').each(function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   249
						var field;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   250
						i = fields.length;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   251
						while ( i-- ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   252
							if( itemType == 'menu-item' )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   253
								field = fields[i] + '[' + id + ']';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
							else if( itemType == 'add-menu-item' )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   255
								field = 'menu-item[' + id + '][' + fields[i] + ']';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   256
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   257
							if (
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   258
								this.name &&
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   259
								field == this.name
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   260
							) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   261
								itemData[fields[i]] = this.value;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   262
							}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   263
						}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   264
					});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   265
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   266
					return itemData;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   267
				},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   268
				setItemData : function( itemData, itemType, id ) { // Can take a type, such as 'menu-item', or an id.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   269
					itemType = itemType || 'menu-item';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   270
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   271
					if( !id && itemType == 'menu-item' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   272
						id = $('.menu-item-data-db-id', this).val();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   273
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   274
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   275
					if( !id ) return this;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   276
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   277
					this.find('input').each(function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   278
						var t = $(this), field;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   279
						$.each( itemData, function( attr, val ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   280
							if( itemType == 'menu-item' )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   281
								field = attr + '[' + id + ']';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   282
							else if( itemType == 'add-menu-item' )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   283
								field = 'menu-item[' + id + '][' + attr + ']';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   284
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   285
							if ( field == t.attr('name') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   286
								t.val( val );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   287
							}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   288
						});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   289
					});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   290
					return this;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   291
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   292
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   293
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   294
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   295
		countMenuItems : function( depth ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   296
			return $( '.menu-item-depth-' + depth ).length;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   297
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   298
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   299
		moveMenuItem : function( $this, dir ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   300
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   301
			var items, newItemPosition, newDepth,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   302
				menuItems = $( '#menu-to-edit li' ),
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   303
				menuItemsCount = menuItems.length,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   304
				thisItem = $this.parents( 'li.menu-item' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   305
				thisItemChildren = thisItem.childMenuItems(),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   306
				thisItemData = thisItem.getItemData(),
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   307
				thisItemDepth = parseInt( thisItem.menuItemDepth(), 10 ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   308
				thisItemPosition = parseInt( thisItem.index(), 10 ),
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   309
				nextItem = thisItem.next(),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   310
				nextItemChildren = nextItem.childMenuItems(),
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   311
				nextItemDepth = parseInt( nextItem.menuItemDepth(), 10 ) + 1,
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   312
				prevItem = thisItem.prev(),
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   313
				prevItemDepth = parseInt( prevItem.menuItemDepth(), 10 ),
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   314
				prevItemId = prevItem.getItemData()['menu-item-db-id'],
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   315
				a11ySpeech = menus[ 'moved' + dir.charAt(0).toUpperCase() + dir.slice(1) ];
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   316
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   317
			switch ( dir ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   318
			case 'up':
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   319
				newItemPosition = thisItemPosition - 1;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   320
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   321
				// Already at top.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   322
				if ( 0 === thisItemPosition )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   323
					break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   324
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   325
				// If a sub item is moved to top, shift it to 0 depth.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   326
				if ( 0 === newItemPosition && 0 !== thisItemDepth )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   327
					thisItem.moveHorizontally( 0, thisItemDepth );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   328
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   329
				// If prev item is sub item, shift to match depth.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   330
				if ( 0 !== prevItemDepth )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   331
					thisItem.moveHorizontally( prevItemDepth, thisItemDepth );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   332
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   333
				// Does this item have sub items?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   334
				if ( thisItemChildren ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   335
					items = thisItem.add( thisItemChildren );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   336
					// Move the entire block.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   337
					items.detach().insertBefore( menuItems.eq( newItemPosition ) ).updateParentMenuItemDBId();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   338
				} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   339
					thisItem.detach().insertBefore( menuItems.eq( newItemPosition ) ).updateParentMenuItemDBId();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   340
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   341
				break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   342
			case 'down':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   343
				// Does this item have sub items?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   344
				if ( thisItemChildren ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   345
					items = thisItem.add( thisItemChildren ),
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   346
						nextItem = menuItems.eq( items.length + thisItemPosition ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   347
						nextItemChildren = 0 !== nextItem.childMenuItems().length;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   348
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   349
					if ( nextItemChildren ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   350
						newDepth = parseInt( nextItem.menuItemDepth(), 10 ) + 1;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   351
						thisItem.moveHorizontally( newDepth, thisItemDepth );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   352
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   353
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   354
					// Have we reached the bottom?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   355
					if ( menuItemsCount === thisItemPosition + items.length )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   356
						break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   357
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   358
					items.detach().insertAfter( menuItems.eq( thisItemPosition + items.length ) ).updateParentMenuItemDBId();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   359
				} else {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   360
					// If next item has sub items, shift depth.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   361
					if ( 0 !== nextItemChildren.length )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   362
						thisItem.moveHorizontally( nextItemDepth, thisItemDepth );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   363
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   364
					// Have we reached the bottom?
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   365
					if ( menuItemsCount === thisItemPosition + 1 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   366
						break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   367
					thisItem.detach().insertAfter( menuItems.eq( thisItemPosition + 1 ) ).updateParentMenuItemDBId();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   368
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   369
				break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   370
			case 'top':
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   371
				// Already at top.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   372
				if ( 0 === thisItemPosition )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   373
					break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   374
				// Does this item have sub items?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   375
				if ( thisItemChildren ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   376
					items = thisItem.add( thisItemChildren );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   377
					// Move the entire block.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   378
					items.detach().insertBefore( menuItems.eq( 0 ) ).updateParentMenuItemDBId();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   379
				} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   380
					thisItem.detach().insertBefore( menuItems.eq( 0 ) ).updateParentMenuItemDBId();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   381
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   382
				break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   383
			case 'left':
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   384
				// As far left as possible.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   385
				if ( 0 === thisItemDepth )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   386
					break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   387
				thisItem.shiftHorizontally( -1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   388
				break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   389
			case 'right':
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   390
				// Can't be sub item at top.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   391
				if ( 0 === thisItemPosition )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   392
					break;
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   393
				// Already sub item of prevItem.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   394
				if ( thisItemData['menu-item-parent-id'] === prevItemId )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   395
					break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   396
				thisItem.shiftHorizontally( 1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   397
				break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   398
			}
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   399
			$this.trigger( 'focus' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   400
			api.registerChange();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   401
			api.refreshKeyboardAccessibility();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   402
			api.refreshAdvancedAccessibility();
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   403
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   404
			if ( a11ySpeech ) {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   405
				wp.a11y.speak( a11ySpeech );
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   406
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   407
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   408
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   409
		initAccessibility : function() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   410
			var menu = $( '#menu-to-edit' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   411
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   412
			api.refreshKeyboardAccessibility();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   413
			api.refreshAdvancedAccessibility();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   414
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   415
			// Refresh the accessibility when the user comes close to the item in any way.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   416
			menu.on( 'mouseenter.refreshAccessibility focus.refreshAccessibility touchstart.refreshAccessibility' , '.menu-item' , function(){
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   417
				api.refreshAdvancedAccessibilityOfItem( $( this ).find( 'a.item-edit' ) );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   418
			} );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   419
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   420
			// We have to update on click as well because we might hover first, change the item, and then click.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   421
			menu.on( 'click', 'a.item-edit', function() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   422
				api.refreshAdvancedAccessibilityOfItem( $( this ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   423
			} );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   424
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   425
			// Links for moving items.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   426
			menu.on( 'click', '.menus-move', function () {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   427
				var $this = $( this ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   428
					dir = $this.data( 'dir' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   429
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   430
				if ( 'undefined' !== typeof dir ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   431
					api.moveMenuItem( $( this ).parents( 'li.menu-item' ).find( 'a.item-edit' ), dir );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   432
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   433
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   434
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   435
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   436
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   437
		 * refreshAdvancedAccessibilityOfItem( [itemToRefresh] )
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   438
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   439
		 * Refreshes advanced accessibility buttons for one menu item.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   440
		 * Shows or hides buttons based on the location of the menu item.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   441
		 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   442
		 * @param {Object} itemToRefresh The menu item that might need its advanced accessibility buttons refreshed
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   443
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   444
		refreshAdvancedAccessibilityOfItem : function( itemToRefresh ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   445
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   446
			// Only refresh accessibility when necessary.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   447
			if ( true !== $( itemToRefresh ).data( 'needs_accessibility_refresh' ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   448
				return;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   449
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   450
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   451
			var thisLink, thisLinkText, primaryItems, itemPosition, title,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   452
				parentItem, parentItemId, parentItemName, subItems,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   453
				$this = $( itemToRefresh ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   454
				menuItem = $this.closest( 'li.menu-item' ).first(),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   455
				depth = menuItem.menuItemDepth(),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   456
				isPrimaryMenuItem = ( 0 === depth ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   457
				itemName = $this.closest( '.menu-item-handle' ).find( '.menu-item-title' ).text(),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   458
				position = parseInt( menuItem.index(), 10 ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   459
				prevItemDepth = ( isPrimaryMenuItem ) ? depth : parseInt( depth - 1, 10 ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   460
				prevItemNameLeft = menuItem.prevAll('.menu-item-depth-' + prevItemDepth).first().find( '.menu-item-title' ).text(),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   461
				prevItemNameRight = menuItem.prevAll('.menu-item-depth-' + depth).first().find( '.menu-item-title' ).text(),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   462
				totalMenuItems = $('#menu-to-edit li').length,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   463
				hasSameDepthSibling = menuItem.nextAll( '.menu-item-depth-' + depth ).length;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   464
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   465
				menuItem.find( '.field-move' ).toggle( totalMenuItems > 1 );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   466
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   467
			// Where can they move this menu item?
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   468
			if ( 0 !== position ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   469
				thisLink = menuItem.find( '.menus-move-up' );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   470
				thisLink.attr( 'aria-label', menus.moveUp ).css( 'display', 'inline' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   471
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   472
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   473
			if ( 0 !== position && isPrimaryMenuItem ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   474
				thisLink = menuItem.find( '.menus-move-top' );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   475
				thisLink.attr( 'aria-label', menus.moveToTop ).css( 'display', 'inline' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   476
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   477
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   478
			if ( position + 1 !== totalMenuItems && 0 !== position ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   479
				thisLink = menuItem.find( '.menus-move-down' );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   480
				thisLink.attr( 'aria-label', menus.moveDown ).css( 'display', 'inline' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   481
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   482
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   483
			if ( 0 === position && 0 !== hasSameDepthSibling ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   484
				thisLink = menuItem.find( '.menus-move-down' );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   485
				thisLink.attr( 'aria-label', menus.moveDown ).css( 'display', 'inline' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   486
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   487
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   488
			if ( ! isPrimaryMenuItem ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   489
				thisLink = menuItem.find( '.menus-move-left' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   490
				thisLinkText = menus.outFrom.replace( '%s', prevItemNameLeft );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   491
				thisLink.attr( 'aria-label', menus.moveOutFrom.replace( '%s', prevItemNameLeft ) ).text( thisLinkText ).css( 'display', 'inline' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   492
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   493
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   494
			if ( 0 !== position ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   495
				if ( menuItem.find( '.menu-item-data-parent-id' ).val() !== menuItem.prev().find( '.menu-item-data-db-id' ).val() ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   496
					thisLink = menuItem.find( '.menus-move-right' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   497
					thisLinkText = menus.under.replace( '%s', prevItemNameRight );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   498
					thisLink.attr( 'aria-label', menus.moveUnder.replace( '%s', prevItemNameRight ) ).text( thisLinkText ).css( 'display', 'inline' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   499
				}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   500
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   501
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   502
			if ( isPrimaryMenuItem ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   503
				primaryItems = $( '.menu-item-depth-0' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   504
				itemPosition = primaryItems.index( menuItem ) + 1,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   505
				totalMenuItems = primaryItems.length,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   506
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   507
				// String together help text for primary menu items.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   508
				title = menus.menuFocus.replace( '%1$s', itemName ).replace( '%2$d', itemPosition ).replace( '%3$d', totalMenuItems );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   509
			} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   510
				parentItem = menuItem.prevAll( '.menu-item-depth-' + parseInt( depth - 1, 10 ) ).first(),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   511
				parentItemId = parentItem.find( '.menu-item-data-db-id' ).val(),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   512
				parentItemName = parentItem.find( '.menu-item-title' ).text(),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   513
				subItems = $( '.menu-item .menu-item-data-parent-id[value="' + parentItemId + '"]' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   514
				itemPosition = $( subItems.parents('.menu-item').get().reverse() ).index( menuItem ) + 1;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   515
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   516
				// String together help text for sub menu items.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   517
				title = menus.subMenuFocus.replace( '%1$s', itemName ).replace( '%2$d', itemPosition ).replace( '%3$s', parentItemName );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   518
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   519
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   520
			$this.attr( 'aria-label', title );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   521
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   522
			// Mark this item's accessibility as refreshed.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   523
			$this.data( 'needs_accessibility_refresh', false );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   524
		},
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   525
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   526
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   527
		 * refreshAdvancedAccessibility
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   528
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   529
		 * Hides all advanced accessibility buttons and marks them for refreshing.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   530
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   531
		refreshAdvancedAccessibility : function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   532
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   533
			// Hide all the move buttons by default.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   534
			$( '.menu-item-settings .field-move .menus-move' ).hide();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   535
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   536
			// Mark all menu items as unprocessed.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   537
			$( 'a.item-edit' ).data( 'needs_accessibility_refresh', true );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   538
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   539
			// All open items have to be refreshed or they will show no links.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   540
			$( '.menu-item-edit-active a.item-edit' ).each( function() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   541
				api.refreshAdvancedAccessibilityOfItem( this );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   542
			} );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   543
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   544
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   545
		refreshKeyboardAccessibility : function() {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   546
			$( 'a.item-edit' ).off( 'focus' ).on( 'focus', function(){
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   547
				$(this).off( 'keydown' ).on( 'keydown', function(e){
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   548
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   549
					var arrows,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   550
						$this = $( this ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   551
						thisItem = $this.parents( 'li.menu-item' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   552
						thisItemData = thisItem.getItemData();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   553
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   554
					// Bail if it's not an arrow key.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   555
					if ( 37 != e.which && 38 != e.which && 39 != e.which && 40 != e.which )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   556
						return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   557
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   558
					// Avoid multiple keydown events.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   559
					$this.off('keydown');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   560
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   561
					// Bail if there is only one menu item.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   562
					if ( 1 === $('#menu-to-edit li').length )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   563
						return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   564
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   565
					// If RTL, swap left/right arrows.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   566
					arrows = { '38': 'up', '40': 'down', '37': 'left', '39': 'right' };
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   567
					if ( $('body').hasClass('rtl') )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   568
						arrows = { '38' : 'up', '40' : 'down', '39' : 'left', '37' : 'right' };
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   569
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   570
					switch ( arrows[e.which] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   571
					case 'up':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   572
						api.moveMenuItem( $this, 'up' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   573
						break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   574
					case 'down':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   575
						api.moveMenuItem( $this, 'down' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   576
						break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   577
					case 'left':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   578
						api.moveMenuItem( $this, 'left' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   579
						break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   580
					case 'right':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   581
						api.moveMenuItem( $this, 'right' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   582
						break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   583
					}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   584
					// Put focus back on same menu item.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   585
					$( '#edit-' + thisItemData['menu-item-db-id'] ).trigger( 'focus' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   586
					return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   587
				});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   588
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   589
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   590
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   591
		initPreviewing : function() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   592
			// Update the item handle title when the navigation label is changed.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   593
			$( '#menu-to-edit' ).on( 'change input', '.edit-menu-item-title', function(e) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   594
				var input = $( e.currentTarget ), title, titleEl;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   595
				title = input.val();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   596
				titleEl = input.closest( '.menu-item' ).find( '.menu-item-title' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   597
				// Don't update to empty title.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   598
				if ( title ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   599
					titleEl.text( title ).removeClass( 'no-title' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   600
				} else {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   601
					titleEl.text( wp.i18n._x( '(no label)', 'missing menu item navigation label' ) ).addClass( 'no-title' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   602
				}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   603
			} );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   604
		},
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   605
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   606
		initToggles : function() {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   607
			// Init postboxes.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   608
			postboxes.add_postbox_toggles('nav-menus');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   609
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   610
			// Adjust columns functions for menus UI.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   611
			columns.useCheckboxesForHidden();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   612
			columns.checked = function(field) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   613
				$('.field-' + field).removeClass('hidden-field');
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   614
			};
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   615
			columns.unchecked = function(field) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   616
				$('.field-' + field).addClass('hidden-field');
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   617
			};
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   618
			// Hide fields.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   619
			api.menuList.hideAdvancedMenuItemFields();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   620
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   621
			$('.hide-postbox-tog').on( 'click', function () {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   622
				var hidden = $( '.accordion-container li.accordion-section' ).filter(':hidden').map(function() { return this.id; }).get().join(',');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   623
				$.post(ajaxurl, {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   624
					action: 'closed-postboxes',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   625
					hidden: hidden,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   626
					closedpostboxesnonce: jQuery('#closedpostboxesnonce').val(),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   627
					page: 'nav-menus'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   628
				});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   629
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   630
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   631
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   632
		initSortables : function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   633
			var currentDepth = 0, originalDepth, minDepth, maxDepth,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   634
				prev, next, prevBottom, nextThreshold, helperHeight, transport,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   635
				menuEdge = api.menuList.offset().left,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   636
				body = $('body'), maxChildDepth,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   637
				menuMaxDepth = initialMenuMaxDepth();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   638
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   639
			if( 0 !== $( '#menu-to-edit li' ).length )
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   640
				$( '.drag-instructions' ).show();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   641
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   642
			// Use the right edge if RTL.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   643
			menuEdge += api.isRTL ? api.menuList.width() : 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   644
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   645
			api.menuList.sortable({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   646
				handle: '.menu-item-handle',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   647
				placeholder: 'sortable-placeholder',
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   648
				items: api.options.sortableItems,
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   649
				start: function(e, ui) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   650
					var height, width, parent, children, tempHolder;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   651
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   652
					// Handle placement for RTL orientation.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   653
					if ( api.isRTL )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   654
						ui.item[0].style.right = 'auto';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   655
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   656
					transport = ui.item.children('.menu-item-transport');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   657
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   658
					// Set depths. currentDepth must be set before children are located.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   659
					originalDepth = ui.item.menuItemDepth();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   660
					updateCurrentDepth(ui, originalDepth);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   661
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   662
					// Attach child elements to parent.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   663
					// Skip the placeholder.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   664
					parent = ( ui.item.next()[0] == ui.placeholder[0] ) ? ui.item.next() : ui.item;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   665
					children = parent.childMenuItems();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   666
					transport.append( children );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   667
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   668
					// Update the height of the placeholder to match the moving item.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   669
					height = transport.outerHeight();
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   670
					// If there are children, account for distance between top of children and parent.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   671
					height += ( height > 0 ) ? (ui.placeholder.css('margin-top').slice(0, -2) * 1) : 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   672
					height += ui.helper.outerHeight();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   673
					helperHeight = height;
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   674
					height -= 2;                                              // Subtract 2 for borders.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   675
					ui.placeholder.height(height);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   676
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   677
					// Update the width of the placeholder to match the moving item.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   678
					maxChildDepth = originalDepth;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   679
					children.each(function(){
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   680
						var depth = $(this).menuItemDepth();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   681
						maxChildDepth = (depth > maxChildDepth) ? depth : maxChildDepth;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   682
					});
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   683
					width = ui.helper.find('.menu-item-handle').outerWidth(); // Get original width.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   684
					width += api.depthToPx(maxChildDepth - originalDepth);    // Account for children.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   685
					width -= 2;                                               // Subtract 2 for borders.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   686
					ui.placeholder.width(width);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   687
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   688
					// Update the list of menu items.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   689
					tempHolder = ui.placeholder.next( '.menu-item' );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   690
					tempHolder.css( 'margin-top', helperHeight + 'px' ); // Set the margin to absorb the placeholder.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   691
					ui.placeholder.detach();         // Detach or jQuery UI will think the placeholder is a menu item.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   692
					$(this).sortable( 'refresh' );   // The children aren't sortable. We should let jQuery UI know.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   693
					ui.item.after( ui.placeholder ); // Reattach the placeholder.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   694
					tempHolder.css('margin-top', 0); // Reset the margin.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   695
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   696
					// Now that the element is complete, we can update...
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   697
					updateSharedVars(ui);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   698
				},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   699
				stop: function(e, ui) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   700
					var children, subMenuTitle,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   701
						depthChange = currentDepth - originalDepth;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   702
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   703
					// Return child elements to the list.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   704
					children = transport.children().insertAfter(ui.item);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   705
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   706
					// Add "sub menu" description.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   707
					subMenuTitle = ui.item.find( '.item-title .is-submenu' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   708
					if ( 0 < currentDepth )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   709
						subMenuTitle.show();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   710
					else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   711
						subMenuTitle.hide();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   712
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   713
					// Update depth classes.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   714
					if ( 0 !== depthChange ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   715
						ui.item.updateDepthClass( currentDepth );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   716
						children.shiftDepthClass( depthChange );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   717
						updateMenuMaxDepth( depthChange );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   718
					}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   719
					// Register a change.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   720
					api.registerChange();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   721
					// Update the item data.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   722
					ui.item.updateParentMenuItemDBId();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   723
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   724
					// Address sortable's incorrectly-calculated top in Opera.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   725
					ui.item[0].style.top = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   726
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   727
					// Handle drop placement for rtl orientation.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   728
					if ( api.isRTL ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   729
						ui.item[0].style.left = 'auto';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   730
						ui.item[0].style.right = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   731
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   732
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   733
					api.refreshKeyboardAccessibility();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   734
					api.refreshAdvancedAccessibility();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   735
				},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   736
				change: function(e, ui) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   737
					// Make sure the placeholder is inside the menu.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   738
					// Otherwise fix it, or we're in trouble.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   739
					if( ! ui.placeholder.parent().hasClass('menu') )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   740
						(prev.length) ? prev.after( ui.placeholder ) : api.menuList.prepend( ui.placeholder );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   741
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   742
					updateSharedVars(ui);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   743
				},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   744
				sort: function(e, ui) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   745
					var offset = ui.helper.offset(),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   746
						edge = api.isRTL ? offset.left + ui.helper.width() : offset.left,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   747
						depth = api.negateIfRTL * api.pxToDepth( edge - menuEdge );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   748
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   749
					/*
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   750
					 * Check and correct if depth is not within range.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   751
					 * Also, if the dragged element is dragged upwards over an item,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   752
					 * shift the placeholder to a child position.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   753
					 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   754
					if ( depth > maxDepth || offset.top < ( prevBottom - api.options.targetTolerance ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   755
						depth = maxDepth;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   756
					} else if ( depth < minDepth ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   757
						depth = minDepth;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   758
					}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   759
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   760
					if( depth != currentDepth )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   761
						updateCurrentDepth(ui, depth);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   762
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   763
					// If we overlap the next element, manually shift downwards.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   764
					if( nextThreshold && offset.top + helperHeight > nextThreshold ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   765
						next.after( ui.placeholder );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   766
						updateSharedVars( ui );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   767
						$( this ).sortable( 'refreshPositions' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   768
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   769
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   770
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   771
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   772
			function updateSharedVars(ui) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   773
				var depth;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   774
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   775
				prev = ui.placeholder.prev( '.menu-item' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   776
				next = ui.placeholder.next( '.menu-item' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   777
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   778
				// Make sure we don't select the moving item.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   779
				if( prev[0] == ui.item[0] ) prev = prev.prev( '.menu-item' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   780
				if( next[0] == ui.item[0] ) next = next.next( '.menu-item' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   781
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   782
				prevBottom = (prev.length) ? prev.offset().top + prev.height() : 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   783
				nextThreshold = (next.length) ? next.offset().top + next.height() / 3 : 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   784
				minDepth = (next.length) ? next.menuItemDepth() : 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   785
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   786
				if( prev.length )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   787
					maxDepth = ( (depth = prev.menuItemDepth() + 1) > api.options.globalMaxDepth ) ? api.options.globalMaxDepth : depth;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   788
				else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   789
					maxDepth = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   790
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   791
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   792
			function updateCurrentDepth(ui, depth) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   793
				ui.placeholder.updateDepthClass( depth, currentDepth );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   794
				currentDepth = depth;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   795
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   796
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   797
			function initialMenuMaxDepth() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   798
				if( ! body[0].className ) return 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   799
				var match = body[0].className.match(/menu-max-depth-(\d+)/);
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   800
				return match && match[1] ? parseInt( match[1], 10 ) : 0;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   801
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   802
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   803
			function updateMenuMaxDepth( depthChange ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   804
				var depth, newDepth = menuMaxDepth;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   805
				if ( depthChange === 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   806
					return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   807
				} else if ( depthChange > 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   808
					depth = maxChildDepth + depthChange;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   809
					if( depth > menuMaxDepth )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   810
						newDepth = depth;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   811
				} else if ( depthChange < 0 && maxChildDepth == menuMaxDepth ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   812
					while( ! $('.menu-item-depth-' + newDepth, api.menuList).length && newDepth > 0 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   813
						newDepth--;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   814
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   815
				// Update the depth class.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   816
				body.removeClass( 'menu-max-depth-' + menuMaxDepth ).addClass( 'menu-max-depth-' + newDepth );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   817
				menuMaxDepth = newDepth;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   818
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   819
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   820
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   821
		initManageLocations : function () {
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   822
			$('#menu-locations-wrap form').on( 'submit', function(){
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   823
				window.onbeforeunload = null;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   824
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   825
			$('.menu-location-menus select').on('change', function () {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   826
				var editLink = $(this).closest('tr').find('.locations-edit-menu-link');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   827
				if ($(this).find('option:selected').data('orig'))
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   828
					editLink.show();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   829
				else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   830
					editLink.hide();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   831
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   832
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   833
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   834
		attachMenuEditListeners : function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   835
			var that = this;
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   836
			$('#update-nav-menu').on('click', function(e) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   837
				if ( e.target && e.target.className ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   838
					if ( -1 != e.target.className.indexOf('item-edit') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   839
						return that.eventOnClickEditLink(e.target);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   840
					} else if ( -1 != e.target.className.indexOf('menu-save') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   841
						return that.eventOnClickMenuSave(e.target);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   842
					} else if ( -1 != e.target.className.indexOf('menu-delete') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   843
						return that.eventOnClickMenuDelete(e.target);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   844
					} else if ( -1 != e.target.className.indexOf('item-delete') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   845
						return that.eventOnClickMenuItemDelete(e.target);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   846
					} else if ( -1 != e.target.className.indexOf('item-cancel') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   847
						return that.eventOnClickCancelLink(e.target);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   848
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   849
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   850
			});
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   851
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   852
			$( '#menu-name' ).on( 'input', _.debounce( function () {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   853
				var menuName = $( document.getElementById( 'menu-name' ) ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   854
					menuNameVal = menuName.val();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   855
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   856
				if ( ! menuNameVal || ! menuNameVal.replace( /\s+/, '' ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   857
					// Add warning for invalid menu name.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   858
					menuName.parent().addClass( 'form-invalid' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   859
				} else {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   860
					// Remove warning for valid menu name.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   861
					menuName.parent().removeClass( 'form-invalid' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   862
				}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   863
			}, 500 ) );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   864
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   865
			$('#add-custom-links input[type="text"]').on( 'keypress', function(e){
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   866
				$('#customlinkdiv').removeClass('form-invalid');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   867
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   868
				if ( e.keyCode === 13 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   869
					e.preventDefault();
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   870
					$( '#submit-customlinkdiv' ).trigger( 'click' );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   871
				}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   872
			});
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   873
		},
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   874
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   875
		/**
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   876
		 * Handle toggling bulk selection checkboxes for menu items.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   877
		 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   878
		 * @since 5.8.0
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   879
		 */ 
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   880
		attachBulkSelectButtonListeners : function() {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   881
			var that = this;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   882
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   883
			$( '.bulk-select-switcher' ).on( 'change', function() {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   884
				if ( this.checked ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   885
					$( '.bulk-select-switcher' ).prop( 'checked', true );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   886
					that.enableBulkSelection();
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   887
				} else {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   888
					$( '.bulk-select-switcher' ).prop( 'checked', false );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   889
					that.disableBulkSelection();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   890
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   891
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   892
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   893
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   894
		/**
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   895
		 * Enable bulk selection checkboxes for menu items.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   896
		 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   897
		 * @since 5.8.0
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   898
		 */ 
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   899
		enableBulkSelection : function() {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   900
			var checkbox = $( '#menu-to-edit .menu-item-checkbox' );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   901
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   902
			$( '#menu-to-edit' ).addClass( 'bulk-selection' );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   903
			$( '#nav-menu-bulk-actions-top' ).addClass( 'bulk-selection' );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   904
			$( '#nav-menu-bulk-actions-bottom' ).addClass( 'bulk-selection' );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   905
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   906
			$.each( checkbox, function() {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   907
				$(this).prop( 'disabled', false );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   908
			});
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   909
		},
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   910
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   911
		/**
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   912
		 * Disable bulk selection checkboxes for menu items.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   913
		 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   914
		 * @since 5.8.0
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   915
		 */ 
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   916
		disableBulkSelection : function() {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   917
			var checkbox = $( '#menu-to-edit .menu-item-checkbox' );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   918
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   919
			$( '#menu-to-edit' ).removeClass( 'bulk-selection' );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   920
			$( '#nav-menu-bulk-actions-top' ).removeClass( 'bulk-selection' );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   921
			$( '#nav-menu-bulk-actions-bottom' ).removeClass( 'bulk-selection' );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   922
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   923
			if ( $( '.menu-items-delete' ).is( '[aria-describedby="pending-menu-items-to-delete"]' ) ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   924
				$( '.menu-items-delete' ).removeAttr( 'aria-describedby' );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   925
			}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   926
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   927
			$.each( checkbox, function() {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   928
				$(this).prop( 'disabled', true ).prop( 'checked', false );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   929
			});
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   930
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   931
			$( '.menu-items-delete' ).addClass( 'disabled' );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   932
			$( '#pending-menu-items-to-delete ul' ).empty();
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   933
		},
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   934
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   935
		/**
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   936
		 * Listen for state changes on bulk action checkboxes.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   937
		 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   938
		 * @since 5.8.0
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   939
		 */ 
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   940
		attachMenuCheckBoxListeners : function() {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   941
			var that = this;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   942
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   943
			$( '#menu-to-edit' ).on( 'change', '.menu-item-checkbox', function() {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   944
				that.setRemoveSelectedButtonStatus();
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   945
			});
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   946
		},
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   947
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   948
		/**
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   949
		 * Create delete button to remove menu items from collection.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   950
		 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   951
		 * @since 5.8.0
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   952
		 */ 
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   953
		attachMenuItemDeleteButton : function() {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   954
			var that = this;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   955
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   956
			$( document ).on( 'click', '.menu-items-delete', function( e ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   957
				var itemsPendingDeletion, itemsPendingDeletionList, deletionSpeech;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   958
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   959
				e.preventDefault();
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   960
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   961
				if ( ! $(this).hasClass( 'disabled' ) ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   962
					$.each( $( '.menu-item-checkbox:checked' ), function( index, element ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   963
						$( element ).parents( 'li' ).find( 'a.item-delete' ).trigger( 'click' );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   964
					});
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   965
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   966
					$( '.menu-items-delete' ).addClass( 'disabled' );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   967
					$( '.bulk-select-switcher' ).prop( 'checked', false );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   968
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   969
					itemsPendingDeletion     = '';
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   970
					itemsPendingDeletionList = $( '#pending-menu-items-to-delete ul li' );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   971
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   972
					$.each( itemsPendingDeletionList, function( index, element ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   973
						var itemName = $( element ).find( '.pending-menu-item-name' ).text();
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   974
						var itemSpeech = menus.menuItemDeletion.replace( '%s', itemName );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   975
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   976
						itemsPendingDeletion += itemSpeech;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   977
						if ( ( index + 1 ) < itemsPendingDeletionList.length ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   978
							itemsPendingDeletion += ', ';
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   979
						}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   980
					});
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   981
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   982
					deletionSpeech = menus.itemsDeleted.replace( '%s', itemsPendingDeletion );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   983
					wp.a11y.speak( deletionSpeech, 'polite' );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   984
					that.disableBulkSelection();
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   985
				}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   986
			});
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   987
		},
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   988
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   989
		/**
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   990
		 * List menu items awaiting deletion.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   991
		 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   992
		 * @since 5.8.0
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   993
		 */ 
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   994
		attachPendingMenuItemsListForDeletion : function() {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   995
			$( '#post-body-content' ).on( 'change', '.menu-item-checkbox', function() {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   996
				var menuItemName, menuItemType, menuItemID, listedMenuItem;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   997
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   998
				if ( ! $( '.menu-items-delete' ).is( '[aria-describedby="pending-menu-items-to-delete"]' ) ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   999
					$( '.menu-items-delete' ).attr( 'aria-describedby', 'pending-menu-items-to-delete' );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1000
				}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1001
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1002
				menuItemName = $(this).next().text();
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1003
				menuItemType = $(this).parent().next( '.item-controls' ).find( '.item-type' ).text();
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1004
				menuItemID   = $(this).attr( 'data-menu-item-id' );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1005
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1006
				listedMenuItem = $( '#pending-menu-items-to-delete ul' ).find( '[data-menu-item-id=' + menuItemID + ']' );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1007
				if ( listedMenuItem.length > 0 ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1008
					listedMenuItem.remove();
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1009
				}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1010
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1011
				if ( this.checked === true ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1012
					$( '#pending-menu-items-to-delete ul' ).append(
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1013
						'<li data-menu-item-id="' + menuItemID + '">' +
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1014
							'<span class="pending-menu-item-name">' + menuItemName + '</span> ' +
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1015
							'<span class="pending-menu-item-type">(' + menuItemType + ')</span>' +
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1016
							'<span class="separator"></span>' +
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1017
						'</li>'
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1018
					);
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1019
				}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1020
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1021
				$( '#pending-menu-items-to-delete li .separator' ).html( ', ' );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1022
				$( '#pending-menu-items-to-delete li .separator' ).last().html( '.' );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1023
			});
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1024
		},
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1025
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1026
		/**
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1027
		 * Set status of bulk delete checkbox.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1028
		 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1029
		 * @since 5.8.0
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1030
		 */ 
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1031
		setBulkDeleteCheckboxStatus : function() {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1032
			var that = this;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1033
			var checkbox = $( '#menu-to-edit .menu-item-checkbox' );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1034
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1035
			$.each( checkbox, function() {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1036
				if ( $(this).prop( 'disabled' ) ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1037
					$(this).prop( 'disabled', false );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1038
				} else {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1039
					$(this).prop( 'disabled', true );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1040
				}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1041
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1042
				if ( $(this).is( ':checked' ) ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1043
					$(this).prop( 'checked', false );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1044
				}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1045
			});
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1046
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1047
			that.setRemoveSelectedButtonStatus();
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1048
		},
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1049
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1050
		/**
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1051
		 * Set status of menu items removal button.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1052
		 *
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1053
		 * @since 5.8.0
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1054
		 */ 
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1055
		setRemoveSelectedButtonStatus : function() {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1056
			var button = $( '.menu-items-delete' );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1057
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1058
			if ( $( '.menu-item-checkbox:checked' ).length > 0 ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1059
				button.removeClass( 'disabled' );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1060
			} else {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1061
				button.addClass( 'disabled' );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1062
			}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1063
		},
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1064
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1065
		attachMenuSaveSubmitListeners : function() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1066
			/*
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1067
			 * When a navigation menu is saved, store a JSON representation of all form data
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1068
			 * in a single input to avoid PHP `max_input_vars` limitations. See #14134.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1069
			 */
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1070
			$( '#update-nav-menu' ).on( 'submit', function() {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1071
				var navMenuData = $( '#update-nav-menu' ).serializeArray();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1072
				$( '[name="nav-menu-data"]' ).val( JSON.stringify( navMenuData ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1073
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1074
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1075
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1076
		attachThemeLocationsListeners : function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1077
			var loc = $('#nav-menu-theme-locations'), params = {};
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1078
			params.action = 'menu-locations-save';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1079
			params['menu-settings-column-nonce'] = $('#menu-settings-column-nonce').val();
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1080
			loc.find('input[type="submit"]').on( 'click', function() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1081
				loc.find('select').each(function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1082
					params[this.name] = $(this).val();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1083
				});
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1084
				loc.find( '.spinner' ).addClass( 'is-active' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1085
				$.post( ajaxurl, params, function() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1086
					loc.find( '.spinner' ).removeClass( 'is-active' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1087
				});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1088
				return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1089
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1090
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1091
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1092
		attachQuickSearchListeners : function() {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1093
			var searchTimer;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1094
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1095
			// Prevent form submission.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1096
			$( '#nav-menu-meta' ).on( 'submit', function( event ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1097
				event.preventDefault();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1098
			});
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1099
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1100
			$( '#nav-menu-meta' ).on( 'input', '.quick-search', function() {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1101
				var $this = $( this );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1102
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1103
				$this.attr( 'autocomplete', 'off' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1104
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1105
				if ( searchTimer ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1106
					clearTimeout( searchTimer );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1107
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1108
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1109
				searchTimer = setTimeout( function() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1110
					api.updateQuickSearchResults( $this );
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1111
				}, 500 );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1112
			}).on( 'blur', '.quick-search', function() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1113
				api.lastSearch = '';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1114
			});
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1115
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1116
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1117
		updateQuickSearchResults : function(input) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1118
			var panel, params,
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1119
				minSearchLength = 2,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1120
				q = input.val();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1121
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1122
			/*
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1123
			 * Minimum characters for a search. Also avoid a new Ajax search when
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1124
			 * the pressed key (e.g. arrows) doesn't change the searched term.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1125
			 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1126
			if ( q.length < minSearchLength || api.lastSearch == q ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1127
				return;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1128
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1129
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1130
			api.lastSearch = q;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1131
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1132
			panel = input.parents('.tabs-panel');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1133
			params = {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1134
				'action': 'menu-quick-search',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1135
				'response-format': 'markup',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1136
				'menu': $('#menu').val(),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1137
				'menu-settings-column-nonce': $('#menu-settings-column-nonce').val(),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1138
				'q': q,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1139
				'type': input.attr('name')
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1140
			};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1141
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1142
			$( '.spinner', panel ).addClass( 'is-active' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1143
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1144
			$.post( ajaxurl, params, function(menuMarkup) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1145
				api.processQuickSearchQueryResponse(menuMarkup, params, panel);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1146
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1147
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1148
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1149
		addCustomLink : function( processMethod ) {
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1150
			var url = $('#custom-menu-item-url').val().toString(),
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1151
				label = $('#custom-menu-item-name').val();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1152
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1153
			if ( '' !== url ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1154
				url = url.trim();
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1155
			}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1156
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1157
			processMethod = processMethod || api.addMenuItemToBottom;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1158
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1159
			if ( '' === url || 'https://' == url || 'http://' == url ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1160
				$('#customlinkdiv').addClass('form-invalid');
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1161
				return false;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1162
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1163
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1164
			// Show the Ajax spinner.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1165
			$( '.customlinkdiv .spinner' ).addClass( 'is-active' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1166
			this.addLinkToMenu( url, label, processMethod, function() {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1167
				// Remove the Ajax spinner.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1168
				$( '.customlinkdiv .spinner' ).removeClass( 'is-active' );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1169
				// Set custom link form back to defaults.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1170
				$('#custom-menu-item-name').val('').trigger( 'blur' );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1171
				$( '#custom-menu-item-url' ).val( '' ).attr( 'placeholder', 'https://' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1172
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1173
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1174
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1175
		addLinkToMenu : function(url, label, processMethod, callback) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1176
			processMethod = processMethod || api.addMenuItemToBottom;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1177
			callback = callback || function(){};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1178
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1179
			api.addItemToMenu({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1180
				'-1': {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1181
					'menu-item-type': 'custom',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1182
					'menu-item-url': url,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1183
					'menu-item-title': label
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1184
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1185
			}, processMethod, callback);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1186
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1187
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1188
		addItemToMenu : function(menuItem, processMethod, callback) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1189
			var menu = $('#menu').val(),
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1190
				nonce = $('#menu-settings-column-nonce').val(),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1191
				params;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1192
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1193
			processMethod = processMethod || function(){};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1194
			callback = callback || function(){};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1195
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1196
			params = {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1197
				'action': 'add-menu-item',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1198
				'menu': menu,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1199
				'menu-settings-column-nonce': nonce,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1200
				'menu-item': menuItem
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1201
			};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1202
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1203
			$.post( ajaxurl, params, function(menuMarkup) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1204
				var ins = $('#menu-instructions');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1205
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1206
				menuMarkup = menuMarkup || '';
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1207
				menuMarkup = menuMarkup.toString().trim(); // Trim leading whitespaces.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1208
				processMethod(menuMarkup, params);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1209
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1210
				// Make it stand out a bit more visually, by adding a fadeIn.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1211
				$( 'li.pending' ).hide().fadeIn('slow');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1212
				$( '.drag-instructions' ).show();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1213
				if( ! ins.hasClass( 'menu-instructions-inactive' ) && ins.siblings().length )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1214
					ins.addClass( 'menu-instructions-inactive' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1215
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1216
				callback();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1217
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1218
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1219
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1220
		/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1221
		 * Process the add menu item request response into menu list item. Appends to menu.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1222
		 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1223
		 * @param {string} menuMarkup The text server response of menu item markup.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1224
		 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1225
		 * @fires document#menu-item-added Passes menuMarkup as a jQuery object.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1226
		 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1227
		addMenuItemToBottom : function( menuMarkup ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1228
			var $menuMarkup = $( menuMarkup );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1229
			$menuMarkup.hideAdvancedMenuItemFields().appendTo( api.targetList );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1230
			api.refreshKeyboardAccessibility();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1231
			api.refreshAdvancedAccessibility();
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  1232
			wp.a11y.speak( menus.itemAdded );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1233
			$( document ).trigger( 'menu-item-added', [ $menuMarkup ] );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1234
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1235
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1236
		/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1237
		 * Process the add menu item request response into menu list item. Prepends to menu.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1238
		 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1239
		 * @param {string} menuMarkup The text server response of menu item markup.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1240
		 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1241
		 * @fires document#menu-item-added Passes menuMarkup as a jQuery object.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1242
		 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1243
		addMenuItemToTop : function( menuMarkup ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1244
			var $menuMarkup = $( menuMarkup );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1245
			$menuMarkup.hideAdvancedMenuItemFields().prependTo( api.targetList );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1246
			api.refreshKeyboardAccessibility();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1247
			api.refreshAdvancedAccessibility();
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  1248
			wp.a11y.speak( menus.itemAdded );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1249
			$( document ).trigger( 'menu-item-added', [ $menuMarkup ] );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1250
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1251
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1252
		attachUnsavedChangesListener : function() {
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1253
			$('#menu-management input, #menu-management select, #menu-management, #menu-management textarea, .menu-location-menus select').on( 'change', function(){
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1254
				api.registerChange();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1255
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1256
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1257
			if ( 0 !== $('#menu-to-edit').length || 0 !== $('.menu-location-menus select').length ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1258
				window.onbeforeunload = function(){
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1259
					if ( api.menusChanged )
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1260
						return wp.i18n.__( 'The changes you made will be lost if you navigate away from this page.' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1261
				};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1262
			} else {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1263
				// Make the post boxes read-only, as they can't be used yet.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1264
				$( '#menu-settings-column' ).find( 'input,select' ).end().find( 'a' ).attr( 'href', '#' ).off( 'click' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1265
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1266
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1267
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1268
		registerChange : function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1269
			api.menusChanged = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1270
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1271
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1272
		attachTabsPanelListeners : function() {
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1273
			$('#menu-settings-column').on('click', function(e) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1274
				var selectAreaMatch, selectAll, panelId, wrapper, items,
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1275
					target = $(e.target);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1276
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1277
				if ( target.hasClass('nav-tab-link') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1278
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1279
					panelId = target.data( 'type' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1280
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1281
					wrapper = target.parents('.accordion-section-content').first();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1282
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1283
					// Upon changing tabs, we want to uncheck all checkboxes.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1284
					$( 'input', wrapper ).prop( 'checked', false );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1285
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1286
					$('.tabs-panel-active', wrapper).removeClass('tabs-panel-active').addClass('tabs-panel-inactive');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1287
					$('#' + panelId, wrapper).removeClass('tabs-panel-inactive').addClass('tabs-panel-active');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1288
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1289
					$('.tabs', wrapper).removeClass('tabs');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1290
					target.parent().addClass('tabs');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1291
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1292
					// Select the search bar.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1293
					$('.quick-search', wrapper).trigger( 'focus' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1294
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1295
					// Hide controls in the search tab if no items found.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1296
					if ( ! wrapper.find( '.tabs-panel-active .menu-item-title' ).length ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1297
						wrapper.addClass( 'has-no-menu-item' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1298
					} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1299
						wrapper.removeClass( 'has-no-menu-item' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1300
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1301
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1302
					e.preventDefault();
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1303
				} else if ( target.hasClass( 'select-all' ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1304
					selectAreaMatch = target.closest( '.button-controls' ).data( 'items-type' );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1305
					if ( selectAreaMatch ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1306
						items = $( '#' + selectAreaMatch + ' .tabs-panel-active .menu-item-title input' );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1307
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1308
						if ( items.length === items.filter( ':checked' ).length && ! target.is( ':checked' ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1309
							items.prop( 'checked', false );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1310
						} else if ( target.is( ':checked' ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1311
							items.prop( 'checked', true );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1312
						}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1313
					}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1314
				} else if ( target.hasClass( 'menu-item-checkbox' ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1315
					selectAreaMatch = target.closest( '.tabs-panel-active' ).parent().attr( 'id' );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1316
					if ( selectAreaMatch ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1317
						items     = $( '#' + selectAreaMatch + ' .tabs-panel-active .menu-item-title input' );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1318
						selectAll = $( '.button-controls[data-items-type="' + selectAreaMatch + '"] .select-all' );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1319
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1320
						if ( items.length === items.filter( ':checked' ).length && ! selectAll.is( ':checked' ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1321
							selectAll.prop( 'checked', true );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1322
						} else if ( selectAll.is( ':checked' ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1323
							selectAll.prop( 'checked', false );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1324
						}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1325
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1326
				} else if ( target.hasClass('submit-add-to-menu') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1327
					api.registerChange();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1328
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1329
					if ( e.target.id && 'submit-customlinkdiv' == e.target.id )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1330
						api.addCustomLink( api.addMenuItemToBottom );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1331
					else if ( e.target.id && -1 != e.target.id.indexOf('submit-') )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1332
						$('#' + e.target.id.replace(/submit-/, '')).addSelectedToMenu( api.addMenuItemToBottom );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1333
					return false;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1334
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1335
			});
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1336
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1337
			/*
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1338
			 * Delegate the `click` event and attach it just to the pagination
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1339
			 * links thus excluding the current page `<span>`. See ticket #35577.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1340
			 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1341
			$( '#nav-menu-meta' ).on( 'click', 'a.page-numbers', function() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1342
				var $container = $( this ).closest( '.inside' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1343
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1344
				$.post( ajaxurl, this.href.replace( /.*\?/, '' ).replace( /action=([^&]*)/, '' ) + '&action=menu-get-metabox',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1345
					function( resp ) {
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1346
						var metaBoxData = JSON.parse( resp ),
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1347
							toReplace;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1348
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1349
						if ( -1 === resp.indexOf( 'replace-id' ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1350
							return;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1351
						}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1352
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1353
						// Get the post type menu meta box to update.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1354
						toReplace = document.getElementById( metaBoxData['replace-id'] );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1355
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1356
						if ( ! metaBoxData.markup || ! toReplace ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1357
							return;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1358
						}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1359
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1360
						// Update the post type menu meta box with new content from the response.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1361
						$container.html( metaBoxData.markup );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1362
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1363
				);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1364
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1365
				return false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1366
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1367
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1368
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1369
		eventOnClickEditLink : function(clickedEl) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1370
			var settings, item,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1371
			matchedSection = /#(.*)$/.exec(clickedEl.href);
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1372
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1373
			if ( matchedSection && matchedSection[1] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1374
				settings = $('#'+matchedSection[1]);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1375
				item = settings.parent();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1376
				if( 0 !== item.length ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1377
					if( item.hasClass('menu-item-edit-inactive') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1378
						if( ! settings.data('menu-item-data') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1379
							settings.data( 'menu-item-data', settings.getItemData() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1380
						}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1381
						settings.slideDown('fast');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1382
						item.removeClass('menu-item-edit-inactive')
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1383
							.addClass('menu-item-edit-active');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1384
					} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1385
						settings.slideUp('fast');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1386
						item.removeClass('menu-item-edit-active')
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1387
							.addClass('menu-item-edit-inactive');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1388
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1389
					return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1390
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1391
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1392
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1393
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1394
		eventOnClickCancelLink : function(clickedEl) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1395
			var settings = $( clickedEl ).closest( '.menu-item-settings' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1396
				thisMenuItem = $( clickedEl ).closest( '.menu-item' );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1397
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1398
			thisMenuItem.removeClass( 'menu-item-edit-active' ).addClass( 'menu-item-edit-inactive' );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1399
			settings.setItemData( settings.data( 'menu-item-data' ) ).hide();
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1400
			// Restore the title of the currently active/expanded menu item.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1401
			thisMenuItem.find( '.menu-item-title' ).text( settings.data( 'menu-item-data' )['menu-item-title'] );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1402
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1403
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1404
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1405
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1406
		eventOnClickMenuSave : function() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1407
			var locs = '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1408
			menuName = $('#menu-name'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1409
			menuNameVal = menuName.val();
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1410
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1411
			// Cancel and warn if invalid menu name.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1412
			if ( ! menuNameVal || ! menuNameVal.replace( /\s+/, '' ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1413
				menuName.parent().addClass( 'form-invalid' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1414
				return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1415
			}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1416
			// Copy menu theme locations.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1417
			$('#nav-menu-theme-locations select').each(function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1418
				locs += '<input type="hidden" name="' + this.name + '" value="' + $(this).val() + '" />';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1419
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1420
			$('#update-nav-menu').append( locs );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1421
			// Update menu item position data.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1422
			api.menuList.find('.menu-item-data-position').val( function(index) { return index + 1; } );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1423
			window.onbeforeunload = null;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1424
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1425
			return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1426
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1427
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1428
		eventOnClickMenuDelete : function() {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1429
			// Delete warning AYS.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1430
			if ( window.confirm( wp.i18n.__( 'You are about to permanently delete this menu.\n\'Cancel\' to stop, \'OK\' to delete.' ) ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1431
				window.onbeforeunload = null;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1432
				return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1433
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1434
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1435
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1436
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1437
		eventOnClickMenuItemDelete : function(clickedEl) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1438
			var itemID = parseInt(clickedEl.id.replace('delete-', ''), 10);
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1439
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1440
			api.removeMenuItem( $('#menu-item-' + itemID) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1441
			api.registerChange();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1442
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1443
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1444
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1445
		/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1446
		 * Process the quick search response into a search result
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1447
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1448
		 * @param string resp The server response to the query.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1449
		 * @param object req The request arguments.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1450
		 * @param jQuery panel The tabs panel we're searching in.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1451
		 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1452
		processQuickSearchQueryResponse : function(resp, req, panel) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1453
			var matched, newID,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1454
			takenIDs = {},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1455
			form = document.getElementById('nav-menu-meta'),
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1456
			pattern = /menu-item[(\[^]\]*/,
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1457
			$items = $('<div>').html(resp).find('li'),
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1458
			wrapper = panel.closest( '.accordion-section-content' ),
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1459
			selectAll = wrapper.find( '.button-controls .select-all' ),
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1460
			$item;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1461
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1462
			if( ! $items.length ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1463
				$('.categorychecklist', panel).html( '<li><p>' + wp.i18n.__( 'No results found.' ) + '</p></li>' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1464
				$( '.spinner', panel ).removeClass( 'is-active' );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1465
				wrapper.addClass( 'has-no-menu-item' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1466
				return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1467
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1468
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1469
			$items.each(function(){
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1470
				$item = $(this);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1471
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1472
				// Make a unique DB ID number.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1473
				matched = pattern.exec($item.html());
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1474
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1475
				if ( matched && matched[1] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1476
					newID = matched[1];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1477
					while( form.elements['menu-item[' + newID + '][menu-item-type]'] || takenIDs[ newID ] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1478
						newID--;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1479
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1480
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1481
					takenIDs[newID] = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1482
					if ( newID != matched[1] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1483
						$item.html( $item.html().replace(new RegExp(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1484
							'menu-item\\[' + matched[1] + '\\]', 'g'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1485
							'menu-item[' + newID + ']'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1486
						) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1487
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1488
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1489
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1490
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1491
			$('.categorychecklist', panel).html( $items );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1492
			$( '.spinner', panel ).removeClass( 'is-active' );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1493
			wrapper.removeClass( 'has-no-menu-item' );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1494
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1495
			if ( selectAll.is( ':checked' ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1496
				selectAll.prop( 'checked', false );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1497
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1498
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1499
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1500
		/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1501
		 * Remove a menu item.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1502
		 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1503
		 * @param {Object} el The element to be removed as a jQuery object.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1504
		 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1505
		 * @fires document#menu-removing-item Passes the element to be removed.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1506
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1507
		removeMenuItem : function(el) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1508
			var children = el.childMenuItems();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1509
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1510
			$( document ).trigger( 'menu-removing-item', [ el ] );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1511
			el.addClass('deleting').animate({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1512
					opacity : 0,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1513
					height: 0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1514
				}, 350, function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1515
					var ins = $('#menu-instructions');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1516
					el.remove();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1517
					children.shiftDepthClass( -1 ).updateParentMenuItemDBId();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1518
					if ( 0 === $( '#menu-to-edit li' ).length ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1519
						$( '.drag-instructions' ).hide();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1520
						ins.removeClass( 'menu-instructions-inactive' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1521
					}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1522
					api.refreshAdvancedAccessibility();
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
  1523
					wp.a11y.speak( menus.itemRemoved );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1524
				});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1525
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1526
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1527
		depthToPx : function(depth) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1528
			return depth * api.options.menuItemDepthPerLevel;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1529
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1530
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1531
		pxToDepth : function(px) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1532
			return Math.floor(px / api.options.menuItemDepthPerLevel);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1533
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1534
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1535
	};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1536
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1537
	$( function() {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1538
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1539
		wpNavMenu.init();
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1540
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1541
		// Prevent focused element from being hidden by the sticky footer.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1542
		$( '.menu-edit a, .menu-edit button, .menu-edit input, .menu-edit textarea, .menu-edit select' ).on('focus', function() {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1543
			if ( window.innerWidth >= 783 ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1544
				var navMenuHeight = $( '#nav-menu-footer' ).height() + 20;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1545
				var bottomOffset = $(this).offset().top - ( $(window).scrollTop() + $(window).height() - $(this).height() );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1546
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1547
				if ( bottomOffset > 0 ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1548
					bottomOffset = 0;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1549
				}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1550
				bottomOffset = bottomOffset * -1;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1551
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1552
				if( bottomOffset < navMenuHeight ) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1553
					var scrollTop = $(document).scrollTop();
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1554
					$(document).scrollTop( scrollTop + ( navMenuHeight - bottomOffset ) );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1555
				}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1556
			}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1557
		});
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
  1558
	});
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1559
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1560
})(jQuery);