23
menuItemTransport: 'postMessage',
22
settingTransport: 'refresh',
25
24
defaultSettingValues: {
28
locationSlugMappedToName: {}
30
30
if ( 'undefined' !== typeof _wpCustomizeNavMenusSettings ) {
31
31
$.extend( api.Menus.data, _wpCustomizeNavMenusSettings );
248
250
$section.addClass( 'loading' );
249
251
self.loading = true;
251
'customize-menus-nonce': api.Menus.data.nonce,
253
'customize-menus-nonce': api.settings.nonce['customize-menus'],
252
254
'wp_customize': 'on',
253
255
'search': self.searchTerm,
615
saveManageColumnsState: function() {
616
var hidden = this.hidden();
617
$.post( wp.ajax.settings.url, {
618
action: 'hidden-columns',
617
saveManageColumnsState: _.debounce( function() {
619
if ( panel._updateHiddenColumnsRequest ) {
620
panel._updateHiddenColumnsRequest.abort();
623
panel._updateHiddenColumnsRequest = wp.ajax.post( 'hidden-columns', {
624
hidden: panel.hidden(),
620
625
screenoptionnonce: $( '#screenoptionnonce' ).val(),
621
626
page: 'nav-menus'
628
panel._updateHiddenColumnsRequest.always( function() {
629
panel._updateHiddenColumnsRequest = null;
625
633
checked: function( column ) {
626
634
this.container.addClass( 'field-' + column + '-active' );
633
641
hidden: function() {
634
this.hidden = function() {
635
return $( '.hide-column-tog' ).not( ':checked' ).map( function() {
637
return id.substring( id, id.length - 5 );
638
}).get().join( ',' );
642
return $( '.hide-column-tog' ).not( ':checked' ).map( function() {
644
return id.substring( 0, id.length - 5 );
645
}).get().join( ',' );
807
813
* @param {array} themeLocations
809
updateAssignedLocationsInSectionTitle: function( themeLocations ) {
815
updateAssignedLocationsInSectionTitle: function( themeLocationSlugs ) {
810
816
var section = this,
813
819
$title = section.container.find( '.accordion-section-title:first' );
814
820
$title.find( '.menu-in-location' ).remove();
815
_.each( themeLocations, function( themeLocation ) {
816
var $label = $( '<span class="menu-in-location"></span>' );
817
$label.text( api.Menus.data.l10n.menuLocation.replace( '%s', themeLocation ) );
821
_.each( themeLocationSlugs, function( themeLocationSlug ) {
822
var $label, locationName;
823
$label = $( '<span class="menu-in-location"></span>' );
824
locationName = api.Menus.data.locationSlugMappedToName[ themeLocationSlug ];
825
$label.text( api.Menus.data.l10n.menuLocation.replace( '%s', locationName ) );
818
826
$title.append( $label );
821
section.container.toggleClass( 'assigned-to-menu-location', 0 !== themeLocations.length );
829
section.container.toggleClass( 'assigned-to-menu-location', 0 !== themeLocationSlugs.length );
1365
1373
* Expand the menu item form control.
1375
* @since 4.5.0 Added params.completeCallback.
1377
* @param {Object} [params] - Optional params.
1378
* @param {Function} [params.completeCallback] - Function to call when the form toggle has finished animating.
1367
expandForm: function() {
1368
this.toggleForm( true );
1380
expandForm: function( params ) {
1381
this.toggleForm( true, params );
1372
1385
* Collapse the menu item form control.
1387
* @since 4.5.0 Added params.completeCallback.
1389
* @param {Object} [params] - Optional params.
1390
* @param {Function} [params.completeCallback] - Function to call when the form toggle has finished animating.
1374
collapseForm: function() {
1375
this.toggleForm( false );
1392
collapseForm: function( params ) {
1393
this.toggleForm( false, params );
1379
1397
* Expand or collapse the menu item control.
1381
* @param {boolean|undefined} [showOrHide] If not supplied, will be inverse of current visibility
1399
* @since 4.5.0 Added params.completeCallback.
1401
* @param {boolean} [showOrHide] - If not supplied, will be inverse of current visibility
1402
* @param {Object} [params] - Optional params.
1403
* @param {Function} [params.completeCallback] - Function to call when the form toggle has finished animating.
1383
toggleForm: function( showOrHide ) {
1405
toggleForm: function( showOrHide, params ) {
1384
1406
var self = this, $menuitem, $inside, complete;
1386
1408
$menuitem = this.container;
1407
1432
.removeClass( 'menu-item-edit-inactive' )
1408
1433
.addClass( 'menu-item-edit-active' );
1409
1434
self.container.trigger( 'expanded' );
1436
if ( params && params.completeCallback ) {
1437
params.completeCallback();
1412
1441
$menuitem.find( '.item-edit' ).attr( 'aria-expanded', 'true' );
1419
1448
.addClass( 'menu-item-edit-inactive' )
1420
1449
.removeClass( 'menu-item-edit-active' );
1421
1450
self.container.trigger( 'collapsed' );
1452
if ( params && params.completeCallback ) {
1453
params.completeCallback();
1424
1457
self.container.trigger( 'collapse' );
1432
1465
* Expand the containing menu section, expand the form, and focus on
1433
1466
* the first input in the control.
1468
* @since 4.5.0 Added params.completeCallback.
1470
* @param {Object} [params] - Params object.
1471
* @param {Function} [params.completeCallback] - Optional callback function when focus has completed.
1436
var control = this, focusable;
1473
focus: function( params ) {
1474
params = params || {};
1475
var control = this, originalCompleteCallback = params.completeCallback;
1437
1477
control.expandControlSection();
1438
control.expandForm();
1439
// Note that we can't use :focusable due to a jQuery UI issue. See: https://github.com/jquery/jquery-ui/pull/1583
1440
focusable = control.container.find( '.menu-item-settings' ).find( 'input, select, textarea, button, object, a[href], [tabindex]' ).filter( ':visible' );
1441
focusable.first().focus();
1479
params.completeCallback = function() {
1482
// Note that we can't use :focusable due to a jQuery UI issue. See: https://github.com/jquery/jquery-ui/pull/1583
1483
focusable = control.container.find( '.menu-item-settings' ).find( 'input, select, textarea, button, object, a[href], [tabindex]' ).filter( ':visible' );
1484
focusable.first().focus();
1486
if ( originalCompleteCallback ) {
1487
originalCompleteCallback();
1491
control.expandForm( params );
2266
2316
customizeId = 'nav_menu_item[' + String( placeholderId ) + ']';
2267
2317
settingArgs = {
2268
2318
type: 'nav_menu_item',
2269
transport: 'postMessage',
2319
transport: api.Menus.data.settingTransport,
2270
2320
previewer: api.previewer
2272
2322
setting = api.create( customizeId, customizeId, {}, settingArgs );
2355
2405
// Register the menu control setting.
2356
2406
api.create( customizeId, customizeId, {}, {
2357
2407
type: 'nav_menu',
2358
transport: 'postMessage',
2408
transport: api.Menus.data.settingTransport,
2359
2409
previewer: api.previewer
2361
2411
api( customizeId ).set( $.extend(
2488
2537
newCustomizeId = 'nav_menu[' + String( update.term_id ) + ']';
2489
2538
newSetting = api.create( newCustomizeId, newCustomizeId, settingValue, {
2490
2539
type: 'nav_menu',
2491
transport: 'postMessage',
2540
transport: api.Menus.data.settingTransport,
2492
2541
previewer: api.previewer
2636
2685
newCustomizeId = 'nav_menu_item[' + String( update.post_id ) + ']';
2637
2686
newSetting = api.create( newCustomizeId, newCustomizeId, settingValue, {
2638
2687
type: 'nav_menu_item',
2639
transport: 'postMessage',
2688
transport: api.Menus.data.settingTransport,
2640
2689
previewer: api.previewer