jQuery((function(e){"use strict";var t,i;window.send_to_editor_default=window.send_to_editor;var a=sensei_certificate_templates_params.primary_image_width,n=sensei_certificate_templates_params.primary_image_height;function r(){e(".field_pos").each((function(t,i){var n=(i=e(i)).attr("id"),r=e("#field"+n),c=e("#certificate_image_0");if(""!=c.attr("src")){var l=1;a!=c.width()&&(l=c.width()/a);var o=i.val()?i.val().split(",").map((function(e){return parseInt(e)*l})):null;0===r.length&&(e("#certificate_image_wrapper").append('<span id="field'+n+'" class="certificate_field" style="display:none;">'+sensei_certificate_templates_params[n]+"</span>"),e("#field"+n).click((function(e){s(e.target.id.substr(6))})),r=e("#field"+n)),o?(r.css({left:o[0]+"px",top:o[1]+"px",width:o[2]+"px",height:o[3]+"px"}),r.show()):r.hide()}else r&&r.hide()}))}function s(t){if(e("img#certificate_image_0").attr("src"))if(c(),e("#"+t).val()!=sensei_certificate_templates_params.done_label){e("#field_"+t).hide();var i=e("#_"+t).val()?e("#_"+t).val().split(",").map((function(e){return parseInt(e)})):[null,null,null,null];e("input.set_position").val(sensei_certificate_templates_params.set_position_label),e("#"+t).val(sensei_certificate_templates_params.done_label),e("img#certificate_image_0").imgAreaSelect({show:!0,handles:!0,instance:!0,imageWidth:a,imageHeight:n,x1:i[0],y1:i[1],x2:i[0]+i[2],y2:i[1]+i[3],onSelectEnd:function(i,a){!function(t,i){t&&0!==t.width&&0!==t.height?e("#_"+i).val(t.x1+","+t.y1+","+t.width+","+t.height):s(i),e("#remove_"+i).show()}(a,t)}}),e(document).scrollTop()>e("img#certificate_image_0").offset().top+e("img#certificate_image_0").height()*(2/3)&&e("html, body").animate({scrollTop:e("#title").offset().top},500)}else e("#"+t).val(sensei_certificate_templates_params.set_position_label)}function c(){e("img#certificate_image_0").imgAreaSelect({remove:!0}),r()}e(document).on("click","#set-certificate-image",(function(r){r.preventDefault(),i=e(this),t||(t=wp.media.frames.file_frame=wp.media({title:"Select an Image",button:{text:"Set Image"},multiple:!1})).on("select",(function(){var r=t.state().get("selection").first().toJSON();a=r.width,n=r.height,"set-certificate-image"==i.attr("id")&&(e("#upload_image_id_0").val(r.id),e("#remove-certificate-image").show(),e("img#certificate_image_0").attr("src",r.url))})),t.open()})),e("#remove-certificate-image").click((function(){return e("#upload_image_id_0").val(""),e("img#certificate_image_0").attr("src",""),e(this).hide(),!1})),e(window).resize((function(){r()})),r(),e("input.set_position").click((function(){s(this.id)})),e("input.remove_position").click((function(){e(this).hide(),e("#_"+this.id.substr(7)).val(""),e("#"+this.id.substr(7)).val(sensei_certificate_templates_params.set_position_label),c()})),"function"!=typeof jQuery.fn.hasParent&&jQuery.extend(jQuery.fn,{hasParent:function(t){return this.filter((function(){return e(t).find(this).length}))}});const l=e(".colorpick");"function"==typeof jQuery.fn.wpColorPicker&&l.length>0&&(l.wpColorPicker(),e(document).mousedown((function(t){e(t.target).hasParent(".wp-picker-holder")||e(t.target).hasParent("mark")||e(".wp-picker-holder").each((function(){e(this).fadeOut()}))})))}));