;jQuery(document).ready(function(e){"use strict";e(".elementpress-menu-wpcolor-picker").wpColorPicker();var t=e(".elementpress-menu-icon-picker").fontIconPicker();e(".elementpress-menu-settings-save").on("click",function(){var n=e("#elementpress-menu-metabox-input-is-enabled:checked").length,i=e("#elementpress-menu-metabox-input-menu-id").val(),t=e(this).parent().find(".spinner"),m={is_enabled:n,menu_id:i,};t.addClass("loading");e.get(window.elementpress.resturl+"megamenu/save_megamenu_settings",m).done(function(e){t.removeClass("loading")})});e(".elementpress-menu-item-save").on("click",function(){var t=e(this).parent().find(".spinner"),n={settings:{menu_id:e("#elementpress-menu-modal-menu-id").val(),menu_has_child:e("#elementpress-menu-modal-menu-has-child").val(),menu_enable:e("#elementpress-menu-item-enable:checked").val(),menu_icon:e("#elementpress-menu-icon-field").val(),menu_icon_color:e("#elementpress-menu-icon-color-field").val(),menu_badge_text:e("#elementpress-menu-badge-text-field").val(),menu_badge_color:e("#elementpress-menu-badge-color-field").val(),menu_badge_background:e("#elementpress-menu-badge-background-field").val(),mobile_submenu_content_type:e("#mobile_submenu_content_type input[name=content_type]:checked").val(),}};t.addClass("loading");e.get(window.elementpress.resturl+"megamenu/save_menuitem_settings",n).done(function(n){t.removeClass("loading");e("#elementpress-menu-item-settings-modal").modal("hide")})});e("#elementpress-menu-builder-trigger").on("click",function(){var t=e("#elementpress-menu-modal-menu-id").val(),n=window.elementpress.resturl+"dynamic-content/content_editor/megamenu/menuitem"+t;e("#elementpress-menu-builder-iframe").attr("src",n)});e("body").on("DOMSubtreeModified","#menu-to-edit",function(){setTimeout(function(){e("#menu-to-edit li.menu-item").each(function(){var t=e(this);if(t.find(".elementpress_menu_trigger").length<1){e(".item-title",t).append("<a data-toggle='modal' data-target='#attr_menu_control_panel_modal' href='#' class='elementpress_menu_trigger'>Mega Menu</a> ")}})},200)});e("#menu-to-edit").trigger("DOMSubtreeModified");e("#menu-to-edit").on("click",".elementpress_menu_trigger",function(n){n.preventDefault();var i=e("#attr_menu_control_panel_modal"),m=e(this).parents("li.menu-item"),a=parseInt(m.attr("id").match(/[0-9]+/)[0],10),o=m.find(".menu-item-title").text(),d=m.attr("class").match(/\menu-item-depth-(\d+)\b/)[1];e(".epress_menu_control_nav > li").removeClass("attr-active");e(".attr-tab-pane").removeClass("attr-active");if(e(this).parent().find(".is-submenu").is(":hidden")==!0){var l=0;i.removeClass("elementpress-menu-has-child");e("#attr_content_nav").addClass("attr-active");e("#attr_content_tab").addClass("attr-active")}


else{var l=1;i.addClass("elementpress-menu-has-child");e("#attr_icon_nav").addClass("attr-active");e("#attr_icon_tab").addClass("attr-active")};e("#elementpress-menu-modal-menu-id").val(a);e("#elementpress-menu-modal-menu-has-child").val(l);var s={menu_id:a};e.get(window.elementpress.resturl+"megamenu/get_menuitem_settings",s).done(function(n){e("#elementpress-menu-item-enable").prop("checked",!1);e("#elementpress-menu-icon-color-field").wpColorPicker("color",n.menu_icon_color);e("#elementpress-menu-icon-field").val(n.menu_icon);e("#elementpress-menu-badge-text-field").val(n.menu_badge_text);e("#elementpress-menu-badge-color-field").wpColorPicker("color",n.menu_badge_color);e("#elementpress-menu-badge-background-field").wpColorPicker("color",n.menu_badge_background);if(typeof n.menu_enable!==undefined&&n.menu_enable==1){e("#elementpress-menu-item-enable").prop("checked",!0)}


else{e("#elementpress-menu-item-enable").prop("checked",!1)};e("#mobile_submenu_content_type input").prop("checked",!1);if(typeof n.mobile_submenu_content_type===undefined||n.mobile_submenu_content_type=="builder_content"){e("#mobile_submenu_content_type input[value=builder_content]").prop("checked",!0)}


else{e("#mobile_submenu_content_type input[value=submenu_list]").prop("checked",!0)};e("#elementpress-menu-item-enable").trigger("change");t.refreshPicker();setTimeout(function(){i.removeClass("elementpress-menu-modal-loading")},500)})});e("#elementpress-menu-item-enable").on("change",function(){if(e(this).is(":checked")){e("#elementpress-menu-builder-trigger").prop("disabled",!1);e("#elementpress-menu-builder-warper").addClass("is_enabled")}


else{e("#elementpress-menu-item-enable").prop("checked",!1);e("#elementpress-menu-builder-warper").removeClass("is_enabled");e("#elementpress-menu-builder-trigger").prop("disabled",!0)}});e("#post-body-content").on("change","#elementpress-menu-metabox-input-is-enabled",function(){console.log(e(this).is(":checked"));if(e(this).is(":checked")){e("body").addClass("is_mega_enabled").removeClass("is_mega_disabled")}


else{e("body").removeClass("is_mega_enabled").addClass("is_mega_disabled")}});e("#post-body-content").prepend(window.elementpress_options_megamenu_markup).find("#elementpress-menu-metabox-input-is-enabled").trigger("change")});