wp/wp-admin/js/nav-menu.js
author ymh <ymh.work@gmail.com>
Tue, 15 Dec 2020 13:49:49 +0100
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 18 be944660c56a
permissions -rw-r--r--
update enmi-conf
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
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
			this.attachQuickSearchListeners();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
			this.attachThemeLocationsListeners();
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    50
			this.attachMenuSaveSubmitListeners();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
			this.attachTabsPanelListeners();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
			this.attachUnsavedChangesListener();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
			if ( api.menuList.length )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
				this.initSortables();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
			if ( menus.oneThemeLocationNoMenus )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
				$( '#posttype-page' ).addSelectedToMenu( api.addMenuItemToBottom );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
			this.initManageLocations();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
			this.initAccessibility();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
			this.initToggles();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    67
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    68
			this.initPreviewing();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
		jQueryExtensions : function() {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    72
			// jQuery extensions.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
			$.fn.extend({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
				menuItemDepth : function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
					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
    76
					return api.pxToDepth( margin && -1 != margin.indexOf('px') ? margin.slice(0, -2) : 0 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
				},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
				updateDepthClass : function(current, prev) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
					return this.each(function(){
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
						var t = $(this);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
						prev = prev || t.menuItemDepth();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
						$(this).removeClass('menu-item-depth-'+ prev )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
							.addClass('menu-item-depth-'+ current );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
					});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
				},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
				shiftDepthClass : function(change) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
					return this.each(function(){
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
						var t = $(this),
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    89
							depth = t.menuItemDepth(),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    90
							newDepth = depth + change;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    91
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    92
						t.removeClass( 'menu-item-depth-'+ depth )
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    93
							.addClass( 'menu-item-depth-'+ ( newDepth ) );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    94
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    95
						if ( 0 === newDepth ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    96
							t.find( '.is-submenu' ).hide();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    97
						}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
					});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
				},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
				childMenuItems : function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
					var result = $();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
					this.each(function(){
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   103
						var t = $(this), depth = t.menuItemDepth(), next = t.next( '.menu-item' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
						while( next.length && next.menuItemDepth() > depth ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
							result = result.add( next );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   106
							next = next.next( '.menu-item' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
						}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
					});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
					return result;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
				},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
				shiftHorizontally : function( dir ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
					return this.each(function(){
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
						var t = $(this),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
							depth = t.menuItemDepth(),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
							newDepth = depth + dir;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   117
						// Change .menu-item-depth-n class.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
						t.moveHorizontally( newDepth, depth );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
					});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
				},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
				moveHorizontally : function( newDepth, depth ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
					return this.each(function(){
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
						var t = $(this),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
							children = t.childMenuItems(),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
							diff = newDepth - depth,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
							subItemText = t.find('.is-submenu');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   127
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   128
						// Change .menu-item-depth-n class.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
						t.updateDepthClass( newDepth, depth ).updateParentMenuItemDBId();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   130
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   131
						// If it has children, move those too.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
						if ( children ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   133
							children.each(function() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
								var t = $(this),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
									thisDepth = t.menuItemDepth(),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
									newDepth = thisDepth + diff;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
								t.updateDepthClass(newDepth, thisDepth).updateParentMenuItemDBId();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   138
							});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
						}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   141
						// Show "Sub item" helper text.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
						if (0 === newDepth)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   143
							subItemText.hide();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
						else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
							subItemText.show();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   146
					});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
				},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   148
				updateParentMenuItemDBId : function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   149
					return this.each(function(){
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   150
						var item = $(this),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   151
							input = item.find( '.menu-item-data-parent-id' ),
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   152
							depth = parseInt( item.menuItemDepth(), 10 ),
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
							parentDepth = depth - 1,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   154
							parent = item.prevAll( '.menu-item-depth-' + parentDepth ).first();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   155
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   156
						if ( 0 === depth ) { // Item is on the top level, has no parent.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
							input.val(0);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   158
						} else { // Find the parent item, and retrieve its object id.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
							input.val( parent.find( '.menu-item-data-db-id' ).val() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
						}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
					});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
				},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
				hideAdvancedMenuItemFields : function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
					return this.each(function(){
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
						var that = $(this);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
						$('.hide-column-tog').not(':checked').each(function(){
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
							that.find('.field-' + $(this).val() ).addClass('hidden-field');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
						});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
					});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   170
				},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   171
				/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
				 * Adds selected menu items to the menu.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
				 *
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   174
				 * @ignore
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   175
				 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   176
				 * @param jQuery metabox The metabox jQuery object.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
				 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
				addSelectedToMenu : function(processMethod) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   179
					if ( 0 === $('#menu-to-edit').length ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   180
						return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   181
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
					return this.each(function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   184
						var t = $(this), menuItems = {},
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   185
							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
   186
							re = /menu-item\[([^\]]*)/;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   187
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   188
						processMethod = processMethod || api.addMenuItemToBottom;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
						// If no items are checked, bail.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   191
						if ( !checkboxes.length )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   192
							return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   194
						// Show the Ajax spinner.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   195
						t.find( '.button-controls .spinner' ).addClass( 'is-active' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   197
						// Retrieve menu item data.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   198
						$(checkboxes).each(function(){
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   199
							var t = $(this),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   200
								listItemDBIDMatch = re.exec( t.attr('name') ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   201
								listItemDBID = 'undefined' == typeof listItemDBIDMatch[1] ? 0 : parseInt(listItemDBIDMatch[1], 10);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   202
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   203
							if ( this.className && -1 != this.className.indexOf('add-to-top') )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
								processMethod = api.addMenuItemToTop;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
							menuItems[listItemDBID] = t.closest('li').getItemData( 'add-menu-item', listItemDBID );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   206
						});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   207
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   208
						// Add the items.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   209
						api.addItemToMenu(menuItems, processMethod, function(){
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   210
							// Deselect the items and hide the Ajax spinner.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   211
							checkboxes.prop( 'checked', false );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   212
							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
   213
							t.find( '.button-controls .spinner' ).removeClass( 'is-active' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   214
						});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   215
					});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   216
				},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   217
				getItemData : function( itemType, id ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   218
					itemType = itemType || 'menu-item';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   219
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   220
					var itemData = {}, i,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   221
					fields = [
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   222
						'menu-item-db-id',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   223
						'menu-item-object-id',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   224
						'menu-item-object',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   225
						'menu-item-parent-id',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   226
						'menu-item-position',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   227
						'menu-item-type',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   228
						'menu-item-title',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   229
						'menu-item-url',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
						'menu-item-description',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   231
						'menu-item-attr-title',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   232
						'menu-item-target',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
						'menu-item-classes',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
						'menu-item-xfn'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   235
					];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   236
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   237
					if( !id && itemType == 'menu-item' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   238
						id = this.find('.menu-item-data-db-id').val();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   239
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   240
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   241
					if( !id ) return itemData;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   242
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   243
					this.find('input').each(function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   244
						var field;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   245
						i = fields.length;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   246
						while ( i-- ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
							if( itemType == 'menu-item' )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   248
								field = fields[i] + '[' + id + ']';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   249
							else if( itemType == 'add-menu-item' )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   250
								field = 'menu-item[' + id + '][' + fields[i] + ']';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   251
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   252
							if (
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   253
								this.name &&
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
								field == this.name
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   255
							) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   256
								itemData[fields[i]] = this.value;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   257
							}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   258
						}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   259
					});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   260
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   261
					return itemData;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   262
				},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   263
				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
   264
					itemType = itemType || 'menu-item';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   265
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   266
					if( !id && itemType == 'menu-item' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   267
						id = $('.menu-item-data-db-id', this).val();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   268
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   269
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   270
					if( !id ) return this;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   271
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   272
					this.find('input').each(function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   273
						var t = $(this), field;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   274
						$.each( itemData, function( attr, val ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   275
							if( itemType == 'menu-item' )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   276
								field = attr + '[' + id + ']';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   277
							else if( itemType == 'add-menu-item' )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   278
								field = 'menu-item[' + id + '][' + attr + ']';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   279
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   280
							if ( field == t.attr('name') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   281
								t.val( val );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   282
							}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   283
						});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   284
					});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   285
					return this;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   286
				}
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
		countMenuItems : function( depth ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   291
			return $( '.menu-item-depth-' + depth ).length;
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
		moveMenuItem : function( $this, dir ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   295
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   296
			var items, newItemPosition, newDepth,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   297
				menuItems = $( '#menu-to-edit li' ),
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   298
				menuItemsCount = menuItems.length,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   299
				thisItem = $this.parents( 'li.menu-item' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   300
				thisItemChildren = thisItem.childMenuItems(),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   301
				thisItemData = thisItem.getItemData(),
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   302
				thisItemDepth = parseInt( thisItem.menuItemDepth(), 10 ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   303
				thisItemPosition = parseInt( thisItem.index(), 10 ),
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   304
				nextItem = thisItem.next(),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   305
				nextItemChildren = nextItem.childMenuItems(),
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   306
				nextItemDepth = parseInt( nextItem.menuItemDepth(), 10 ) + 1,
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   307
				prevItem = thisItem.prev(),
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   308
				prevItemDepth = parseInt( prevItem.menuItemDepth(), 10 ),
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   309
				prevItemId = prevItem.getItemData()['menu-item-db-id'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   310
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   311
			switch ( dir ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   312
			case 'up':
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   313
				newItemPosition = thisItemPosition - 1;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   314
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   315
				// Already at top.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   316
				if ( 0 === thisItemPosition )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   317
					break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   318
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   319
				// 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
   320
				if ( 0 === newItemPosition && 0 !== thisItemDepth )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   321
					thisItem.moveHorizontally( 0, thisItemDepth );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   322
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   323
				// If prev item is sub item, shift to match depth.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   324
				if ( 0 !== prevItemDepth )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   325
					thisItem.moveHorizontally( prevItemDepth, thisItemDepth );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   326
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   327
				// Does this item have sub items?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   328
				if ( thisItemChildren ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   329
					items = thisItem.add( thisItemChildren );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   330
					// Move the entire block.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   331
					items.detach().insertBefore( menuItems.eq( newItemPosition ) ).updateParentMenuItemDBId();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   332
				} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   333
					thisItem.detach().insertBefore( menuItems.eq( newItemPosition ) ).updateParentMenuItemDBId();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   334
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   335
				break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   336
			case 'down':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   337
				// Does this item have sub items?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   338
				if ( thisItemChildren ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   339
					items = thisItem.add( thisItemChildren ),
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   340
						nextItem = menuItems.eq( items.length + thisItemPosition ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   341
						nextItemChildren = 0 !== nextItem.childMenuItems().length;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   342
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   343
					if ( nextItemChildren ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   344
						newDepth = parseInt( nextItem.menuItemDepth(), 10 ) + 1;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   345
						thisItem.moveHorizontally( newDepth, thisItemDepth );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   346
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   347
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   348
					// Have we reached the bottom?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   349
					if ( menuItemsCount === thisItemPosition + items.length )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   350
						break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   351
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   352
					items.detach().insertAfter( menuItems.eq( thisItemPosition + items.length ) ).updateParentMenuItemDBId();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   353
				} else {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   354
					// If next item has sub items, shift depth.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   355
					if ( 0 !== nextItemChildren.length )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   356
						thisItem.moveHorizontally( nextItemDepth, thisItemDepth );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   357
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   358
					// Have we reached the bottom?
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   359
					if ( menuItemsCount === thisItemPosition + 1 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   360
						break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   361
					thisItem.detach().insertAfter( menuItems.eq( thisItemPosition + 1 ) ).updateParentMenuItemDBId();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   362
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   363
				break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   364
			case 'top':
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   365
				// Already at top.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   366
				if ( 0 === thisItemPosition )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   367
					break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   368
				// Does this item have sub items?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   369
				if ( thisItemChildren ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   370
					items = thisItem.add( thisItemChildren );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   371
					// Move the entire block.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   372
					items.detach().insertBefore( menuItems.eq( 0 ) ).updateParentMenuItemDBId();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   373
				} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   374
					thisItem.detach().insertBefore( menuItems.eq( 0 ) ).updateParentMenuItemDBId();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   375
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   376
				break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   377
			case 'left':
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   378
				// As far left as possible.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   379
				if ( 0 === thisItemDepth )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   380
					break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   381
				thisItem.shiftHorizontally( -1 );
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 'right':
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   384
				// Can't be sub item at top.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   385
				if ( 0 === thisItemPosition )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   386
					break;
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   387
				// Already sub item of prevItem.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   388
				if ( thisItemData['menu-item-parent-id'] === prevItemId )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   389
					break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   390
				thisItem.shiftHorizontally( 1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   391
				break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   392
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   393
			$this.focus();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   394
			api.registerChange();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   395
			api.refreshKeyboardAccessibility();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   396
			api.refreshAdvancedAccessibility();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   397
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   398
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   399
		initAccessibility : function() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   400
			var menu = $( '#menu-to-edit' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   401
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   402
			api.refreshKeyboardAccessibility();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   403
			api.refreshAdvancedAccessibility();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   404
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   405
			// 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
   406
			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
   407
				api.refreshAdvancedAccessibilityOfItem( $( this ).find( 'a.item-edit' ) );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   408
			} );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   409
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   410
			// 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
   411
			menu.on( 'click', 'a.item-edit', function() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   412
				api.refreshAdvancedAccessibilityOfItem( $( this ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   413
			} );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   414
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   415
			// Links for moving items.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   416
			menu.on( 'click', '.menus-move', function () {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   417
				var $this = $( this ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   418
					dir = $this.data( 'dir' );
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
				if ( 'undefined' !== typeof dir ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   421
					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
   422
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   423
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   424
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   425
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   426
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   427
		 * refreshAdvancedAccessibilityOfItem( [itemToRefresh] )
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   428
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   429
		 * Refreshes advanced accessibility buttons for one menu item.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   430
		 * 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
   431
		 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   432
		 * @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
   433
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   434
		refreshAdvancedAccessibilityOfItem : function( itemToRefresh ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   435
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   436
			// Only refresh accessibility when necessary.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   437
			if ( true !== $( itemToRefresh ).data( 'needs_accessibility_refresh' ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   438
				return;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   439
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   440
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   441
			var thisLink, thisLinkText, primaryItems, itemPosition, title,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   442
				parentItem, parentItemId, parentItemName, subItems,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   443
				$this = $( itemToRefresh ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   444
				menuItem = $this.closest( 'li.menu-item' ).first(),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   445
				depth = menuItem.menuItemDepth(),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   446
				isPrimaryMenuItem = ( 0 === depth ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   447
				itemName = $this.closest( '.menu-item-handle' ).find( '.menu-item-title' ).text(),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   448
				position = parseInt( menuItem.index(), 10 ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   449
				prevItemDepth = ( isPrimaryMenuItem ) ? depth : parseInt( depth - 1, 10 ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   450
				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
   451
				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
   452
				totalMenuItems = $('#menu-to-edit li').length,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   453
				hasSameDepthSibling = menuItem.nextAll( '.menu-item-depth-' + depth ).length;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   454
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   455
				menuItem.find( '.field-move' ).toggle( totalMenuItems > 1 );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   456
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   457
			// Where can they move this menu item?
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   458
			if ( 0 !== position ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   459
				thisLink = menuItem.find( '.menus-move-up' );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   460
				thisLink.attr( 'aria-label', menus.moveUp ).css( 'display', 'inline' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   461
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   462
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   463
			if ( 0 !== position && isPrimaryMenuItem ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   464
				thisLink = menuItem.find( '.menus-move-top' );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   465
				thisLink.attr( 'aria-label', menus.moveToTop ).css( 'display', 'inline' );
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
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   468
			if ( position + 1 !== totalMenuItems && 0 !== position ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   469
				thisLink = menuItem.find( '.menus-move-down' );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   470
				thisLink.attr( 'aria-label', menus.moveDown ).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 && 0 !== hasSameDepthSibling ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   474
				thisLink = menuItem.find( '.menus-move-down' );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   475
				thisLink.attr( 'aria-label', menus.moveDown ).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 ( ! isPrimaryMenuItem ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   479
				thisLink = menuItem.find( '.menus-move-left' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   480
				thisLinkText = menus.outFrom.replace( '%s', prevItemNameLeft );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   481
				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
   482
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   483
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   484
			if ( 0 !== position ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   485
				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
   486
					thisLink = menuItem.find( '.menus-move-right' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   487
					thisLinkText = menus.under.replace( '%s', prevItemNameRight );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   488
					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
   489
				}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   490
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   491
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   492
			if ( isPrimaryMenuItem ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   493
				primaryItems = $( '.menu-item-depth-0' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   494
				itemPosition = primaryItems.index( menuItem ) + 1,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   495
				totalMenuItems = primaryItems.length,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   496
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   497
				// String together help text for primary menu items.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   498
				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
   499
			} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   500
				parentItem = menuItem.prevAll( '.menu-item-depth-' + parseInt( depth - 1, 10 ) ).first(),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   501
				parentItemId = parentItem.find( '.menu-item-data-db-id' ).val(),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   502
				parentItemName = parentItem.find( '.menu-item-title' ).text(),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   503
				subItems = $( '.menu-item .menu-item-data-parent-id[value="' + parentItemId + '"]' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   504
				itemPosition = $( subItems.parents('.menu-item').get().reverse() ).index( menuItem ) + 1;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   505
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   506
				// String together help text for sub menu items.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   507
				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
   508
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   509
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   510
			$this.attr( 'aria-label', title );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   511
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   512
			// Mark this item's accessibility as refreshed.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   513
			$this.data( 'needs_accessibility_refresh', false );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   514
		},
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   515
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   516
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   517
		 * refreshAdvancedAccessibility
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
		 * Hides all advanced accessibility buttons and marks them for refreshing.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   520
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   521
		refreshAdvancedAccessibility : function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   522
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   523
			// Hide all the move buttons by default.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   524
			$( '.menu-item-settings .field-move .menus-move' ).hide();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   525
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   526
			// Mark all menu items as unprocessed.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   527
			$( 'a.item-edit' ).data( 'needs_accessibility_refresh', true );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   528
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   529
			// 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
   530
			$( '.menu-item-edit-active a.item-edit' ).each( function() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   531
				api.refreshAdvancedAccessibilityOfItem( this );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   532
			} );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   533
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   534
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   535
		refreshKeyboardAccessibility : function() {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   536
			$( 'a.item-edit' ).off( 'focus' ).on( 'focus', function(){
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   537
				$(this).off( 'keydown' ).on( 'keydown', function(e){
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   538
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   539
					var arrows,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   540
						$this = $( this ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   541
						thisItem = $this.parents( 'li.menu-item' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   542
						thisItemData = thisItem.getItemData();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   543
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   544
					// Bail if it's not an arrow key.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   545
					if ( 37 != e.which && 38 != e.which && 39 != e.which && 40 != e.which )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   546
						return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   547
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   548
					// Avoid multiple keydown events.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   549
					$this.off('keydown');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   550
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   551
					// Bail if there is only one menu item.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   552
					if ( 1 === $('#menu-to-edit li').length )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   553
						return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   554
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   555
					// If RTL, swap left/right arrows.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   556
					arrows = { '38': 'up', '40': 'down', '37': 'left', '39': 'right' };
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   557
					if ( $('body').hasClass('rtl') )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   558
						arrows = { '38' : 'up', '40' : 'down', '39' : 'left', '37' : 'right' };
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   559
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   560
					switch ( arrows[e.which] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   561
					case 'up':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   562
						api.moveMenuItem( $this, 'up' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   563
						break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   564
					case 'down':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   565
						api.moveMenuItem( $this, 'down' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   566
						break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   567
					case 'left':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   568
						api.moveMenuItem( $this, 'left' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   569
						break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   570
					case 'right':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   571
						api.moveMenuItem( $this, 'right' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   572
						break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   573
					}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   574
					// Put focus back on same menu item.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   575
					$( '#edit-' + thisItemData['menu-item-db-id'] ).focus();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   576
					return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   577
				});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   578
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   579
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   580
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   581
		initPreviewing : function() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   582
			// Update the item handle title when the navigation label is changed.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   583
			$( '#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
   584
				var input = $( e.currentTarget ), title, titleEl;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   585
				title = input.val();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   586
				titleEl = input.closest( '.menu-item' ).find( '.menu-item-title' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   587
				// Don't update to empty title.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   588
				if ( title ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   589
					titleEl.text( title ).removeClass( 'no-title' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   590
				} else {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   591
					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
   592
				}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   593
			} );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   594
		},
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   595
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   596
		initToggles : function() {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   597
			// Init postboxes.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   598
			postboxes.add_postbox_toggles('nav-menus');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   599
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   600
			// Adjust columns functions for menus UI.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   601
			columns.useCheckboxesForHidden();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   602
			columns.checked = function(field) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   603
				$('.field-' + field).removeClass('hidden-field');
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   604
			};
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   605
			columns.unchecked = function(field) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   606
				$('.field-' + field).addClass('hidden-field');
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   607
			};
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   608
			// Hide fields.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   609
			api.menuList.hideAdvancedMenuItemFields();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   610
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   611
			$('.hide-postbox-tog').click(function () {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   612
				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
   613
				$.post(ajaxurl, {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   614
					action: 'closed-postboxes',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   615
					hidden: hidden,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   616
					closedpostboxesnonce: jQuery('#closedpostboxesnonce').val(),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   617
					page: 'nav-menus'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   618
				});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   619
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   620
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   621
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   622
		initSortables : function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   623
			var currentDepth = 0, originalDepth, minDepth, maxDepth,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   624
				prev, next, prevBottom, nextThreshold, helperHeight, transport,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   625
				menuEdge = api.menuList.offset().left,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   626
				body = $('body'), maxChildDepth,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   627
				menuMaxDepth = initialMenuMaxDepth();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   628
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   629
			if( 0 !== $( '#menu-to-edit li' ).length )
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   630
				$( '.drag-instructions' ).show();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   631
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   632
			// Use the right edge if RTL.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   633
			menuEdge += api.isRTL ? api.menuList.width() : 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   634
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   635
			api.menuList.sortable({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   636
				handle: '.menu-item-handle',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   637
				placeholder: 'sortable-placeholder',
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   638
				items: api.options.sortableItems,
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   639
				start: function(e, ui) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   640
					var height, width, parent, children, tempHolder;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   641
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   642
					// Handle placement for RTL orientation.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   643
					if ( api.isRTL )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   644
						ui.item[0].style.right = 'auto';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   645
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   646
					transport = ui.item.children('.menu-item-transport');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   647
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   648
					// Set depths. currentDepth must be set before children are located.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   649
					originalDepth = ui.item.menuItemDepth();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   650
					updateCurrentDepth(ui, originalDepth);
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
					// Attach child elements to parent.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   653
					// Skip the placeholder.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   654
					parent = ( ui.item.next()[0] == ui.placeholder[0] ) ? ui.item.next() : ui.item;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   655
					children = parent.childMenuItems();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   656
					transport.append( children );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   657
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   658
					// Update the height of the placeholder to match the moving item.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   659
					height = transport.outerHeight();
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   660
					// 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
   661
					height += ( height > 0 ) ? (ui.placeholder.css('margin-top').slice(0, -2) * 1) : 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   662
					height += ui.helper.outerHeight();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   663
					helperHeight = height;
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   664
					height -= 2;                                              // Subtract 2 for borders.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   665
					ui.placeholder.height(height);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   666
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   667
					// Update the width of the placeholder to match the moving item.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   668
					maxChildDepth = originalDepth;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   669
					children.each(function(){
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   670
						var depth = $(this).menuItemDepth();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   671
						maxChildDepth = (depth > maxChildDepth) ? depth : maxChildDepth;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   672
					});
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   673
					width = ui.helper.find('.menu-item-handle').outerWidth(); // Get original width.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   674
					width += api.depthToPx(maxChildDepth - originalDepth);    // Account for children.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   675
					width -= 2;                                               // Subtract 2 for borders.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   676
					ui.placeholder.width(width);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   677
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   678
					// Update the list of menu items.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   679
					tempHolder = ui.placeholder.next( '.menu-item' );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   680
					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
   681
					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
   682
					$(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
   683
					ui.item.after( ui.placeholder ); // Reattach the placeholder.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   684
					tempHolder.css('margin-top', 0); // Reset the margin.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   685
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   686
					// Now that the element is complete, we can update...
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   687
					updateSharedVars(ui);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   688
				},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   689
				stop: function(e, ui) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   690
					var children, subMenuTitle,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   691
						depthChange = currentDepth - originalDepth;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   692
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   693
					// Return child elements to the list.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   694
					children = transport.children().insertAfter(ui.item);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   695
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   696
					// Add "sub menu" description.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   697
					subMenuTitle = ui.item.find( '.item-title .is-submenu' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   698
					if ( 0 < currentDepth )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   699
						subMenuTitle.show();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   700
					else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   701
						subMenuTitle.hide();
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
					// Update depth classes.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   704
					if ( 0 !== depthChange ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   705
						ui.item.updateDepthClass( currentDepth );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   706
						children.shiftDepthClass( depthChange );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   707
						updateMenuMaxDepth( depthChange );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   708
					}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   709
					// Register a change.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   710
					api.registerChange();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   711
					// Update the item data.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   712
					ui.item.updateParentMenuItemDBId();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   713
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   714
					// Address sortable's incorrectly-calculated top in Opera.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   715
					ui.item[0].style.top = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   716
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   717
					// Handle drop placement for rtl orientation.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   718
					if ( api.isRTL ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   719
						ui.item[0].style.left = 'auto';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   720
						ui.item[0].style.right = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   721
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   722
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   723
					api.refreshKeyboardAccessibility();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   724
					api.refreshAdvancedAccessibility();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   725
				},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   726
				change: function(e, ui) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   727
					// Make sure the placeholder is inside the menu.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   728
					// Otherwise fix it, or we're in trouble.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   729
					if( ! ui.placeholder.parent().hasClass('menu') )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   730
						(prev.length) ? prev.after( ui.placeholder ) : api.menuList.prepend( ui.placeholder );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   731
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   732
					updateSharedVars(ui);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   733
				},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   734
				sort: function(e, ui) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   735
					var offset = ui.helper.offset(),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   736
						edge = api.isRTL ? offset.left + ui.helper.width() : offset.left,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   737
						depth = api.negateIfRTL * api.pxToDepth( edge - menuEdge );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   738
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   739
					/*
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   740
					 * Check and correct if depth is not within range.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   741
					 * Also, if the dragged element is dragged upwards over an item,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   742
					 * shift the placeholder to a child position.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   743
					 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   744
					if ( depth > maxDepth || offset.top < ( prevBottom - api.options.targetTolerance ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   745
						depth = maxDepth;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   746
					} else if ( depth < minDepth ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   747
						depth = minDepth;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   748
					}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   749
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   750
					if( depth != currentDepth )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   751
						updateCurrentDepth(ui, depth);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   752
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   753
					// If we overlap the next element, manually shift downwards.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   754
					if( nextThreshold && offset.top + helperHeight > nextThreshold ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   755
						next.after( ui.placeholder );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   756
						updateSharedVars( ui );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   757
						$( this ).sortable( 'refreshPositions' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   758
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   759
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   760
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   761
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   762
			function updateSharedVars(ui) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   763
				var depth;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   764
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   765
				prev = ui.placeholder.prev( '.menu-item' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   766
				next = ui.placeholder.next( '.menu-item' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   767
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   768
				// 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
   769
				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
   770
				if( next[0] == ui.item[0] ) next = next.next( '.menu-item' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   771
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   772
				prevBottom = (prev.length) ? prev.offset().top + prev.height() : 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   773
				nextThreshold = (next.length) ? next.offset().top + next.height() / 3 : 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   774
				minDepth = (next.length) ? next.menuItemDepth() : 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   775
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   776
				if( prev.length )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   777
					maxDepth = ( (depth = prev.menuItemDepth() + 1) > api.options.globalMaxDepth ) ? api.options.globalMaxDepth : depth;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   778
				else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   779
					maxDepth = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   780
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   781
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   782
			function updateCurrentDepth(ui, depth) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   783
				ui.placeholder.updateDepthClass( depth, currentDepth );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   784
				currentDepth = depth;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   785
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   786
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   787
			function initialMenuMaxDepth() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   788
				if( ! body[0].className ) return 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   789
				var match = body[0].className.match(/menu-max-depth-(\d+)/);
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   790
				return match && match[1] ? parseInt( match[1], 10 ) : 0;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   791
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   792
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   793
			function updateMenuMaxDepth( depthChange ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   794
				var depth, newDepth = menuMaxDepth;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   795
				if ( depthChange === 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   796
					return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   797
				} else if ( depthChange > 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   798
					depth = maxChildDepth + depthChange;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   799
					if( depth > menuMaxDepth )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   800
						newDepth = depth;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   801
				} else if ( depthChange < 0 && maxChildDepth == menuMaxDepth ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   802
					while( ! $('.menu-item-depth-' + newDepth, api.menuList).length && newDepth > 0 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   803
						newDepth--;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   804
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   805
				// Update the depth class.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   806
				body.removeClass( 'menu-max-depth-' + menuMaxDepth ).addClass( 'menu-max-depth-' + newDepth );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   807
				menuMaxDepth = newDepth;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   808
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   809
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   810
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   811
		initManageLocations : function () {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   812
			$('#menu-locations-wrap form').submit(function(){
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   813
				window.onbeforeunload = null;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   814
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   815
			$('.menu-location-menus select').on('change', function () {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   816
				var editLink = $(this).closest('tr').find('.locations-edit-menu-link');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   817
				if ($(this).find('option:selected').data('orig'))
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   818
					editLink.show();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   819
				else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   820
					editLink.hide();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   821
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   822
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   823
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   824
		attachMenuEditListeners : function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   825
			var that = this;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   826
			$('#update-nav-menu').bind('click', function(e) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   827
				if ( e.target && e.target.className ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   828
					if ( -1 != e.target.className.indexOf('item-edit') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   829
						return that.eventOnClickEditLink(e.target);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   830
					} else if ( -1 != e.target.className.indexOf('menu-save') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   831
						return that.eventOnClickMenuSave(e.target);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   832
					} else if ( -1 != e.target.className.indexOf('menu-delete') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   833
						return that.eventOnClickMenuDelete(e.target);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   834
					} else if ( -1 != e.target.className.indexOf('item-delete') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   835
						return that.eventOnClickMenuItemDelete(e.target);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   836
					} else if ( -1 != e.target.className.indexOf('item-cancel') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   837
						return that.eventOnClickCancelLink(e.target);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   838
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   839
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   840
			});
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   841
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   842
			$( '#menu-name' ).on( 'input', _.debounce( function () {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   843
				var menuName = $( document.getElementById( 'menu-name' ) ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   844
					menuNameVal = menuName.val();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   845
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   846
				if ( ! menuNameVal || ! menuNameVal.replace( /\s+/, '' ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   847
					// Add warning for invalid menu name.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   848
					menuName.parent().addClass( 'form-invalid' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   849
				} else {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   850
					// Remove warning for valid menu name.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   851
					menuName.parent().removeClass( 'form-invalid' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   852
				}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   853
			}, 500 ) );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   854
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   855
			$('#add-custom-links input[type="text"]').keypress(function(e){
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   856
				$('#customlinkdiv').removeClass('form-invalid');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   857
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   858
				if ( e.keyCode === 13 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   859
					e.preventDefault();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   860
					$( '#submit-customlinkdiv' ).click();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   861
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   862
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   863
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   864
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   865
		attachMenuSaveSubmitListeners : function() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   866
			/*
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   867
			 * 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
   868
			 * 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
   869
			 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   870
			$( '#update-nav-menu' ).submit( function() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   871
				var navMenuData = $( '#update-nav-menu' ).serializeArray();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   872
				$( '[name="nav-menu-data"]' ).val( JSON.stringify( navMenuData ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   873
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   874
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   875
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   876
		attachThemeLocationsListeners : function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   877
			var loc = $('#nav-menu-theme-locations'), params = {};
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   878
			params.action = 'menu-locations-save';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   879
			params['menu-settings-column-nonce'] = $('#menu-settings-column-nonce').val();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   880
			loc.find('input[type="submit"]').click(function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   881
				loc.find('select').each(function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   882
					params[this.name] = $(this).val();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   883
				});
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   884
				loc.find( '.spinner' ).addClass( 'is-active' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   885
				$.post( ajaxurl, params, function() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   886
					loc.find( '.spinner' ).removeClass( 'is-active' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   887
				});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   888
				return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   889
			});
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
		attachQuickSearchListeners : function() {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   893
			var searchTimer;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   894
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   895
			// Prevent form submission.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   896
			$( '#nav-menu-meta' ).on( 'submit', function( event ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   897
				event.preventDefault();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   898
			});
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   899
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   900
			$( '#nav-menu-meta' ).on( 'input', '.quick-search', function() {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   901
				var $this = $( this );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   902
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   903
				$this.attr( 'autocomplete', 'off' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   904
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   905
				if ( searchTimer ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   906
					clearTimeout( searchTimer );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   907
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   908
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   909
				searchTimer = setTimeout( function() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   910
					api.updateQuickSearchResults( $this );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   911
 				}, 500 );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   912
			}).on( 'blur', '.quick-search', function() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   913
				api.lastSearch = '';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   914
			});
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   915
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   916
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   917
		updateQuickSearchResults : function(input) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   918
			var panel, params,
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   919
				minSearchLength = 2,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   920
				q = input.val();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   921
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   922
			/*
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   923
			 * 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
   924
			 * 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
   925
			 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   926
			if ( q.length < minSearchLength || api.lastSearch == q ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   927
				return;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   928
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   929
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   930
			api.lastSearch = q;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   931
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   932
			panel = input.parents('.tabs-panel');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   933
			params = {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   934
				'action': 'menu-quick-search',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   935
				'response-format': 'markup',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   936
				'menu': $('#menu').val(),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   937
				'menu-settings-column-nonce': $('#menu-settings-column-nonce').val(),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   938
				'q': q,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   939
				'type': input.attr('name')
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   940
			};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   941
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   942
			$( '.spinner', panel ).addClass( 'is-active' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   943
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   944
			$.post( ajaxurl, params, function(menuMarkup) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   945
				api.processQuickSearchQueryResponse(menuMarkup, params, panel);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   946
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   947
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   948
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   949
		addCustomLink : function( processMethod ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   950
			var url = $('#custom-menu-item-url').val().trim(),
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   951
				label = $('#custom-menu-item-name').val();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   952
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   953
			processMethod = processMethod || api.addMenuItemToBottom;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   954
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   955
			if ( '' === url || 'https://' == url || 'http://' == url ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   956
				$('#customlinkdiv').addClass('form-invalid');
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   957
				return false;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   958
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   959
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   960
			// Show the Ajax spinner.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   961
			$( '.customlinkdiv .spinner' ).addClass( 'is-active' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   962
			this.addLinkToMenu( url, label, processMethod, function() {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   963
				// Remove the Ajax spinner.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   964
				$( '.customlinkdiv .spinner' ).removeClass( 'is-active' );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   965
				// Set custom link form back to defaults.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   966
				$('#custom-menu-item-name').val('').blur();
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   967
				$( '#custom-menu-item-url' ).val( '' ).attr( 'placeholder', 'https://' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   968
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   969
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   970
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   971
		addLinkToMenu : function(url, label, processMethod, callback) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   972
			processMethod = processMethod || api.addMenuItemToBottom;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   973
			callback = callback || function(){};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   974
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   975
			api.addItemToMenu({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   976
				'-1': {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   977
					'menu-item-type': 'custom',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   978
					'menu-item-url': url,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   979
					'menu-item-title': label
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   980
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   981
			}, processMethod, callback);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   982
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   983
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   984
		addItemToMenu : function(menuItem, processMethod, callback) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   985
			var menu = $('#menu').val(),
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   986
				nonce = $('#menu-settings-column-nonce').val(),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   987
				params;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   988
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   989
			processMethod = processMethod || function(){};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   990
			callback = callback || function(){};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   991
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   992
			params = {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   993
				'action': 'add-menu-item',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   994
				'menu': menu,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   995
				'menu-settings-column-nonce': nonce,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   996
				'menu-item': menuItem
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   997
			};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   998
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   999
			$.post( ajaxurl, params, function(menuMarkup) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1000
				var ins = $('#menu-instructions');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1001
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1002
				menuMarkup = $.trim( menuMarkup ); // Trim leading whitespaces.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1003
				processMethod(menuMarkup, params);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1004
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1005
				// Make it stand out a bit more visually, by adding a fadeIn.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1006
				$( 'li.pending' ).hide().fadeIn('slow');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1007
				$( '.drag-instructions' ).show();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1008
				if( ! ins.hasClass( 'menu-instructions-inactive' ) && ins.siblings().length )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1009
					ins.addClass( 'menu-instructions-inactive' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1010
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1011
				callback();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1012
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1013
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1014
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1015
		/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1016
		 * 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
  1017
		 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1018
		 * @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
  1019
		 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1020
		 * @fires document#menu-item-added Passes menuMarkup as a jQuery object.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1021
		 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1022
		addMenuItemToBottom : function( menuMarkup ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1023
			var $menuMarkup = $( menuMarkup );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1024
			$menuMarkup.hideAdvancedMenuItemFields().appendTo( api.targetList );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1025
			api.refreshKeyboardAccessibility();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1026
			api.refreshAdvancedAccessibility();
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1027
			$( document ).trigger( 'menu-item-added', [ $menuMarkup ] );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1028
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1029
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1030
		/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1031
		 * 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
  1032
		 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1033
		 * @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
  1034
		 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1035
		 * @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
  1036
		 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1037
		addMenuItemToTop : function( menuMarkup ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1038
			var $menuMarkup = $( menuMarkup );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1039
			$menuMarkup.hideAdvancedMenuItemFields().prependTo( api.targetList );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1040
			api.refreshKeyboardAccessibility();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1041
			api.refreshAdvancedAccessibility();
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1042
			$( document ).trigger( 'menu-item-added', [ $menuMarkup ] );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1043
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1044
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1045
		attachUnsavedChangesListener : function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1046
			$('#menu-management input, #menu-management select, #menu-management, #menu-management textarea, .menu-location-menus select').change(function(){
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1047
				api.registerChange();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1048
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1049
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1050
			if ( 0 !== $('#menu-to-edit').length || 0 !== $('.menu-location-menus select').length ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1051
				window.onbeforeunload = function(){
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1052
					if ( api.menusChanged )
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1053
						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
  1054
				};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1055
			} else {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1056
				// Make the post boxes read-only, as they can't be used yet.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1057
				$( '#menu-settings-column' ).find( 'input,select' ).end().find( 'a' ).attr( 'href', '#' ).unbind( 'click' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1058
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1059
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1060
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1061
		registerChange : function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1062
			api.menusChanged = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1063
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1064
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1065
		attachTabsPanelListeners : function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1066
			$('#menu-settings-column').bind('click', function(e) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1067
				var selectAreaMatch, selectAll, panelId, wrapper, items,
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1068
					target = $(e.target);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1069
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1070
				if ( target.hasClass('nav-tab-link') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1071
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1072
					panelId = target.data( 'type' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1073
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1074
					wrapper = target.parents('.accordion-section-content').first();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1075
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1076
					// Upon changing tabs, we want to uncheck all checkboxes.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1077
					$( 'input', wrapper ).prop( 'checked', false );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1078
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1079
					$('.tabs-panel-active', wrapper).removeClass('tabs-panel-active').addClass('tabs-panel-inactive');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1080
					$('#' + panelId, wrapper).removeClass('tabs-panel-inactive').addClass('tabs-panel-active');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1081
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1082
					$('.tabs', wrapper).removeClass('tabs');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1083
					target.parent().addClass('tabs');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1084
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1085
					// Select the search bar.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1086
					$('.quick-search', wrapper).focus();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1087
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1088
					// 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
  1089
					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
  1090
						wrapper.addClass( 'has-no-menu-item' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1091
					} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1092
						wrapper.removeClass( 'has-no-menu-item' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1093
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1094
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1095
					e.preventDefault();
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1096
				} else if ( target.hasClass( 'select-all' ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1097
					selectAreaMatch = target.closest( '.button-controls' ).data( 'items-type' );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1098
					if ( selectAreaMatch ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1099
						items = $( '#' + selectAreaMatch + ' .tabs-panel-active .menu-item-title input' );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1100
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1101
						if ( items.length === items.filter( ':checked' ).length && ! target.is( ':checked' ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1102
							items.prop( 'checked', false );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1103
						} else if ( target.is( ':checked' ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1104
							items.prop( 'checked', true );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1105
						}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1106
					}
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1107
				} else if ( target.hasClass( 'menu-item-checkbox' ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1108
					selectAreaMatch = target.closest( '.tabs-panel-active' ).parent().attr( 'id' );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1109
					if ( selectAreaMatch ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1110
						items     = $( '#' + selectAreaMatch + ' .tabs-panel-active .menu-item-title input' );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1111
						selectAll = $( '.button-controls[data-items-type="' + selectAreaMatch + '"] .select-all' );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1112
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1113
						if ( items.length === items.filter( ':checked' ).length && ! selectAll.is( ':checked' ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1114
							selectAll.prop( 'checked', true );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1115
						} else if ( selectAll.is( ':checked' ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1116
							selectAll.prop( 'checked', false );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1117
						}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1118
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1119
				} else if ( target.hasClass('submit-add-to-menu') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1120
					api.registerChange();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1121
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1122
					if ( e.target.id && 'submit-customlinkdiv' == e.target.id )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1123
						api.addCustomLink( api.addMenuItemToBottom );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1124
					else if ( e.target.id && -1 != e.target.id.indexOf('submit-') )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1125
						$('#' + e.target.id.replace(/submit-/, '')).addSelectedToMenu( api.addMenuItemToBottom );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1126
					return false;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1127
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1128
			});
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1129
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1130
			/*
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1131
			 * 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
  1132
			 * 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
  1133
			 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1134
			$( '#nav-menu-meta' ).on( 'click', 'a.page-numbers', function() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1135
				var $container = $( this ).closest( '.inside' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1136
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1137
				$.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
  1138
					function( resp ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1139
						var metaBoxData = $.parseJSON( resp ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1140
							toReplace;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1141
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1142
						if ( -1 === resp.indexOf( 'replace-id' ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1143
							return;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1144
						}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1145
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1146
						// Get the post type menu meta box to update.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1147
						toReplace = document.getElementById( metaBoxData['replace-id'] );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1148
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1149
						if ( ! metaBoxData.markup || ! toReplace ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1150
							return;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1151
						}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1152
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1153
						// 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
  1154
						$container.html( metaBoxData.markup );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1155
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1156
				);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1157
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1158
				return false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1159
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1160
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1161
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1162
		eventOnClickEditLink : function(clickedEl) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1163
			var settings, item,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1164
			matchedSection = /#(.*)$/.exec(clickedEl.href);
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1165
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1166
			if ( matchedSection && matchedSection[1] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1167
				settings = $('#'+matchedSection[1]);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1168
				item = settings.parent();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1169
				if( 0 !== item.length ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1170
					if( item.hasClass('menu-item-edit-inactive') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1171
						if( ! settings.data('menu-item-data') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1172
							settings.data( 'menu-item-data', settings.getItemData() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1173
						}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1174
						settings.slideDown('fast');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1175
						item.removeClass('menu-item-edit-inactive')
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1176
							.addClass('menu-item-edit-active');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1177
					} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1178
						settings.slideUp('fast');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1179
						item.removeClass('menu-item-edit-active')
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1180
							.addClass('menu-item-edit-inactive');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1181
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1182
					return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1183
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1184
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1185
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1186
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1187
		eventOnClickCancelLink : function(clickedEl) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1188
			var settings = $( clickedEl ).closest( '.menu-item-settings' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1189
				thisMenuItem = $( clickedEl ).closest( '.menu-item' );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1190
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1191
			thisMenuItem.removeClass( 'menu-item-edit-active' ).addClass( 'menu-item-edit-inactive' );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1192
			settings.setItemData( settings.data( 'menu-item-data' ) ).hide();
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1193
			// Restore the title of the currently active/expanded menu item.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1194
			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
  1195
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1196
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1197
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1198
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1199
		eventOnClickMenuSave : function() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1200
			var locs = '',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1201
			menuName = $('#menu-name'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1202
			menuNameVal = menuName.val();
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1203
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1204
			// Cancel and warn if invalid menu name.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1205
			if ( ! menuNameVal || ! menuNameVal.replace( /\s+/, '' ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1206
				menuName.parent().addClass( 'form-invalid' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1207
				return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1208
			}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1209
			// Copy menu theme locations.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1210
			$('#nav-menu-theme-locations select').each(function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1211
				locs += '<input type="hidden" name="' + this.name + '" value="' + $(this).val() + '" />';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1212
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1213
			$('#update-nav-menu').append( locs );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1214
			// Update menu item position data.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1215
			api.menuList.find('.menu-item-data-position').val( function(index) { return index + 1; } );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1216
			window.onbeforeunload = null;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1217
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1218
			return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1219
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1220
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1221
		eventOnClickMenuDelete : function() {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1222
			// Delete warning AYS.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1223
			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
  1224
				window.onbeforeunload = null;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1225
				return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1226
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1227
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1228
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1229
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1230
		eventOnClickMenuItemDelete : function(clickedEl) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1231
			var itemID = parseInt(clickedEl.id.replace('delete-', ''), 10);
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1232
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1233
			api.removeMenuItem( $('#menu-item-' + itemID) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1234
			api.registerChange();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1235
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1236
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1237
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1238
		/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1239
		 * Process the quick search response into a search result
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1240
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1241
		 * @param string resp The server response to the query.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1242
		 * @param object req The request arguments.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1243
		 * @param jQuery panel The tabs panel we're searching in.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1244
		 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1245
		processQuickSearchQueryResponse : function(resp, req, panel) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1246
			var matched, newID,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1247
			takenIDs = {},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1248
			form = document.getElementById('nav-menu-meta'),
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1249
			pattern = /menu-item[(\[^]\]*/,
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1250
			$items = $('<div>').html(resp).find('li'),
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1251
			wrapper = panel.closest( '.accordion-section-content' ),
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1252
			selectAll = wrapper.find( '.button-controls .select-all' ),
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1253
			$item;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1254
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1255
			if( ! $items.length ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1256
				$('.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
  1257
				$( '.spinner', panel ).removeClass( 'is-active' );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1258
				wrapper.addClass( 'has-no-menu-item' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1259
				return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1260
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1261
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1262
			$items.each(function(){
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1263
				$item = $(this);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1264
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1265
				// Make a unique DB ID number.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1266
				matched = pattern.exec($item.html());
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1267
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1268
				if ( matched && matched[1] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1269
					newID = matched[1];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1270
					while( form.elements['menu-item[' + newID + '][menu-item-type]'] || takenIDs[ newID ] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1271
						newID--;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1272
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1273
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1274
					takenIDs[newID] = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1275
					if ( newID != matched[1] ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1276
						$item.html( $item.html().replace(new RegExp(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1277
							'menu-item\\[' + matched[1] + '\\]', 'g'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1278
							'menu-item[' + newID + ']'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1279
						) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1280
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1281
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1282
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1283
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1284
			$('.categorychecklist', panel).html( $items );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1285
			$( '.spinner', panel ).removeClass( 'is-active' );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1286
			wrapper.removeClass( 'has-no-menu-item' );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1287
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1288
			if ( selectAll.is( ':checked' ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1289
				selectAll.prop( 'checked', false );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1290
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1291
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1292
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1293
		/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1294
		 * Remove a menu item.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1295
		 *
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
  1296
		 * @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
  1297
		 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1298
		 * @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
  1299
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1300
		removeMenuItem : function(el) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1301
			var children = el.childMenuItems();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1302
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1303
			$( document ).trigger( 'menu-removing-item', [ el ] );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1304
			el.addClass('deleting').animate({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1305
					opacity : 0,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1306
					height: 0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1307
				}, 350, function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1308
					var ins = $('#menu-instructions');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1309
					el.remove();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1310
					children.shiftDepthClass( -1 ).updateParentMenuItemDBId();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1311
					if ( 0 === $( '#menu-to-edit li' ).length ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1312
						$( '.drag-instructions' ).hide();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1313
						ins.removeClass( 'menu-instructions-inactive' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1314
					}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1315
					api.refreshAdvancedAccessibility();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1316
				});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1317
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1318
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1319
		depthToPx : function(depth) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1320
			return depth * api.options.menuItemDepthPerLevel;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1321
		},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1322
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1323
		pxToDepth : function(px) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1324
			return Math.floor(px / api.options.menuItemDepthPerLevel);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1325
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1326
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1327
	};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1328
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1329
	$(document).ready(function(){ wpNavMenu.init(); });
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1330
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1331
})(jQuery);