WordPress/wp-includes/js/customize-preview-nav-menus...

1 line
4.6 KiB
JavaScript
Raw Normal View History

wp.customize.navMenusPreview=wp.customize.MenusCustomizerPreview=function(a,s,o){"use strict";var t={data:{navMenuInstanceArgs:{}}};return"undefined"!=typeof _wpCustomizePreviewNavMenusExports&&s.extend(t.data,_wpCustomizePreviewNavMenusExports),t.init=function(){var n=this;o.selectiveRefresh&&(o.each(function(e){n.bindSettingListener(e)}),o.bind("add",function(e){n.bindSettingListener(e,{fire:!0})}),o.bind("remove",function(e){n.unbindSettingListener(e)}),o.selectiveRefresh.bind("render-partials-response",function(e){e.nav_menu_instance_args&&s.extend(n.data.navMenuInstanceArgs,e.nav_menu_instance_args)})),o.preview.bind("active",function(){n.highlightControls()})},o.selectiveRefresh&&(t.NavMenuInstancePartial=o.selectiveRefresh.Partial.extend({initialize:function(e,n){var t=this,a=e.match(/^nav_menu_instance\[([0-9a-f]{32})]$/);if(!a)throw new Error("Illegal id for nav_menu_instance partial. The key corresponds with the args HMAC.");if(a=a[1],(n=n||{}).params=s.extend({selector:'[data-customize-partial-id="'+e+'"]',navMenuArgs:n.constructingContainerContext||{},containerInclusive:!0},n.params||{}),o.selectiveRefresh.Partial.prototype.initialize.call(t,e,n),!s.isObject(t.params.navMenuArgs))throw new Error("Missing navMenuArgs");if(t.params.navMenuArgs.args_hmac!==a)throw new Error("args_hmac mismatch with id")},isRelatedSetting:function(e,n,t){var a,i,r=this;if(s.isString(e)&&(e=o(e)),i=/^nav_menu_item\[/.test(e.id),i&&s.isObject(n)&&s.isObject(t)&&(delete n.type_label,delete t.type_label,s.isEqual(t,n)))return!1;if(r.params.navMenuArgs.theme_location){if("nav_menu_locations["+r.params.navMenuArgs.theme_location+"]"===e.id)return!0;a=o("nav_menu_locations["+r.params.navMenuArgs.theme_location+"]")}return!!(r=!(r=r.params.navMenuArgs.menu)&&a?a():r)&&("nav_menu["+r+"]"===e.id||i&&(n&&n.nav_menu_term_id===r||t&&t.nav_menu_term_id===r))},refresh:function(){var e,n=this,t=a.Deferred();return s.isNumber(n.params.navMenuArgs.menu)?e=n.params.navMenuArgs.menu:n.params.navMenuArgs.theme_location&&o.has("nav_menu_locations["+n.params.navMenuArgs.theme_location+"]")&&(e=o("nav_menu_locations["+n.params.navMenuArgs.theme_location+"]").get()),e?o.selectiveRefresh.Partial.prototype.refresh.call(n):(n.fallback(),t.reject(),t.promise())},renderContent:function(e){var n=e.container;""===e.addedContent&&e.partial.fallback(),o.selectiveRefresh.Partial.prototype.renderContent.call(this,e)&&a(document).trigger("customize-preview-menu-refreshed",[{instanceNumber:null,wpNavArgs:e.context,wpNavMenuArgs:e.context,oldContainer:n,newContainer:e.container}])}}),o.selectiveRefresh.partialConstructor.nav_menu_instance=t.NavMenuInstancePartial,t.handleUnplacedNavMenuInstances=function(e){var n=s.filter(s.values(t.data.navMenuInstanceArgs),function(e){return!o.selectiveRefresh.partial.has("nav_menu_instance["+e.args_hmac+"]")});return!!s.findWhere(n,e)&&(o.selectiveRefresh.requestFullRefresh(),!0)},t.bindSettingListener=function(e,n){var t;return n=n||{},(t=e.id.match(/^nav_menu\[(-?\d+)]$/))?(e._navMenuId=parseInt(t[1],10),e.bind(this.onChangeNavMenuSetting),n.fire&&this.onChangeNavMenuSetting.call(e,e(),!1),!0):(t=e.id.match(/^nav_menu_item\[(-?\d+)]$/))?(e._navMenuItemId=parseInt(t[1],10),e.bind(this.onChangeNavMenuItemSetting),n.fire&&this.onChangeNavMenuItemSetting.call(e,e(),!1),!0):!!(t=e.id.match(/^nav_menu_locations\[(.+?)]/))&&(e._navMenuThemeLocation=t[1],e.bind(this.onChangeNavMenuLocationsSetting),n.fire&&this.onChangeNavMenuLocationsSetting.call(e,e(),!1),!0)},t.unbindSettingListener=function(e){e.unbind(this.onChangeNavMenuSetting),e.unbind(this.onChangeNavMenuItemSetting),e.unbind(this.onChangeNavMenuLocationsSetting)},t.onChangeNavMenuSetting=function(){var n=this;t.handleUnplacedNavMenuInstances({menu:n._navMenuId}),o.each(function(e){e._navMenuThemeLocation&&n._navMenuId===e()&&t.handleUnplacedNavMenuInstances({theme_location:e._navMenuThemeLocation})})},t.onChangeNavMenuItemSetting=function(e,n){n=o("nav_menu["+String((e||n).nav_menu_term_id)+"]");n&&t.onChangeNavMenuSetting.call(n)},t.onChangeNavMenuLocationsSetting=function(){