jQuery(function(b){var k=b(".mpsl-sliders-table"),d=b("#mpsl-import-export-wrapper"),c=b("#mpsl-slider-preset-wrapper"),n=d.find(".mpsl-export-table"),g=b(".mpsl-slider-preview"),h=g.find("iframe"),p=g.find(".mpsl-preloader"),f=MPSL.Vars.menu_url,q=null,w=g.find(".mpsl-resolution-buttons-wrapper"),r=g.find(".desktop"),s=g.find(".mpsl-slider-preview-footer-message"),f=MPSL.Functions.addParamToUrl(f,"view","preview"),f=MPSL.Functions.addParamToUrl(f,"type","sliders");g.dialog({resizable:!1,draggable:!1,
autoOpen:!1,modal:!0,width:b(window).width()-100,height:b(window).height()-100,title:MPSL.Vars.lang.preview_dialog_title,closeText:"",dialogClass:"mpsl-preview-dialog",close:function(){(h[0].contentDocument||h[0].contentWindow.document).documentElement.innerHTML=""},beforeClose:function(){s.addClass("hidden")},open:function(){p.show();s.removeClass("hidden");f=MPSL.Functions.removeParamFromUrl(f,"slider_id");f=MPSL.Functions.addParamToUrl(f,"slider_id",q);h.attr("src",f);h.width("100%");r.siblings().removeClass("active");
r.addClass("active")},create:function(){w.removeClass("hidden")}});[{type:"desktop",resolution:"100%"},{type:"tablet",resolution:"768px"},{type:"mobile",resolution:"480px"}].forEach(function(a){g.on("click","."+a.type,function(){h.width(a.resolution);b(this).siblings().removeClass("active");b(this).addClass("active");(h[0].contentWindow||h[0].contentDocument)._mpslResizePreview()})});h.on("load",function(){p.hide()});k.on("click",".mpsl-delete-slider-btn",function(a){a.preventDefault();var e=b(this),
l=b(this).attr("data-mpsl-slider-id");if(0==confirm(MPSL.Vars.lang.slider_want_delete_single.replace("%d",l)))return!0;e.attr("disabled","disabled");b.ajax({type:"POST",url:MPSL.Vars.ajax_url,data:{action:"mpsl_delete_slider",nonce:MPSL.Vars.nonces.delete_slider,id:l},success:function(a){e.removeAttr("disabled");a.result&&!0===a.result?(e.closest("tr").remove(),k.find("tbody>tr").length||k.hide(),window.location.reload(!0),MPSL.Functions.showMessage(MPSL.Vars.lang.slider_deleted_id.replace("%d",l),
MPSL.Functions.MSG_SUCCESS_TYPE)):MPSL.Functions.showMessage(a.error,MPSL.Functions.MSG_ERROR_TYPE)},error:function(a){console.error(a)},dataType:"JSON"})});k.on("click",".mpsl-duplicate-slider-btn",function(a){a.preventDefault();var e=b(this);e.attr("disabled","disabled");a=b(this).attr("data-mpsl-slider-id");b.ajax({type:"POST",url:MPSL.Vars.ajax_url,data:{action:"mpsl_duplicate_slider",nonce:MPSL.Vars.nonces.duplicate_slider,id:a},success:function(a){e.removeAttr("disabled");a.hasOwnProperty("result")&&
!0===a.result?(k.append(a.html),MPSL.Functions.showMessage(MPSL.Vars.lang.slider_duplicated,MPSL.Functions.MSG_SUCCESS_TYPE),window.location.reload(!0)):MPSL.Functions.showMessage(a.error,MPSL.Functions.MSG_ERROR_TYPE)},error:function(a){console.error(a)},dataType:"JSON"})});k.on("click",".mpsl-preview-slider-btn",function(a){a.preventDefault();q=b(a.target).attr("data-mpsl-slider-id");g.dialog("open")});var x=d.find("#mpsl-import-form"),t=d.find("#mpsl-export-form");d.dialog({resizable:!1,draggable:!1,
autoOpen:!1,modal:!0,width:800,height:b(window).height()-85,title:MPSL.Vars.lang.import_export_dialog_title,closeText:"",dialogClass:"mpsl-import-export-dialog",close:function(a,b){},open:function(){x[0].reset();t.length&&t[0].reset()}});var u=function(){var a=c.find(".mpsl-slider-preset-footer").height(),e=c.find(".mpsl-presets-tables-wrapper");b(e).height(c.outerHeight(!0)-a-24);c.dialog("option","position",{my:"center",at:"center",of:window})};c.dialog({resizable:!1,draggable:!1,autoOpen:!1,modal:!0,
width:950,height:b(window).height()/1.5,title:MPSL.Vars.lang.template_dialog_title,closeText:"",dialogClass:"mpsl-template-dialog",position:{my:"center",at:"center",of:window},close:function(a,b){},beforeClose:function(){c.addClass("hide-slider-preset-wrapper")},open:function(){c.removeClass("hide-slider-preset-wrapper");u();c.outerHeight(!0)}});b(window).on("resize",function(){var a=b(window).height()/1.5;c.dialog("option","height",0<a?a:0);u()});b(".ui-widget-overlay").on("click",function(){d.dialog("isOpen")&&
d.dialog("close")});b("#template-btn").on("click",function(){c.dialog("open")});b("#import-export-btn").on("click",function(){d.dialog("open")});d.on("click",".export-check-all",function(a){a=b(a.target).prop("checked");n.find(".mpsl-export-id-checkbox").prop("checked",a)});d.on("click","#mpsl-export-btn",function(a){n.find(".mpsl-export-id-checkbox:checked").length||(a.preventDefault(),a.stopPropagation(),MPSL.Functions.showMessage(MPSL.Vars.lang.no_sliders_selected_to_export,MPSL.Functions.MSG_ERROR_TYPE))});
d.on("change","input[name=mpsl_http_auth]",function(a){var e=d.find("input[name=mpsl_http_auth_login], input[name=mpsl_http_auth_password]"),c=d.find(".need-mpsl_http_auth");b(a.target).is(":checked")?(e.removeAttr("disabled").attr("required","required"),c.show()):(e.removeAttr("required").attr("disabled","disabled"),c.hide())});c.find("form").on("submit",function(a){var c=b(this).find('input[type="radio"]:checked'),d=c.data("type");c.parents("table").hasClass("mpsl-templates-group-main")&&(a.preventDefault(),
window.location.href=MPSL.Vars.menu_url+"&view=slider&slider_type="+d)});var v=c.find(".mpsl-templates-group-main"),y=c.find(".mpsl-templates-group-sample"),z=v.find('input[type="radio"]'),m=y.find("td");z.on("change",function(){m.removeClass("active")});m.on("click",function(){v.find('input[type="radio"]:checked').attr("checked",!1);b(this).find('input[type="radio"]').attr("checked",!0);m.removeClass("active");b(this).addClass("active")})});
