!function(o,c,h){"use strict";var m,n,d,e;h&&h.customize&&(m=h.customize,n={},e={renderQueryVar:null,renderNonceValue:null,renderNoncePostKey:null,previewCustomizeNonce:null,requestUri:"/",theme:{active:!(d={}),stylesheet:""},navMenuInstanceArgs:{}},m.MenusCustomizerPreview={init:function(){var i=this,r={};d=c.extend({},e),"undefined"!=typeof _wpCustomizePreviewNavMenusExports&&c.extend(d,_wpCustomizePreviewNavMenusExports),m.each(function(e,n){e.id=n,r[e.id]=!0,i.bindListener(e)}),m.preview.bind("setting",function(e){var n=(e=e.slice()).shift(),t=e.shift();(e=(e=m(n))||m.create(n,t)).id||(e.id=n),r[e.id]||(r[e.id]=!0,i.bindListener(e)&&e.callbacks.fireWith(e,[e(),null]))})},bindListener:function(e){var n,t=e.id.match(/^nav_menu\[(-?\d+)]$/);return t?(e.navMenuId=parseInt(t[1],10),e.bind(this.onChangeNavMenuSetting),!0):(t=e.id.match(/^nav_menu_item\[(-?\d+)]$/))?(e.navMenuItemId=parseInt(t[1],10),e.bind(this.onChangeNavMenuItemSetting),!0):!!(t=e.id.match(/^nav_menu_locations\[(.+?)]/))&&(n=t[1],e.bind(c.bind(function(){this.refreshMenuLocation(n)},this)),!0)},onChangeNavMenuSetting:function(){if(!this.navMenuId)throw new Error("Expected navMenuId property to be set.");m.MenusCustomizerPreview.refreshMenu(this.navMenuId)},onChangeNavMenuItemSetting:function(e,n){!n||!n.nav_menu_term_id||e&&n.nav_menu_term_id===e.nav_menu_term_id||m.MenusCustomizerPreview.refreshMenu(n.nav_menu_term_id),e&&e.nav_menu_term_id&&m.MenusCustomizerPreview.refreshMenu(e.nav_menu_term_id)},refreshMenu:function(t){var i=[];m.each(function(e,n){n=n.match(/^nav_menu_locations\[(.+?)]/);n&&t===e()&&i.push(n[1])}),c.each(d.navMenuInstanceArgs,function(e,n){t!==e.menu&&-1===c.indexOf(i,e.theme_location)||this.refreshMenuInstanceDebounced(n)},this)},refreshMenuLocation:function(t){var i=!1;c.each(d.navMenuInstanceArgs,function(e,n){t===e.theme_location&&(this.refreshMenuInstanceDebounced(n),i=!0)},this),i||m.preview.send("refresh")},refreshMenuInstance:function(t){var e,i,r,a,s,n,u;if(!d.navMenuInstanceArgs[t])throw new Error("unknown_instance_number");n=d.navMenuInstanceArgs[t],u="partial-refreshable-nav-menu-"+String(t),a=o("."+u),c.isNumber(n.menu)?i=n.menu:n.theme_location&&m.has("nav_menu_locations["+n.theme_location+"]")&&(i=m("nav_menu_locations["+n.theme_location+"]").get()),i&&n.can_partial_refresh&&0!==a.length?(i=parseInt(i,10),e={nonce:d.previewCustomizeNonce,wp_customize:"on"},d.theme.active||(e.theme=d.theme.stylesheet),e[d.renderQueryVar]="1",r={},m.each(function(e,n){e=e.get();(/^nav_menu_locations\[/.test(n)||n==="nav_menu["+String(i)+"]"||/^nav_menu_item\[/.test(n)&&(!1===e||i===e.nav_menu_term_id))&&(r[n]=e)}),e.customized=JSON.stringify(r),e[d.renderNoncePostKey]=d.renderNonceValue,s=o.extend({},n),e.wp_nav_menu_args_hash=s.args_hash,delete s.args_hash,e.wp_nav_menu_args=JSON.stringify(s),a.addClass("customize-partial-refreshing"),h.ajax.send(null,{data:e,url:d.requestUri}).done(function(e){var n;!1!==e?(n=a,(a=o(e)).addClass(u),a.addClass("partial-refreshable-nav-menu customize-partial-refreshing"),n.replaceWith(a),n={instanceNumber:t,wpNavArgs:s,wpNavMenuArgs:s,oldContainer:n,newContainer:a},a.removeClass("customize-partial-refreshing"),o(document).trigger("customize-preview-menu-refreshed",[n])):m.preview.send("refresh")})):m.preview.send("refresh")},refreshMenuInstanceDebounced:function(e){n[e]&&clearTimeout(n[e]),n[e]=setTimeout(c.bind(function(){this.refreshMenuInstance(e)},this),200)}},m.bind("preview-ready",function(){m.preview.bind("active",function(){m.MenusCustomizerPreview.init()})}))}(jQuery,_,wp);