var WCML_Dialog=WCML_Dialog||{};jQuery(function($){var dialog_div;WCML_Dialog.dialog=function(dialog_id,data){var self=this;if(typeof dialog_id=="undefined"){dialog_id="generic"}self.overflow_y=$("body").css("overflow-y");$("body").css("overflow-y","hidden");dialog_div=$("#wcml-dialog-"+dialog_id);var title=$("#"+dialog_id).attr("title");if(typeof title=="undefined"){if(data.title!="undefined"){title=data.title}else{title=""}}if(typeof data.class==="undefined"){data.class=""}if(typeof data.draggable==="undefined"){data.draggable=false}if(!dialog_div.length){$(document.body).append($('
'));dialog_div=$("#wcml-dialog-"+dialog_id);var window_h=$(window).height();var dialog_parameters={title:"",autoOpen:false,show:true,dialogClass:"wcml-ui-dialog otgs-ui-dialog "+data.class,position:{my:"center",at:"center",of:window},modal:true,width:"90%",height:window_h*.7,resizable:false,draggable:data.draggable,beforeOpen:function(event){},beforeClose:function(event){},close:function(event){$("body").css("overflow-y",self.overflow_y)},create:function(event){},focus:function(event){},open:function(event){$("body").css("overflow","hidden");if(data.class==="wcml-cs-dialog"){WCML_Dialog._attachDialogScrollEvent()}},refresh:function(event){}};if(typeof data.height!="undefined"&&data.class!="wcml-cs-dialog"){dialog_parameters.height=Math.min(window_h*.7,data.height)}if(typeof data.width!="undefined"&&data.class!="wcml-cs-dialog"){dialog_parameters.width=data.width}if(WCML_Dialog.using_wpdialog){dialog_div.wpdialog(dialog_parameters)}else{dialog_div.dialog(dialog_parameters).on("dialogopen",function(){WCML_Dialog._repositionDialog()})}}var resizeWindowEvent=_.debounce(function(){WCML_Dialog._repositionDialog();if(data.class==="wcml-cs-dialog"){WCML_Dialog._attachDialogScrollEvent()}},200);if(WCML_Dialog.using_wpdialog){dialog_div.wpdialog("open")}else{dialog_div.dialog("open")}if(data.action){var spinner=$('
');spinner.css({display:"inline-block",visibility:"visible",float:"none"});dialog_div.html(spinner);$.ajax({url:ajaxurl,type:"post",dataType:"json",data:data,success:function(response){dialog_div.html(response.html)}})}if(data.content&&$("#"+data.content).length){dialog_div.html($("#"+data.content).html())}if(typeof WCML_Tooltip!="undefined"){WCML_Tooltip.init()}$(window).resize(resizeWindowEvent);return false};WCML_Dialog._repositionDialog=function(){var winH=$(window).height()-180;dialog_div.css("max-height",winH);dialog_div.dialog("option","position",{my:"center",at:"center",of:window})};WCML_Dialog._attachDialogScrollEvent=function(){var preview=dialog_div.find(".wcml-currency-preview-wrapper"),has_two_columns=dialog_div.width()>900,has_minimal_height=preview.height()+200
');spinner.css({visibility:"visible",float:"right"}).prependTo($(".wcml-dialog-footer .alignright"));$.ajax({url:ajaxurl,type:"post",dataType:"json",data:{action:data.action,fields:elem.closest(".wcml-dialog-container").find("form").serialize(),icl_nonce:data.nonce},async:false,success:function(response){if(data.stay){spinner.remove();elem.removeAttr("disabled")}}})}if(!data.stay){elem.trigger("before_close_dialog");if(WCML_Dialog.using_wpdialog){dialog_div.wpdialog("close")}else{dialog_div.dialog("close")}}})};WCML_Dialog.init=function(){$(document).ready(function(){if(typeof $.wp!="undefined"){WCML_Dialog.using_wpdialog=typeof $.wp.wpdialog!="undefined"}else{WCML_Dialog.using_wpdialog=false}WCML_Dialog._register_open_handler();WCML_Dialog._register_close_handler()})};WCML_Dialog.init()});