(function(c,a){a.FormController("MPSL.SliderFormController",{},{optionControllers:{},dependency:{},disabled_dependency:{},preview_wrapper:null,init:function(d,e){var b=this;this._super(d,e);this.changeShortcode();this.optionControllers.alias.on("change",function(){b.changeShortcode()});c("#mpsl-slider-settings-tabs").tabs({activate:function(b,f){a.CodeMirrorControl.refreshEditors(f.newPanel)}});var f=c(".mpsl-slider-posts-preview");f.length&&new a.PostListPreview(f);this.preview_wrapper=c(".mpsl-slider-preview"); this.previewIframe=this.preview_wrapper.find("iframe");this.preloader=this.preview_wrapper.find(".mpsl-preloader");this.previewUrl=a.Vars.menu_url;this.previewSliderId=null;this.resolutionWrapper=this.preview_wrapper.find(".mpsl-resolution-buttons-wrapper");this.desktopIcon=this.preview_wrapper.find(".desktop");this.footerMessageWrapper=this.preview_wrapper.find(".mpsl-slider-preview-footer-message");this.previewUrl=a.Functions.addParamToUrl(this.previewUrl,"view","preview");this.previewUrl=a.Functions.addParamToUrl(this.previewUrl, "type","slider");this.preview_wrapper.dialog({resizable:!1,draggable:!1,autoOpen:!1,modal:!0,width:c(window).width()-100,height:c(window).height()-100,title:a.Vars.lang.preview_dialog_title,closeText:"",dialogClass:"mpsl-preview-dialog",close:function(){(b.previewIframe[0].contentDocument||b.previewIframe[0].contentWindow.document).documentElement.innerHTML=""},beforeClose:function(){c("body").css("overflow","inherit");b.footerMessageWrapper.addClass("hidden")},open:function(){b.footerMessageWrapper.removeClass("hidden"); c("body").css("overflow","hidden");b.preloader.show();b.previewUrl=a.Functions.removeParamFromUrl(b.previewUrl,"slider_id");b.previewUrl=a.Functions.addParamToUrl(b.previewUrl,"slider_id",b.previewSliderId);b.previewIframe.attr("src",b.previewUrl);b.previewIframe.width("100%");b.desktopIcon.siblings().removeClass("active");b.desktopIcon.addClass("active")},create:function(){b.resolutionWrapper.removeClass("hidden")}});this.resBtns=[{type:"desktop",resolution:"100%"},{type:"tablet",resolution:"768px"}, {type:"mobile",resolution:"480px"}];this.resBtns.forEach(function(a){b.preview_wrapper.on("click","."+a.type,function(){b.previewIframe.width(a.resolution);c(this).siblings().removeClass("active");c(this).addClass("active");(b.previewIframe[0].contentWindow||b.previewIframe[0].contentDocument)._mpslResizePreview()})});this.previewIframe.on("load",function(){b.preloader.hide()});this.constructor.ready()},changeShortcode:function(c){this.optionControllers.shortcode.setValue("["+a.Vars.settings.shortcode_name+ " "+this.optionControllers.alias.getValue()+"]")},disableBtns:function(){this.element.find("#update_slider, #delete_slider, #create_slider, #edit_slides").attr("disabled","disabled")},enableBtns:function(){this.element.find("#update_slider, #delete_slider, #create_slider, #edit_slides").removeAttr("disabled","disabled")},"#update_slider, #slider_preview click":function(d,e){e.preventDefault();var b=this,f="slider_preview"===d.attr("id");f||this.disableBtns();if(b.verifyOptions()){var g=this.getFormData(), g={action:"mpsl_update_slider",nonce:a.Vars.nonces.update_slider,options:JSON.stringify(g),preview:f},h=a.Vars.page.id;h&&(g.id=h);c.ajax({type:"POST",url:a.Vars.ajax_url,data:g,success:function(c){f?(b.previewSliderId=h,b.preview_wrapper.dialog("open")):(b.enableBtns(),c.hasOwnProperty("result")&&(!0===c.result?a.Functions.showMessage(a.Vars.lang.slider_updated,a.Functions.MSG_SUCCESS_TYPE):a.Functions.showMessage(a.Vars.lang.slider_update_error+c.error,a.Functions.MSG_ERROR_TYPE)))},error:function(f){f= c.parseJSON(f.responseText);f.debug?console.log(f.message):a.Functions.showMessage(f.message,a.Functions.MSG_ERROR_TYPE);b.enableBtns()},dataType:"JSON"})}else b.enableBtns()},"#create_slider click":function(d){var e=this;e.disableBtns();if(e.verifyOptions()){d=e.getFormData();var b=e.optionControllers.slider_type.getValue();d={action:"mpsl_create_slider",nonce:a.Vars.nonces.create_slider,options:JSON.stringify(d),slider_type:b};c.ajax({type:"POST",url:a.Vars.ajax_url,data:d,success:function(f){if(f.hasOwnProperty("result"))if(!0=== f.result){a.Functions.showMessage(a.Vars.lang.slider_created,a.Functions.MSG_SUCCESS_TYPE);var c=a.Functions.removeParamFromUrl(window.location.href,"view"),c=a.Functions.removeParamFromUrl(c,"slider_type"),c="custom"===b?a.Functions.addParamsToUrl(c,{view:"slides",id:f.id}):a.Functions.addParamsToUrl(c,{view:"slide",id:f.template_id});window.location.href=c}else a.Functions.showMessage(f.error,a.Functions.MSG_ERROR_TYPE);else a.Functions.showMessage(a.Vars.lang.ajax_result_not_found,a.Functions.MSG_ERROR_TYPE); e.enableBtns()},error:function(b){var d=c.parseJSON(b.responseText);d.debug?console.log(d.message):a.Functions.showMessage(d.message,a.Functions.MSG_ERROR_TYPE);e.enableBtns();console.error(b)},dataType:"JSON"})}else e.enableBtns()},"#delete_slider click":function(d){var e=this;this.disableBtns();d=a.Vars.page.id;if(0==confirm(a.Vars.lang.slider_want_delete_single.replace("%d",d)))return!0;var b={action:"mpsl_delete_slider",nonce:a.Vars.nonces.delete_slider};d&&(b.id=d);c.ajax({type:"POST",url:a.Vars.ajax_url, data:b,success:function(b){e.enableBtns();b.hasOwnProperty("result")?1==b.result?(a.Functions.showMessage(a.Vars.lang.slider_deleted,a.Functions.MSG_SUCCESS_TYPE),b=a.Functions.removeParamsFromUrl(window.location.href,["view","id"]),window.location.href=b):a.Functions.showMessage(b.error,a.Functions.MSG_ERROR_TYPE):a.Functions.showMessage(a.Vars.lang.ajax_result_not_found,a.Functions.MSG_ERROR_TYPE);e.enableBtns()},error:function(b){b=c.parseJSON(b.responseText);b.debug?console.log(b.message):a.Functions.showMessage(b.message, a.Functions.MSG_ERROR_TYPE);e.enableBtns()},dataType:"JSON"})}})})(jQuery,MPSL); (function(c,a){a.PostListPreview=can.Control.extend({},{formController:null,tableBody:null,init:function(a,e){this.formController=c(".mpsl-slider-settings-wrapper").control();this.postsTable=c(".mpsl-posts-table");this.tableBody=this.postsTable.find("tbody");this.postsTableCount=c("#mpsl-preview-posts-count");this.getPosts()},getPosts:function(){var d=this,e=d.formController.getFormData(),e={action:"mpsl_posts_preview",nonce:a.Vars.nonces.posts_preview,options:JSON.stringify(e.post_settings),type:this.formController.optionControllers.slider_type.getValue()}; c.ajax({type:"POST",url:a.Vars.ajax_url,data:e,success:function(b){d.tableBody.empty();b&&b.result&&(d.postsTableCount.text(" ("+b.posts.length+")"),c.each(b.posts,function(b,a){var e=a.image?c("",{src:a.image,width:150}).prop("outerHTML"):"";d.tableBody.append("