-
Notifications
You must be signed in to change notification settings - Fork 7
/
script.min.js
1 lines (1 loc) · 1.6 KB
/
script.min.js
1
var gform_notification_attachment;jQuery(document).ready(function(){var e=jQuery("#gform_notification_attachment"),i=jQuery.parseJSON(e.find(".attachment_ids").val()||"[]"),i=jQuery.makeArray(i);0<e.find(".details li").length&&e.show(),e.find(".remove").on("click",function(t){var a;t.preventDefault(),confirm("Are you sure you wish to remove this attachment?")&&(a=jQuery(this).parent(),-1<(t=i.indexOf(a.data("id")))&&(i.splice(t,1),e.find(".attachment_ids").val(JSON.stringify(i))),a.remove())}),e.find(".add").on("click",function(t){t.preventDefault(),gform_notification_attachment||(gform_notification_attachment=wp.media.frames.gform_notification_attachment=wp.media({title:jQuery(this).attr("title"),button:{text:jQuery(this).attr("title")},multiple:!1})).on("select",function(){attachment=gform_notification_attachment.state().get("selection").first().toJSON();var t={action:"gf_notification_attachment",attachment_id:attachment.id};jQuery.post(ajaxurl,t,function(t){var a;(t=jQuery.parseJSON(t)).success?(a=jQuery("<li/>").data("id",attachment.id),t=[jQuery("<div/>").addClass("remove dashicons dashicons-dismiss"),jQuery("<img/>").addClass("fl").attr("src",t.data.mime_file),jQuery("<div/>").addClass("fl file-details").append(jQuery("<span/>").text(t.data.title).addClass("title"),jQuery("<span/>").text("["+t.data.mime+"]").addClass("mime")),jQuery("<br/>").addClass("clear")],a.append(t),e.find(".details").append(a),i.push(attachment.id),e.find(".attachment_ids").val(JSON.stringify(i))):alert("The system could not attach the selected file to the notification. Please try again.")})}),gform_notification_attachment.open()})});