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