Mercurial > public > sg101
changeset 725:682b159f3763
On comment views, the photo uploading stuff won't be there. Fix javascript.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 21 Sep 2013 21:18:40 -0500 |
parents | 8b027e7a7977 |
children | f0b997651497 |
files | comments/templatetags/comment_tags.py static/js/markitup/sets/markdown/set.js |
diffstat | 2 files changed, 48 insertions(+), 47 deletions(-) [+] |
line wrap: on
line diff
--- a/comments/templatetags/comment_tags.py Sat Sep 21 18:06:57 2013 -0500 +++ b/comments/templatetags/comment_tags.py Sat Sep 21 21:18:40 2013 -0500 @@ -10,7 +10,6 @@ from django import template from django.conf import settings from django.template.loader import render_to_string -from django.contrib.contenttypes.models import ContentType from comments.models import Comment from comments.forms import CommentForm
--- a/static/js/markitup/sets/markdown/set.js Sat Sep 21 18:06:57 2013 -0500 +++ b/static/js/markitup/sets/markdown/set.js Sat Sep 21 21:18:40 2013 -0500 @@ -128,53 +128,55 @@ }); var $photoProgress = $('#photo-upload-progress'); - var $photoForm = $('#photo-upload-form'); - var $postBox = $('#id_body'); - var $photoUploadSubmit = $('#photo-upload-submit'); + if ($photoProgress.length) { + var $photoForm = $('#photo-upload-form'); + var $postBox = $('#id_body'); + var $photoUploadSubmit = $('#photo-upload-submit'); - $photoForm.ajaxForm({ - beforeSubmit: function(arr, $form, options) { - var fileObj = null; - $.each(arr, function(index, val) { - if (val.name == 'image_file') { - fileObj = val.value; + $photoForm.ajaxForm({ + beforeSubmit: function(arr, $form, options) { + var fileObj = null; + $.each(arr, function(index, val) { + if (val.name == 'image_file') { + fileObj = val.value; + } + }); + if (!fileObj) { + alert("Please choose a file to upload."); + return false; } - }); - if (!fileObj) { - alert("Please choose a file to upload."); - return false; + $photoUploadSubmit.attr('disabled', 'disabled').val('Uploading...'); + return true; + }, + beforeSend: function() { + $photoProgress.progressbar({value: 0}); + }, + uploadProgress: function(event, position, total, percentComplete) { + if (percentComplete < 100) { + $photoProgress.progressbar({value: percentComplete}); + } + else { + $photoProgress.progressbar({value: false}); + } + }, + success: function(resp, statusText, xhr, $form) { + $photoProgress.progressbar({value: 100}); + if (resp.success) { + $postBox.val($postBox.val() + '\n![image](' + resp.url + ')'); + alert("Success! The image code was added to your post."); + } + else { + alert('Error: ' + resp.msg); + } + }, + complete: function(xhr) { + $photoProgress.progressbar({value: 0}); + $photoForm.clearForm(); + $photoUploadSubmit.removeAttr('disabled').val('Upload photo'); + }, + error: function(xhr, textStatus, ex) { + alert('Oops, there was an error: ' + ex); } - $photoUploadSubmit.attr('disabled', 'disabled').val('Uploading...'); - return true; - }, - beforeSend: function() { - $photoProgress.progressbar({value: 0}); - }, - uploadProgress: function(event, position, total, percentComplete) { - if (percentComplete < 100) { - $photoProgress.progressbar({value: percentComplete}); - } - else { - $photoProgress.progressbar({value: false}); - } - }, - success: function(resp, statusText, xhr, $form) { - $photoProgress.progressbar({value: 100}); - if (resp.success) { - $postBox.val($postBox.val() + '\n![image](' + resp.url + ')'); - alert("Success! The image code was added to your post."); - } - else { - alert('Error: ' + resp.msg); - } - }, - complete: function(xhr) { - $photoProgress.progressbar({value: 0}); - $photoForm.clearForm(); - $photoUploadSubmit.removeAttr('disabled').val('Upload photo'); - }, - error: function(xhr, textStatus, ex) { - alert('Oops, there was an error: ' + ex); - } - }); + }); + } });