var wpNavMenu;!function(k){var y;y=wpNavMenu={options:{menuItemDepthPerLevel:30,globalMaxDepth:11,sortableItems:"> *",targetTolerance:0},menuList:void 0,targetList:void 0,menusChanged:!1,isRTL:!("undefined"==typeof isRtl||!isRtl),negateIfRTL:"undefined"!=typeof isRtl&&isRtl?-1:1,lastSearch:"",init:function(){y.menuList=k("#menu-to-edit"),y.targetList=y.menuList,this.jQueryExtensions(),this.attachMenuEditListeners(),this.attachQuickSearchListeners(),this.attachThemeLocationsListeners(),this.attachMenuSaveSubmitListeners(),this.attachTabsPanelListeners(),this.attachUnsavedChangesListener(),y.menuList.length&&this.initSortables(),menus.oneThemeLocationNoMenus&&k("#posttype-page").addSelectedToMenu(y.addMenuItemToBottom),this.initManageLocations(),this.initAccessibility(),this.initToggles(),this.initPreviewing()},jQueryExtensions:function(){k.fn.extend({menuItemDepth:function(){var e=y.isRTL?this.eq(0).css("margin-right"):this.eq(0).css("margin-left");return y.pxToDepth(e&&-1!=e.indexOf("px")?e.slice(0,-2):0)},updateDepthClass:function(t,n){return this.each(function(){var e=k(this);n=n||e.menuItemDepth(),k(this).removeClass("menu-item-depth-"+n).addClass("menu-item-depth-"+t)})},shiftDepthClass:function(i){return this.each(function(){var e=k(this),t=e.menuItemDepth(),n=t+i;e.removeClass("menu-item-depth-"+t).addClass("menu-item-depth-"+n),0===n&&e.find(".is-submenu").hide()})},childMenuItems:function(){var i=k();return this.each(function(){for(var e=k(this),t=e.menuItemDepth(),n=e.next(".menu-item");n.length&&n.menuItemDepth()>t;)i=i.add(n),n=n.next(".menu-item")}),i},shiftHorizontally:function(i){return this.each(function(){var e=k(this),t=e.menuItemDepth(),n=t+i;e.moveHorizontally(n,t)})},moveHorizontally:function(a,s){return this.each(function(){var e=k(this),t=e.childMenuItems(),i=a-s,n=e.find(".is-submenu");e.updateDepthClass(a,s).updateParentMenuItemDBId(),t&&t.each(function(){var e=k(this),t=e.menuItemDepth(),n=t+i;e.updateDepthClass(n,t).updateParentMenuItemDBId()}),0===a?n.hide():n.show()})},updateParentMenuItemDBId:function(){return this.each(function(){var e=k(this),t=e.find(".menu-item-data-parent-id"),n=parseInt(e.menuItemDepth(),10),i=n-1,a=e.prevAll(".menu-item-depth-"+i).first();0===n?t.val(0):t.val(a.find(".menu-item-data-db-id").val())})},hideAdvancedMenuItemFields:function(){return this.each(function(){var e=k(this);k(".hide-column-tog").not(":checked").each(function(){e.find(".field-"+k(this).val()).addClass("hidden-field")})})},addSelectedToMenu:function(s){return 0!==k("#menu-to-edit").length&&this.each(function(){var e=k(this),i={},t=menus.oneThemeLocationNoMenus&&0===e.find(".tabs-panel-active .categorychecklist li input:checked").length?e.find('#page-all li input[type="checkbox"]'):e.find(".tabs-panel-active .categorychecklist li input:checked"),a=/menu-item\[([^\]]*)/;if(s=s||y.addMenuItemToBottom,!t.length)return!1;e.find(".button-controls .spinner").addClass("is-active"),k(t).each(function(){var e=k(this),t=a.exec(e.attr("name")),n=void 0===t[1]?0:parseInt(t[1],10);this.className&&-1!=this.className.indexOf("add-to-top")&&(s=y.addMenuItemToTop),i[n]=e.closest("li").getItemData("add-menu-item",n)}),y.addItemToMenu(i,s,function(){t.removeAttr("checked"),e.find(".button-controls .spinner").removeClass("is-active")})})},getItemData:function(t,n){t=t||"menu-item";var i,a={},s=["menu-item-db-id","menu-item-object-id","menu-item-object","menu-item-parent-id","menu-item-position","menu-item-type","menu-item-title","menu-item-url","menu-item-description","menu-item-attr-title","menu-item-target","menu-item-classes","menu-item-xfn"];return n||"menu-item"!=t||(n=this.find(".menu-item-data-db-id").val()),n&&this.find("input").each(function(){var e;for(i=s.length;i--;)"menu-item"==t?e=s[i]+"["+n+"]":"add-menu-item"==t&&(e="menu-item["+n+"]["+s[i]+"]"),this.name&&e==this.name&&(a[s[i]]=this.value)}),a},setItemData:function(e,a,s){return a=a||"menu-item",s||"menu-item"!=a||(s=k(".menu-item-data-db-id",this).val()),s&&this.find("input").each(function(){var n,i=k(this);k.each(e,function(e,t){"menu-item"==a?n=e+"["+s+"]":"add-menu-item"==a&&(n="menu-item["+s+"]["+e+"]"),n==i.attr("name")&&i.val(t)})}),this}})},countMenuItems:function(e){return k(".menu-item-depth-"+e).length},moveMenuItem:function(e,t){var n,i,a,s=k("#menu-to-edit li"),m=s.length,u=e.parents("li.menu-item"),r=u.childMenuItems(),o=u.getItemData(),c=parseInt(u.menuItemDepth(),10),d=parseInt(u.index(),10),l=u.next(),h=l.childMenuItems(),f=parseInt(l.menuItemDepth(),10)+1,p=u.prev(),v=parseInt(p.menuItemDepth(),10),g=p.getItemData()["menu-item-db-id"];switch(t){case"up":if(i=d-1,0===d)break;0===i&&0!==c&&u.moveHorizontally(0,c),0!==v&&u.moveHorizontally(v,c),r?(n=u.add(r)).detach().insertBefore(s.eq(i)).updateParentMenuItemDBId():u.detach().insertBefore(s.eq(i)).updateParentMenuItemDBId();break;case"down":if(r){if(n=u.add(r),(h=0!==(l=s.eq(n.length+d)).childMenuItems().length)&&(a=parseInt(l.menuItemDepth(),10)+1,u.moveHorizontally(a,c)),m===d+n.length)break;n.detach().insertAfter(s.eq(d+n.length)).updateParentMenuItemDBId()}else{if(0!==h.length&&u.moveHorizontally(f,c),m===d+1)break;u.detach().insertAfter(s.eq(d+1)).updateParentMenuItemDBId()}break;case"top":if(0===d)break;r?(n=u.add(r)).detach().insertBefore(s.eq(0)).updateParentMenuItemDBId():u.detach().insertBefore(s.eq(0)).updateParentMenuItemDBId();break;case"left":if(0===c)break;u.shiftHorizontally(-1);break;case"right":if(0===d)break;if(o["menu-item-parent-id"]===g)break;u.shiftHorizontally(1)}e.focus(),y.registerChange(),y.refreshKeyboardAccessibility(),y.refreshAdvancedAccessibility()},initAccessibility:function(){var e=k("#menu-to-edit");y.refreshKeyboardAccessibility(),y.refreshAdvancedAccessibility(),e.on("mouseenter.refreshAccessibility focus.refreshAccessibility touchstart.refreshAccessibility",".menu-item",function(){y.refreshAdvancedAccessibilityOfItem(k(this).find("a.item-edit"))}),e.on("click","a.item-edit",function(){y.refreshAdvancedAccessibilityOfItem(k(this))}),e.on("click",".menus-move",function(){var e=k(this).data("dir");void 0!==e&&y.moveMenuItem(k(this).parents("li.menu-item").find("a.item-edit"),e)})},refreshAdvancedAccessibilityOfItem:function(e){if(!0===k(e).data("needs_accessibility_refresh")){var t,n,i,a,s,m,u,r,o,c=k(e),d=c.closest("li.menu-item").first(),l=d.menuItemDepth(),h=0===l,f=c.closest(".menu-item-handle").find(".menu-item-title").text(),p=parseInt(d.index(),10),v=h?l:parseInt(l-1,10),g=d.prevAll(".menu-item-depth-"+v).first().find(".menu-item-title").text(),b=d.prevAll(".menu-item-depth-"+l).first().find(".menu-item-title").text(),I=k("#menu-to-edit li").length,y=d.nextAll(".menu-item-depth-"+l).length;d.find(".field-move").toggle(1y.options.globalMaxDepth?y.options.globalMaxDepth:t:0}function I(e,t){e.placeholder.updateDepthClass(t,f),f=t}0!==k("#menu-to-edit li").length&&k(".drag-instructions").show(),p+=y.isRTL?y.menuList.width():0,y.menuList.sortable({handle:".menu-item-handle",placeholder:"sortable-placeholder",items:y.options.sortableItems,start:function(e,t){var n,i,a,s;y.isRTL&&(t.item[0].style.right="auto"),l=t.item.children(".menu-item-transport"),I(t,m=t.item.menuItemDepth()),a=(t.item.next()[0]==t.placeholder[0]?t.item.next():t.item).childMenuItems(),l.append(a),n=l.outerHeight(),n+=0c&&(r.after(t.placeholder),b(t),k(this).sortable("refreshPositions"))}})},initManageLocations:function(){k("#menu-locations-wrap form").submit(function(){window.onbeforeunload=null}),k(".menu-location-menus select").on("change",function(){var e=k(this).closest("tr").find(".locations-edit-menu-link");k(this).find("option:selected").data("orig")?e.show():e.hide()})},attachMenuEditListeners:function(){var t=this;k("#update-nav-menu").bind("click",function(e){if(e.target&&e.target.className){if(-1!=e.target.className.indexOf("item-edit"))return t.eventOnClickEditLink(e.target);if(-1!=e.target.className.indexOf("menu-save"))return t.eventOnClickMenuSave(e.target);if(-1!=e.target.className.indexOf("menu-delete"))return t.eventOnClickMenuDelete(e.target);if(-1!=e.target.className.indexOf("item-delete"))return t.eventOnClickMenuItemDelete(e.target);if(-1!=e.target.className.indexOf("item-cancel"))return t.eventOnClickCancelLink(e.target)}}),k('#add-custom-links input[type="text"]').keypress(function(e){k("#customlinkdiv").removeClass("form-invalid"),13===e.keyCode&&(e.preventDefault(),k("#submit-customlinkdiv").click())})},attachMenuSaveSubmitListeners:function(){k("#update-nav-menu").submit(function(){var e=k("#update-nav-menu").serializeArray();k('[name="nav-menu-data"]').val(JSON.stringify(e))})},attachThemeLocationsListeners:function(){var e=k("#nav-menu-theme-locations"),t={action:"menu-locations-save"};t["menu-settings-column-nonce"]=k("#menu-settings-column-nonce").val(),e.find('input[type="submit"]').click(function(){return e.find("select").each(function(){t[this.name]=k(this).val()}),e.find(".spinner").addClass("is-active"),k.post(ajaxurl,t,function(){e.find(".spinner").removeClass("is-active")}),!1})},attachQuickSearchListeners:function(){var t,e;k("#nav-menu-meta").on("submit",function(e){e.preventDefault()}),e="oninput"in document.createElement("input")?"input":"keyup",k("#nav-menu-meta").on(e,".quick-search",function(){var e=k(this);e.attr("autocomplete","off"),t&&clearTimeout(t),t=setTimeout(function(){y.updateQuickSearchResults(e)},500)}).on("blur",".quick-search",function(){y.lastSearch=""})},updateQuickSearchResults:function(e){var t,n,i=e.val();i.length<2||y.lastSearch==i||(y.lastSearch=i,t=e.parents(".tabs-panel"),n={action:"menu-quick-search","response-format":"markup",menu:k("#menu").val(),"menu-settings-column-nonce":k("#menu-settings-column-nonce").val(),q:i,type:e.attr("name")},k(".spinner",t).addClass("is-active"),k.post(ajaxurl,n,function(e){y.processQuickSearchQueryResponse(e,n,t)}))},addCustomLink:function(e){var t=k("#custom-menu-item-url").val(),n=k("#custom-menu-item-name").val();if(e=e||y.addMenuItemToBottom,""===t||"http://"==t)return k("#customlinkdiv").addClass("form-invalid"),!1;k(".customlinkdiv .spinner").addClass("is-active"),this.addLinkToMenu(t,n,e,function(){k(".customlinkdiv .spinner").removeClass("is-active"),k("#custom-menu-item-name").val("").blur(),k("#custom-menu-item-url").val("http://")})},addLinkToMenu:function(e,t,n,i){n=n||y.addMenuItemToBottom,i=i||function(){},y.addItemToMenu({"-1":{"menu-item-type":"custom","menu-item-url":e,"menu-item-title":t}},n,i)},addItemToMenu:function(e,n,i){var a,t=k("#menu").val(),s=k("#menu-settings-column-nonce").val();n=n||function(){},i=i||function(){},a={action:"add-menu-item",menu:t,"menu-settings-column-nonce":s,"menu-item":e},k.post(ajaxurl,a,function(e){var t=k("#menu-instructions");e=k.trim(e),n(e,a),k("li.pending").hide().fadeIn("slow"),k(".drag-instructions").show(),!t.hasClass("menu-instructions-inactive")&&t.siblings().length&&t.addClass("menu-instructions-inactive"),i()})},addMenuItemToBottom:function(e){var t=k(e);t.hideAdvancedMenuItemFields().appendTo(y.targetList),y.refreshKeyboardAccessibility(),y.refreshAdvancedAccessibility(),k(document).trigger("menu-item-added",[t])},addMenuItemToTop:function(e){var t=k(e);t.hideAdvancedMenuItemFields().prependTo(y.targetList),y.refreshKeyboardAccessibility(),y.refreshAdvancedAccessibility(),k(document).trigger("menu-item-added",[t])},attachUnsavedChangesListener:function(){k("#menu-management input, #menu-management select, #menu-management, #menu-management textarea, .menu-location-menus select").change(function(){y.registerChange()}),0!==k("#menu-to-edit").length||0!==k(".menu-location-menus select").length?window.onbeforeunload=function(){if(y.menusChanged)return navMenuL10n.saveAlert}:k("#menu-settings-column").find("input,select").end().find("a").attr("href","#").unbind("click")},registerChange:function(){y.menusChanged=!0},attachTabsPanelListeners:function(){k("#menu-settings-column").bind("click",function(e){var t,n,i,a,s=k(e.target);if(s.hasClass("nav-tab-link"))n=s.data("type"),i=s.parents(".accordion-section-content").first(),k("input",i).removeAttr("checked"),k(".tabs-panel-active",i).removeClass("tabs-panel-active").addClass("tabs-panel-inactive"),k("#"+n,i).removeClass("tabs-panel-inactive").addClass("tabs-panel-active"),k(".tabs",i).removeClass("tabs"),s.parent().addClass("tabs"),k(".quick-search",i).focus(),i.find(".tabs-panel-active .menu-item-title").length?i.removeClass("has-no-menu-item"):i.addClass("has-no-menu-item"),e.preventDefault();else if(s.hasClass("select-all")){if((t=/#(.*)$/.exec(e.target.href))&&t[1])return(a=k("#"+t[1]+" .tabs-panel-active .menu-item-title input")).length===a.filter(":checked").length?a.removeAttr("checked"):a.prop("checked",!0),!1}else if(s.hasClass("submit-add-to-menu"))return y.registerChange(),e.target.id&&"submit-customlinkdiv"==e.target.id?y.addCustomLink(y.addMenuItemToBottom):e.target.id&&-1!=e.target.id.indexOf("submit-")&&k("#"+e.target.id.replace(/submit-/,"")).addSelectedToMenu(y.addMenuItemToBottom),!1}),k("#nav-menu-meta").on("click","a.page-numbers",function(){var i=k(this).closest(".inside");return k.post(ajaxurl,this.href.replace(/.*\?/,"").replace(/action=([^&]*)/,"")+"&action=menu-get-metabox",function(e){var t,n=k.parseJSON(e);-1!==e.indexOf("replace-id")&&(t=document.getElementById(n["replace-id"]),n.markup&&t&&i.html(n.markup))}),!1})},eventOnClickEditLink:function(e){var t,n,i=/#(.*)$/.exec(e.href);if(i&&i[1]&&0!==(n=(t=k("#"+i[1])).parent()).length)return n.hasClass("menu-item-edit-inactive")?(t.data("menu-item-data")||t.data("menu-item-data",t.getItemData()),t.slideDown("fast"),n.removeClass("menu-item-edit-inactive").addClass("menu-item-edit-active")):(t.slideUp("fast"),n.removeClass("menu-item-edit-active").addClass("menu-item-edit-inactive")),!1},eventOnClickCancelLink:function(e){var t=k(e).closest(".menu-item-settings");return k(e).closest(".menu-item").removeClass("menu-item-edit-active").addClass("menu-item-edit-inactive"),t.setItemData(t.data("menu-item-data")).hide(),!1},eventOnClickMenuSave:function(){var e="",t=k("#menu-name"),n=t.val();return n&&n!=t.attr("title")&&n.replace(/\s+/,"")?(k("#nav-menu-theme-locations select").each(function(){e+=''}),k("#update-nav-menu").append(e),y.menuList.find(".menu-item-data-position").val(function(e){return e+1}),!(window.onbeforeunload=null)):(t.parent().addClass("form-invalid"),!1)},eventOnClickMenuDelete:function(){return!!window.confirm(navMenuL10n.warnDeleteMenu)&&!(window.onbeforeunload=null)},eventOnClickMenuItemDelete:function(e){var t=parseInt(e.id.replace("delete-",""),10);return y.removeMenuItem(k("#menu-item-"+t)),y.registerChange(),!1},processQuickSearchQueryResponse:function(e,t,n){var i,a,s,m={},u=document.getElementById("nav-menu-meta"),r=/menu-item[(\[^]\]*/,o=k("
").html(e).find("li"),c=n.closest(".accordion-section-content");if(!o.length)return k(".categorychecklist",n).html("
  • "+navMenuL10n.noResultsFound+"

  • "),k(".spinner",n).removeClass("is-active"),void c.addClass("has-no-menu-item");o.each(function(){if(s=k(this),(i=r.exec(s.html()))&&i[1]){for(a=i[1];u.elements["menu-item["+a+"][menu-item-type]"]||m[a];)a--;m[a]=!0,a!=i[1]&&s.html(s.html().replace(new RegExp("menu-item\\["+i[1]+"\\]","g"),"menu-item["+a+"]"))}}),k(".categorychecklist",n).html(o),k(".spinner",n).removeClass("is-active"),c.removeClass("has-no-menu-item")},removeMenuItem:function(t){var n=t.childMenuItems();k(document).trigger("menu-removing-item",[t]),t.addClass("deleting").animate({opacity:0,height:0},350,function(){var e=k("#menu-instructions");t.remove(),n.shiftDepthClass(-1).updateParentMenuItemDBId(),0===k("#menu-to-edit li").length&&(k(".drag-instructions").hide(),e.removeClass("menu-instructions-inactive")),y.refreshAdvancedAccessibility()})},depthToPx:function(e){return e*y.options.menuItemDepthPerLevel},pxToDepth:function(e){return Math.floor(e/y.options.menuItemDepthPerLevel)}},k(document).ready(function(){wpNavMenu.init()})}(jQuery);