1 line
1.4 KiB
JavaScript
1 line
1.4 KiB
JavaScript
jQuery(document).ready(function(a){var b;a("#wpo-wcpdf-settings, .wpo-wcpdf-setup").on("click",".wpo_upload_image_button",function(c){c.preventDefault();let d=a(this).parent();return b?void b.open():void(b=wp.media.frames.file_frame=wp.media({title:a(this).data("uploader_title"),button:{text:a(this).data("uploader_button_text")},multiple:!1}),b.on("select",function(){let c=d.find("input.media-upload-id"),e=d.find("img.media-upload-preview"),f=b.state().get("selection").first().toJSON();c.val(f.id),e.length&&e.attr("src",f.url),a(".attachment-resolution, .attachment-resolution-warning").remove(),d.css("opacity","0.25");let g={security:c.data("ajax_nonce"),action:"wpo_wcpdf_get_media_upload_setting_html",args:c.data("settings_callback_args"),attachment_id:f.id};xhr=a.ajax({type:"POST",url:wpo_wcpdf_admin.ajaxurl,data:g,success:function(b){b&&"undefined"!=typeof b.success&&!0===b.success&&d.html(b.data),d.removeAttr("style"),c=d.find("input.media-upload-id"),a(document.body).trigger("wpo-wcpdf-media-upload-setting-updated",[c])},error:function(){d.removeAttr("style")}})}),b.open())}),a("#wpo-wcpdf-settings, .wpo-wcpdf-setup").on("click",".wpo_remove_image_button",function(){let b=a(this).parent(),c=b.find("input.media-upload-id"),d=b.find("img.media-upload-preview");c.val(""),d.remove(),a(this).remove(),a(".attachment-resolution, .attachment-resolution-warning").remove()})}); |