jQuery(document).ready(function(e){"use strict";e(".elementskit-menu-wpcolor-picker").wpColorPicker();var t=e(".elementskit-menu-icon-picker").fontIconPicker();e(".elementskit-menu-settings-save").on("click",function(){var t=e("#elementskit-menu-metabox-input-is-enabled:checked").length,n=e("#elementskit-menu-metabox-input-menu-id").val(),i=e(this).parent().find(".spinner"),m={is_enabled:t,menu_id:n};i.addClass("loading"),e.get(window.elementskit.resturl+"megamenu/save_megamenu_settings",m).done(function(e){i.removeClass("loading")})}),e(".elementskit-menu-item-save").on("click",function(){var t=e(this).parent().find(".spinner"),n={settings:{menu_id:e("#elementskit-menu-modal-menu-id").val(),menu_has_child:e("#elementskit-menu-modal-menu-has-child").val(),menu_enable:e("#elementskit-menu-item-enable:checked").val(),menu_icon:e("#elementskit-menu-icon-field").val(),menu_icon_color:e("#elementskit-menu-icon-color-field").val(),menu_badge_text:e("#elementskit-menu-badge-text-field").val(),menu_badge_color:e("#elementskit-menu-badge-color-field").val(),menu_badge_background:e("#elementskit-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.elementskit.resturl+"megamenu/save_menuitem_settings",n).done(function(n){t.removeClass("loading"),e("#elementskit-menu-item-settings-modal").modal("hide")})}),e("#elementskit-menu-builder-trigger").on("click",function(){var t=e("#elementskit-menu-modal-menu-id").val(),n=window.elementskit.resturl+"dynamic-content/content_editor/megamenu/menuitem"+t;e("#elementskit-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);t.find(".elementskit_menu_trigger").length<1&&e(".item-title",t).append("<a data-attr-toggle='modal' data-target='#attr_menu_control_panel_modal' href='#' class='elementskit_menu_trigger'>Mega Menu</a> ")})},200)}),e("#menu-to-edit").trigger("DOMSubtreeModified"),e("#menu-to-edit").on("click",".elementskit_menu_trigger",function(n){n.preventDefault();var i=e("#attr_menu_control_panel_modal"),m=e(this).parents("li.menu-item"),l=parseInt(m.attr("id").match(/[0-9]+/)[0],10);m.find(".menu-item-title").text(),m.attr("class").match(/\menu-item-depth-(\d+)\b/)[1];if(e(".ekit_menu_control_nav > li").removeClass("attr-active"),e(".attr-tab-pane").removeClass("attr-active"),e(this).parents(".menu-item").hasClass("menu-item-depth-0")){var a=0;i.removeClass("elementskit-menu-has-child"),e("#attr_content_nav").addClass("attr-active"),e("#attr_content_tab").addClass("attr-active")}else{a=1;i.addClass("elementskit-menu-has-child"),e("#attr_icon_nav").addClass("attr-active"),e("#attr_icon_tab").addClass("attr-active")}e("#elementskit-menu-modal-menu-id").val(l),e("#elementskit-menu-modal-menu-has-child").val(a);var o={menu_id:l};e.get(window.elementskit.resturl+"megamenu/get_menuitem_settings",o).done(function(n){e("#elementskit-menu-item-enable").prop("checked",!1),e("#elementskit-menu-icon-color-field").wpColorPicker("color",n.menu_icon_color),e("#elementskit-menu-icon-field").val(n.menu_icon),e("#elementskit-menu-badge-text-field").val(n.menu_badge_text),e("#elementskit-menu-badge-color-field").wpColorPicker("color",n.menu_badge_color),e("#elementskit-menu-badge-background-field").wpColorPicker("color",n.menu_badge_background),void 0!==n.menu_enable&&1==n.menu_enable?e("#elementskit-menu-item-enable").prop("checked",!0):e("#elementskit-menu-item-enable").prop("checked",!1),e("#mobile_submenu_content_type input").prop("checked",!1),void 0===n.mobile_submenu_content_type||"builder_content"==n.mobile_submenu_content_type?e("#mobile_submenu_content_type input[value=builder_content]").prop("checked",!0):e("#mobile_submenu_content_type input[value=submenu_list]").prop("checked",!0),e("#elementskit-menu-item-enable").trigger("change"),t.refreshPicker(),setTimeout(function(){i.removeClass("elementskit-menu-modal-loading")},500)})}),e("#elementskit-menu-item-enable").on("change",function(){e(this).is(":checked")?(e("#elementskit-menu-builder-trigger").prop("disabled",!1),e("#elementskit-menu-builder-warper").addClass("is_enabled")):(e("#elementskit-menu-item-enable").prop("checked",!1),e("#elementskit-menu-builder-warper").removeClass("is_enabled"),e("#elementskit-menu-builder-trigger").prop("disabled",!0))}),e("#post-body-content").on("change","#elementskit-menu-metabox-input-is-enabled",function(){console.log(e(this).is(":checked")),e(this).is(":checked")?e("body").addClass("is_mega_enabled").removeClass("is_mega_disabled"):e("body").removeClass("is_mega_enabled").addClass("is_mega_disabled")}),e("#post-body-content").prepend(window.elementskit_options_megamenu_markup).find("#elementskit-menu-metabox-input-is-enabled").trigger("change")});