~canonical-sysadmins/wordpress/4.6

« back to all changes in this revision

Viewing changes to wp-admin/js/customize-nav-menus.js

  • Committer: Manuel Seelaus
  • Date: 2015-12-09 17:47:18 UTC
  • mfrom: (1.1.11 upstream)
  • Revision ID: manuel.seelaus@canonical.com-20151209174718-coxethm2swbeqksy
Merge WP4.4 from upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
1012
1012
                                return;
1013
1013
                        }
1014
1014
                        section = api.section( sectionId );
1015
 
                        if ( section && section.expanded() ) {
 
1015
                        if ( ( section && section.expanded() ) || api.settings.autofocus.control === control.id ) {
1016
1016
                                control.actuallyEmbed();
1017
1017
                        }
1018
1018
                },
1132
1132
                                        }
1133
1133
                                });
1134
1134
                                if ( settingValue ) {
1135
 
                                        element.set( settingValue[ property ] );
 
1135
                                        if ( ( property === 'classes' || property === 'xfn' ) && _.isArray( settingValue[ property ] ) ) {
 
1136
                                                element.set( settingValue[ property ].join( ' ' ) );
 
1137
                                        } else {
 
1138
                                                element.set( settingValue[ property ] );
 
1139
                                        }
1136
1140
                                }
1137
1141
                        });
1138
1142
 
1246
1250
                                        return;
1247
1251
                                }
1248
1252
 
1249
 
                                var titleEl = control.container.find( '.menu-item-title' );
 
1253
                                var titleEl = control.container.find( '.menu-item-title' ),
 
1254
                                    titleText = item.title || api.Menus.data.l10n.untitled;
 
1255
 
 
1256
                                if ( item._invalid ) {
 
1257
                                        titleText = api.Menus.data.l10n.invalidTitleTpl.replace( '%s', titleText );
 
1258
                                }
1250
1259
 
1251
1260
                                // Don't update to an empty title.
1252
1261
                                if ( item.title ) {
1253
1262
                                        titleEl
1254
 
                                                .text( item.title )
 
1263
                                                .text( titleText )
1255
1264
                                                .removeClass( 'no-title' );
1256
1265
                                } else {
1257
1266
                                        titleEl
1258
 
                                                .text( api.Menus.data.l10n.untitled )
 
1267
                                                .text( titleText )
1259
1268
                                                .addClass( 'no-title' );
1260
1269
                                }
1261
1270
                        } );
1299
1308
                                'menu-item-edit-inactive'
1300
1309
                        ];
1301
1310
 
1302
 
                        if ( settingValue.invalid ) {
1303
 
                                containerClasses.push( 'invalid' );
1304
 
                                control.params.title = api.Menus.data.invalidTitleTpl.replace( '%s', control.params.title );
 
1311
                        if ( settingValue._invalid ) {
 
1312
                                containerClasses.push( 'menu-item-invalid' );
 
1313
                                control.params.title = api.Menus.data.l10n.invalidTitleTpl.replace( '%s', control.params.title );
1305
1314
                        } else if ( 'draft' === settingValue.status ) {
1306
1315
                                containerClasses.push( 'pending' );
1307
1316
                                control.params.title = api.Menus.data.pendingTitleTpl.replace( '%s', control.params.title );
1424
1433
                 * the first input in the control.
1425
1434
                 */
1426
1435
                focus: function() {
1427
 
                        this.expandControlSection();
1428
 
                        this.expandForm();
1429
 
                        this.container.find( '.menu-item-settings :focusable:first' ).focus();
 
1436
                        var control = this, focusable;
 
1437
                        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();
1430
1442
                },
1431
1443
 
1432
1444
                /**
1867
1879
 
1868
1880
                                        control.isSorting = false;
1869
1881
 
 
1882
                                        // Reset horizontal scroll position when done dragging.
 
1883
                                        control.$sectionContent.scrollLeft( 0 );
 
1884
 
1870
1885
                                        _.each( menuItemContainerIds, function( menuItemContainerId ) {
1871
1886
                                                var menuItemId, menuItemControl, matches;
1872
1887
                                                matches = menuItemContainerId.match( /^customize-control-nav_menu_item-(-?\d+)$/, '' );
2442
2457
         */
2443
2458
        api.Menus.applySavedData = function( data ) {
2444
2459
 
2445
 
                var insertedMenuIdMapping = {};
 
2460
                var insertedMenuIdMapping = {}, insertedMenuItemIdMapping = {};
2446
2461
 
2447
2462
                _( data.nav_menu_updates ).each(function( update ) {
2448
2463
                        var oldCustomizeId, newCustomizeId, customizeId, oldSetting, newSetting, setting, settingValue, oldSection, newSection, wasSaved, widgetTemplate, navMenuCount;
2573
2588
                        }
2574
2589
                } );
2575
2590
 
 
2591
                // Build up mapping of nav_menu_item placeholder IDs to inserted IDs.
 
2592
                _( data.nav_menu_item_updates ).each(function( update ) {
 
2593
                        if ( update.previous_post_id ) {
 
2594
                                insertedMenuItemIdMapping[ update.previous_post_id ] = update.post_id;
 
2595
                        }
 
2596
                });
 
2597
 
2576
2598
                _( data.nav_menu_item_updates ).each(function( update ) {
2577
2599
                        var oldCustomizeId, newCustomizeId, oldSetting, newSetting, settingValue, oldControl, newControl;
2578
2600
                        if ( 'inserted' === update.status ) {
2598
2620
                                }
2599
2621
                                settingValue = _.clone( settingValue );
2600
2622
 
 
2623
                                // If the parent menu item was also inserted, update the menu_item_parent to the new ID.
 
2624
                                if ( settingValue.menu_item_parent < 0 ) {
 
2625
                                        if ( ! insertedMenuItemIdMapping[ settingValue.menu_item_parent ] ) {
 
2626
                                                throw new Error( 'inserted ID for menu_item_parent not available' );
 
2627
                                        }
 
2628
                                        settingValue.menu_item_parent = insertedMenuItemIdMapping[ settingValue.menu_item_parent ];
 
2629
                                }
 
2630
 
2601
2631
                                // If the menu was also inserted, then make sure it uses the new menu ID for nav_menu_term_id.
2602
2632
                                if ( insertedMenuIdMapping[ settingValue.nav_menu_term_id ] ) {
2603
2633
                                        settingValue.nav_menu_term_id = insertedMenuIdMapping[ settingValue.nav_menu_term_id ];