"),n=g._getInputs(t),(t=g._getInputsSignature(l)===g._getInputsSignature(n))&&!g.liveUpdateMode&&(g.liveUpdateMode=!0,g.container.removeClass("widget-form-disabled"),g.container.find('input[name="savewidget"]').hide()),t&&g.liveUpdateMode?(l.each(function(e){var t=h(this),e=h(n[e]),i=t.data("state"+r),e=g._getInputState(e);t.data("sanitized",e),_.isEqual(i,e)||!s.ignoreActiveElement&&t.is(document.activeElement)||g._setInputState(t,e)}),h(document).trigger("widget-synced",[a,e.data.form])):g.liveUpdateMode?(g.liveUpdateMode=!1,g.container.find('input[name="savewidget"]').show(),i=!0):(o.html(e.data.form),g.container.removeClass("widget-form-disabled"),h(document).trigger("widget-updated",[a])),(c=!i&&!_(g.setting()).isEqual(e.data.instance))?(g.isWidgetUpdating=!0,g.setting(e.data.instance),g.isWidgetUpdating=!1):g.container.removeClass("previewer-loading"),d&&d.call(g,null,{noChange:!c,ajaxFinished:!0})):(t=f.error,e.data&&e.data.message&&(t=e.data.message),d?d.call(g,t):o.prepend(''+t+"
"))}),i.fail(function(e,t){d&&d.call(g,t)}),i.always(function(){g.container.removeClass("widget-form-loading"),l.each(function(){h(this).removeData("state"+r)}),t(t()-1)})},expandControlSection:function(){p.Control.prototype.expand.call(this)},_toggleExpanded:p.Section.prototype._toggleExpanded,expand:p.Section.prototype.expand,expandForm:function(){this.expand()},collapse:p.Section.prototype.collapse,collapseForm:function(){this.collapse()},toggleForm:function(e){void 0===e&&(e=!this.expanded()),this.expanded(e)},onChangeExpanded:function(e,t){var i,n,s,d,a,o=this;o.embedWidgetControl(),e&&o.embedWidgetContent(),t.unchanged?e&&p.Control.prototype.expand.call(o,{completeCallback:t.completeCallback}):(i=this.container.find("div.widget:first"),n=i.find(".widget-inside:first"),e=function(){p.control.each(function(e){o.params.type===e.params.type&&o!==e&&e.collapse()}),s=function(){o.container.removeClass("expanding"),o.container.addClass("expanded"),i.addClass("open"),a.attr("aria-expanded","true"),o.container.trigger("expanded")},t.completeCallback&&(d=s,s=function(){d(),t.completeCallback()}),o.params.is_wide?n.fadeIn(t.duration,s):n.slideDown(t.duration,s),o.container.trigger("expand"),o.container.addClass("expanding")},"false"===(a=this.container.find(".widget-top button.widget-action")).attr("aria-expanded")?p.section.has(o.section())?p.section(o.section()).expand({completeCallback:e}):e():(s=function(){o.container.removeClass("collapsing"),o.container.removeClass("expanded"),i.removeClass("open"),a.attr("aria-expanded","false"),o.container.trigger("collapsed")},t.completeCallback&&(d=s,s=function(){d(),t.completeCallback()}),o.container.trigger("collapse"),o.container.addClass("collapsing"),o.params.is_wide?n.fadeOut(t.duration,s):n.slideUp(t.duration,function(){i.css({width:"",margin:""}),s()})))},getWidgetSidebarPosition:function(){var e=this.getSidebarWidgetsControl().setting(),e=_.indexOf(e,this.params.widget_id);if(-1!==e)return e},moveUp:function(){this._moveWidgetByOne(-1)},moveDown:function(){this._moveWidgetByOne(1)},_moveWidgetByOne:function(e){var t=this.getWidgetSidebarPosition(),i=this.getSidebarWidgetsControl().setting,n=Array.prototype.slice.call(i()),s=n[t+e];n[t+e]=this.params.widget_id,n[t]=s,i(n)},toggleWidgetMoveArea:function(e){var t=this,i=this.container.find(".move-widget-area");(e=void 0===e?!i.hasClass("active"):e)&&(i.find(".selected").removeClass("selected"),i.find("li").filter(function(){return h(this).data("id")===t.params.sidebar_id}).addClass("selected"),this.container.find(".move-widget-btn").prop("disabled",!0)),i.toggleClass("active",e)},highlightSectionAndControl:function(){var e=this.container.is(":hidden")?this.container.closest(".control-section"):this.container;h(".highlighted").removeClass("highlighted"),e.addClass("highlighted"),setTimeout(function(){e.removeClass("highlighted")},500)}}),p.Widgets.WidgetsPanel=p.Panel.extend({ready:function(){var d=this;p.Panel.prototype.ready.call(d),d.deferred.embedded.done(function(){var t,i,n,e=d.container.find(".panel-meta"),s=h("",{class:"no-widget-areas-rendered-notice",role:"alert"});e.append(s),i=function(){return _.filter(d.sections(),function(e){return"sidebar"===e.params.type&&e.active()}).length},n=function(){var e=i();return 0===e||e!==p.Widgets.data.registeredSidebars.length},(t=function(){var e,t=i();s.empty(),t!==(e=p.Widgets.data.registeredSidebars.length)&&((e=0!==t?f.someAreasShown[e-t]:f.noAreasShown)&&s.append(h("",{text:e})),s.append(h("",{text:f.navigatePreview})))})(),s.toggle(n()),p.previewer.deferred.active.done(function(){s.toggle(n())}),p.bind("pane-contents-reflowed",function(){var e="resolved"===p.previewer.deferred.active.state()?"fast":0;t(),n()?s.slideDown(e):s.slideUp(e)})})},isContextuallyActive:function(){return this.active()}}),p.Widgets.SidebarSection=p.Section.extend({ready:function(){var t;p.Section.prototype.ready.call(this),t=p.Widgets.registeredSidebars.get(this.params.sidebarId),this.active.bind(function(e){t.set("is_rendered",e)}),t.set("is_rendered",this.active())}}),p.Widgets.SidebarControl=p.Control.extend({ready:function(){this.$controlSection=this.container.closest(".control-section"),this.$sectionContent=this.container.closest(".accordion-section-content"),this._setupModel(),this._setupSortable(),this._setupAddition(),this._applyCardinalOrderClassNames()},_setupModel:function(){var s=this;this.setting.bind(function(i,e){var t,n,e=_(e).difference(i);i=_(i).filter(function(e){e=c(e);return!!p.Widgets.availableWidgets.findWhere({id_base:e.id_base})}),(t=_(i).map(function(e){return p.Widgets.getWidgetFormControlForWidget(e)||s.addWidget(e)})).sort(function(e,t){return _.indexOf(i,e.params.widget_id)-_.indexOf(i,t.params.widget_id)}),n=0,_(t).each(function(e){e.priority(n),e.section(s.section()),n+=1}),s.priority(n),s._applyCardinalOrderClassNames(),_(t).each(function(e){e.params.sidebar_id=s.params.sidebar_id}),_(e).each(function(n){setTimeout(function(){var e,t,i=!1;p.each(function(e){e.id!==s.setting.id&&0===e.id.indexOf("sidebars_widgets[")&&"sidebars_widgets[wp_inactive_widgets]"!==e.id&&(e=e(),-1!==_.indexOf(e,n))&&(i=!0)}),i||(t=(e=p.Widgets.getWidgetFormControlForWidget(n))&&h.contains(document,e.container[0])&&!h.contains(s.$sectionContent[0],e.container[0]),e&&!t&&(p.control.remove(e.id),e.container.remove()),p.Widgets.savedWidgetIds[n]&&((t=p.value("sidebars_widgets[wp_inactive_widgets]")().slice()).push(n),p.value("sidebars_widgets[wp_inactive_widgets]")(_(t).unique())),e=c(n).id_base,(t=p.Widgets.availableWidgets.findWhere({id_base:e}))&&!t.get("is_multi")&&t.set("is_disabled",!1))})})})},_setupSortable:function(){var t=this;this.isReordering=!1,this.$sectionContent.sortable({items:"> .customize-control-widget_form",handle:".widget-top",axis:"y",tolerance:"pointer",connectWith:".accordion-section-content:has(.customize-control-sidebar_widgets)",update:function(){var e=t.$sectionContent.sortable("toArray"),e=h.map(e,function(e){return h("#"+e).find(":input[name=widget-id]").val()});t.setting(e)}}),this.$controlSection.find(".accordion-section-title").droppable({accept:".customize-control-widget_form",over:function(){p.section(t.section.get()).expand({allowMultiple:!0,completeCallback:function(){p.section.each(function(e){e.container.find(".customize-control-sidebar_widgets").length&&e.container.find(".accordion-section-content:first").sortable("refreshPositions")})}})}}),this.container.find(".reorder-toggle").on("click",function(){t.toggleReordering(!t.isReordering)})},_setupAddition:function(){var t=this;this.container.find(".add-new-widget").on("click",function(){var e=h(this);t.$sectionContent.hasClass("reordering")||(h("body").hasClass("adding-widget")?(e.attr("aria-expanded","false"),p.Widgets.availableWidgetsPanel.close()):(e.attr("aria-expanded","true"),p.Widgets.availableWidgetsPanel.open(t)))})},_applyCardinalOrderClassNames:function(){var t=[];_.each(this.setting(),function(e){e=p.Widgets.getWidgetFormControlForWidget(e);e&&t.push(e)}),0===t.length||1===p.Widgets.registeredSidebars.length&&t.length<=1?this.container.find(".reorder-toggle").hide():(this.container.find(".reorder-toggle").show(),h(t).each(function(){h(this.container).removeClass("first-widget").removeClass("last-widget").find(".move-widget-down, .move-widget-up").prop("tabIndex",0)}),_.first(t).container.addClass("first-widget").find(".move-widget-up").prop("tabIndex",-1),_.last(t).container.addClass("last-widget").find(".move-widget-down").prop("tabIndex",-1))},toggleReordering:function(e){var t=this.$sectionContent.find(".add-new-widget"),i=this.container.find(".reorder-toggle"),n=this.$sectionContent.find(".widget-title");(e=Boolean(e))!==this.$sectionContent.hasClass("reordering")&&(this.isReordering=e,this.$sectionContent.toggleClass("reordering",e),e?(_(this.getWidgetFormControls()).each(function(e){e.collapse()}),t.attr({tabindex:"-1","aria-hidden":"true"}),i.attr("aria-label",f.reorderLabelOff),u.a11y.speak(f.reorderModeOn),n.attr("aria-hidden","true")):(t.removeAttr("tabindex aria-hidden"),i.attr("aria-label",f.reorderLabelOn),u.a11y.speak(f.reorderModeOff),n.attr("aria-hidden","false")))},getWidgetFormControls:function(){var t=[];return _(this.setting()).each(function(e){e=function(e){var t,e=c(e);t="widget_"+e.id_base,e.number&&(t+="["+e.number+"]");return t}(e),e=p.control(e);e&&t.push(e)}),t},addWidget:function(n){var e,t,i,s,d,a=this,o="widget_form",r=c(n),l=r.number,r=r.id_base,r=p.Widgets.availableWidgets.findWhere({id_base:r});return!(!r||l&&!r.get("is_multi"))&&(r.get("is_multi")&&!l&&(r.set("multi_number",r.get("multi_number")+1),l=r.get("multi_number")),e=h("#widget-tpl-"+r.get("id")).html().trim(),r.get("is_multi")?e=e.replace(/<[^<>]+>/g,function(e){return e.replace(/__i__|%i%/g,l)}):r.set("is_disabled",!0),e=h(e),(e=h("").addClass("customize-control").addClass("customize-control-"+o).append(e)).find("> .widget-icon").remove(),r.get("is_multi")&&(e.find('input[name="widget_number"]').val(l),e.find('input[name="multi_number"]').val(l)),n=e.find('[name="widget-id"]').val(),e.hide(),t="widget_"+r.get("id_base"),r.get("is_multi")&&(t+="["+l+"]"),e.attr("id","customize-control-"+t.replace(/\]/g,"").replace(/\[/g,"-")),(i=p.has(t))||(d={transport:p.Widgets.data.selectiveRefreshableWidgets[r.get("id_base")]?"postMessage":"refresh",previewer:this.setting.previewer},p.create(t,t,"",d).set({})),d=p.controlConstructor[o],s=new d(t,{settings:{default:t},content:e,sidebar_id:a.params.sidebar_id,widget_id:n,widget_id_base:r.get("id_base"),type:o,is_new:!i,width:r.get("width"),height:r.get("height"),is_wide:r.get("is_wide")}),p.control.add(s),p.each(function(e){var t,i;e.id!==a.setting.id&&0===e.id.indexOf("sidebars_widgets[")&&(t=e().slice(),-1!==(i=_.indexOf(t,n)))&&(t.splice(i),e(t))}),d=this.setting().slice(),-1===_.indexOf(d,n)&&(d.push(n),this.setting(d)),e.slideDown(function(){i&&s.updateWidget({instance:s.setting()})}),s)}}),h.extend(p.panelConstructor,{widgets:p.Widgets.WidgetsPanel}),h.extend(p.sectionConstructor,{sidebar:p.Widgets.SidebarSection}),h.extend(p.controlConstructor,{widget_form:p.Widgets.WidgetControl,sidebar_widgets:p.Widgets.SidebarControl}),p.bind("ready",function(){p.Widgets.availableWidgetsPanel=new p.Widgets.AvailableWidgetsPanelView({collection:p.Widgets.availableWidgets}),p.previewer.bind("highlight-widget-control",p.Widgets.highlightWidgetFormControl),p.previewer.bind("focus-widget-control",p.Widgets.focusWidgetFormControl)}),p.Widgets.highlightWidgetFormControl=function(e){e=p.Widgets.getWidgetFormControlForWidget(e);e&&e.highlightSectionAndControl()},p.Widgets.focusWidgetFormControl=function(e){e=p.Widgets.getWidgetFormControlForWidget(e);e&&e.focus()},p.Widgets.getSidebarWidgetControlContainingWidget=function(t){var i=null;return p.control.each(function(e){"sidebar_widgets"===e.params.type&&-1!==_.indexOf(e.setting(),t)&&(i=e)}),i},p.Widgets.getWidgetFormControlForWidget=function(t){var i=null;return p.control.each(function(e){"widget_form"===e.params.type&&e.params.widget_id===t&&(i=e)}),i},h(document).on("widget-added",function(e,t){var s,d,i,n=c(t.find("> .widget-inside > .form > .widget-id").val());"nav_menu"===n.id_base&&(s=p.control("widget_nav_menu["+String(n.number)+"]"))&&(d=t.find('select[name*="nav_menu"]'),i=t.find(".edit-selected-nav-menu > button"),0!==d.length)&&0!==i.length&&(d.on("change",function(){p.section.has("nav_menu["+d.val()+"]")?i.parent().show():i.parent().hide()}),i.on("click",function(){var i,n,e=p.section("nav_menu["+d.val()+"]");e&&(n=s,(i=e).focus(),i.expanded.bind(function e(t){t||(i.expanded.unbind(e),n.focus())}))}))}))}(window.wp,jQuery);