(t=>{t(document).ready(function(){var m,a;n.menu_item_mouseup(),n.megamenu_status_update(),n.update_megamenu_fields(),t(".remove-mh-megamenu-background").manage_thumbnail_display(),t(".mh-megamenu-background-image").css("display","block"),t(".mh-megamenu-background-image[src='']").css("display","none"),t(document.body).on("click.mhOpenMediaManager",".mh-open-media",function(e){e.preventDefault(),a=this.id.replace("mh-media-upload-",""),m||(m=wp.media.frames.MHMediaFrame=wp.media({className:"media-frame mh-media-frame",frame:"select",multiple:!1,library:{type:"image"}})).on("select",function(){var e=m.state().get("selection").first().toJSON();t("#edit-menu-item-megamenu-background-"+a).val(e.url),t("#mh-media-img-"+a).attr("src",e.url).css("display","block")}),m.open()})});var n={menu_item_mouseup:function(){t(document).on("mouseup",".menu-item-bar",function(e,m){t(e.target).is("a")||setTimeout(n.update_megamenu_fields,300)})},megamenu_status_update:function(){t(document).on("click",".edit-menu-item-mh-megamenu-check",function(){var e=t(this).parents(".menu-item:eq( 0 )");t(this).is(":checked")?e.addClass("mh-megamenu"):e.removeClass("mh-megamenu"),n.update_megamenu_fields()})},update_megamenu_fields:function(){var a=t(".menu-item");a.each(function(e){var m=t(".edit-menu-item-mh-megamenu-check",this);t(this).is(".menu-item-depth-0")?m.attr("checked")&&t(this).addClass("mh-megamenu"):a.filter(":eq("+(e-1)+")").is(".mh-megamenu")?(m.attr("checked","checked"),t(this).addClass("mh-megamenu")):(m.attr("checked",""),t(this).removeClass("mh-megamenu"))})}};t.fn.manage_thumbnail_display=function(e){var m;return this.click(function(e){e.preventDefault(),m=this.id.replace("mh-media-remove-",""),t("#edit-menu-item-megamenu-background-"+m).val(""),t("#mh-media-img-"+m).attr("src","").css("display","none")})}})(jQuery);