Mercurial > public > sg101
diff static/js/markitup/sets/markdown/set.js @ 971:4f265f61874b
Hotlink image form is functioning.
The user can now submit a URL via a form and the URL will be downloaded
and uploaded to a S3 bucket if it is an image.
Tests to follow.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Tue, 22 Sep 2015 20:23:50 -0500 |
parents | 682b159f3763 |
children | 8c3d52b7cbd1 |
line wrap: on
line diff
--- a/static/js/markitup/sets/markdown/set.js Sun Sep 13 14:51:33 2015 -0500 +++ b/static/js/markitup/sets/markdown/set.js Tue Sep 22 20:23:50 2015 -0500 @@ -179,4 +179,38 @@ } }); } + + var $hotLinkForm = $('#hot-link-form'); + if ($hotLinkForm.length) { + var $postBox = $('#id_body'); + var $hotLinkFormSubmit = $('#hot-link-form-submit'); + + $hotLinkForm.ajaxForm({ + beforeSubmit: function(arr, $form, options) { + var url = null; + $.each(arr, function(index, val) { + if (val.name == 'url') { + url = val.value; + } + }); + if (!url) { + alert("Please enter an image URL."); + return false; + } + $hotLinkFormSubmit.attr('disabled', 'disabled').val('Retrieving...'); + return true; + }, + success: function(resp, statusText, xhr, $form) { + $postBox.val($postBox.val() + '\n![image](' + resp.url + ')'); + alert("Success! The image code was added to your post."); + $hotLinkForm.clearForm(); + }, + complete: function(xhr) { + $hotLinkFormSubmit.removeAttr('disabled').val('Hot Link'); + }, + error: function(xhr, textStatus, ex) { + alert('Oops, there was an error: ' + ex); + } + }); + } });