# HG changeset patch # User Brian Neal # Date 1379816320 18000 # Node ID 682b159f37630fe85566151633e4411e9f717973 # Parent 8b027e7a7977764767f9e9e631d34773dba88f99 On comment views, the photo uploading stuff won't be there. Fix javascript. diff -r 8b027e7a7977 -r 682b159f3763 comments/templatetags/comment_tags.py --- 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 diff -r 8b027e7a7977 -r 682b159f3763 static/js/markitup/sets/markdown/set.js --- 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); - } - }); + }); + } });