~canonical-sysadmins/wordpress/4.7.5

« back to all changes in this revision

Viewing changes to wp-includes/js/customize-preview-nav-menus.js

  • Committer: Haw Loeung
  • Date: 2016-12-13 06:56:21 UTC
  • mfrom: (1.1.20 upstream)
  • Revision ID: haw.loeung@canonical.com-20161213065621-8tcu7u7vlxgs2s81
Merge WP4.7 from upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
         * Initialize nav menus preview.
16
16
         */
17
17
        self.init = function() {
18
 
                var self = this;
 
18
                var self = this, synced = false;
 
19
 
 
20
                /*
 
21
                 * Keep track of whether we synced to determine whether or not bindSettingListener
 
22
                 * should also initially fire the listener. This initial firing needs to wait until
 
23
                 * after all of the settings have been synced from the pane in order to prevent
 
24
                 * an infinite selective fallback-refresh. Note that this sync handler will be
 
25
                 * added after the sync handler in customize-preview.js, so it will be triggered
 
26
                 * after all of the settings are added.
 
27
                 */
 
28
                api.preview.bind( 'sync', function() {
 
29
                        synced = true;
 
30
                } );
19
31
 
20
32
                if ( api.selectiveRefresh ) {
21
33
                        // Listen for changes to settings related to nav menus.
23
35
                                self.bindSettingListener( setting );
24
36
                        } );
25
37
                        api.bind( 'add', function( setting ) {
26
 
                                self.bindSettingListener( setting, { fire: true } );
 
38
 
 
39
                                /*
 
40
                                 * Handle case where an invalid nav menu item (one for which its associated object has been deleted)
 
41
                                 * is synced from the controls into the preview. Since invalid nav menu items are filtered out from
 
42
                                 * being exported to the frontend by the _is_valid_nav_menu_item filter in wp_get_nav_menu_items(),
 
43
                                 * the customizer controls will have a nav_menu_item setting where the preview will have none, and
 
44
                                 * this can trigger an infinite fallback refresh when the nav menu item lacks any valid items.
 
45
                                 */
 
46
                                if ( setting.get() && ! setting.get()._invalid ) {
 
47
                                        self.bindSettingListener( setting, { fire: synced } );
 
48
                                }
27
49
                        } );
28
50
                        api.bind( 'remove', function( setting ) {
29
51
                                self.unbindSettingListener( setting );
106
128
                         * @returns {boolean}
107
129
                         */
108
130
                        isRelatedSetting: function( setting, newValue, oldValue ) {
109
 
                                var partial = this, navMenuLocationSetting, navMenuId, isNavMenuItemSetting;
 
131
                                var partial = this, navMenuLocationSetting, navMenuId, isNavMenuItemSetting, _newValue, _oldValue, urlParser;
110
132
                                if ( _.isString( setting ) ) {
111
133
                                        setting = api( setting );
112
134
                                }
123
145
                                 */
124
146
                                isNavMenuItemSetting = /^nav_menu_item\[/.test( setting.id );
125
147
                                if ( isNavMenuItemSetting && _.isObject( newValue ) && _.isObject( oldValue ) ) {
126
 
                                        delete newValue.type_label;
127
 
                                        delete oldValue.type_label;
128
 
                                        if ( _.isEqual( oldValue, newValue ) ) {
 
148
                                        _newValue = _.clone( newValue );
 
149
                                        _oldValue = _.clone( oldValue );
 
150
                                        delete _newValue.type_label;
 
151
                                        delete _oldValue.type_label;
 
152
 
 
153
                                        // Normalize URL scheme when parent frame is HTTPS to prevent selective refresh upon initial page load.
 
154
                                        if ( 'https' === api.preview.scheme.get() ) {
 
155
                                                urlParser = document.createElement( 'a' );
 
156
                                                urlParser.href = _newValue.url;
 
157
                                                urlParser.protocol = 'https:';
 
158
                                                _newValue.url = urlParser.href;
 
159
                                                urlParser.href = _oldValue.url;
 
160
                                                urlParser.protocol = 'https:';
 
161
                                                _oldValue.url = urlParser.href;
 
162
                                        }
 
163
 
 
164
                                        // Prevent original_title differences from causing refreshes if title is present.
 
165
                                        if ( newValue.title ) {
 
166
                                                delete _oldValue.original_title;
 
167
                                                delete _newValue.original_title;
 
168
                                        }
 
169
 
 
170
                                        if ( _.isEqual( _oldValue, _newValue ) ) {
129
171
                                                return false;
130
172
                                        }
131
173
                                }
365
407
        self.highlightControls = function() {
366
408
                var selector = '.menu-item';
367
409
 
 
410
                // Skip adding highlights if not in the customizer preview iframe.
 
411
                if ( ! api.settings.channel ) {
 
412
                        return;
 
413
                }
 
414
 
368
415
                // Focus on the menu item control when shift+clicking the menu item.
369
416
                $( document ).on( 'click', selector, function( e ) {
370
417
                        var navMenuItemParts;