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