annotate static/js/markitup/sets/markdown/set.js @ 964:51a2051588f5

Image uploading now expects a file. Refactor image uploading to not expect a Django UploadedFile and use a regular file instead. This will be needed for the future feature of being able to save and upload images from the Internet.
author Brian Neal <bgneal@gmail.com>
date Wed, 02 Sep 2015 20:50:08 -0500
parents 682b159f3763
children 4f265f61874b
rev   line source
bgneal@312 1 // -------------------------------------------------------------------
bgneal@312 2 // markItUp!
bgneal@312 3 // -------------------------------------------------------------------
bgneal@312 4 // Copyright (C) 2008 Jay Salvat
bgneal@312 5 // http://markitup.jaysalvat.com/
bgneal@312 6 // -------------------------------------------------------------------
bgneal@312 7 // MarkDown tags example
bgneal@312 8 // http://en.wikipedia.org/wiki/Markdown
bgneal@312 9 // http://daringfireball.net/projects/markdown/
bgneal@312 10 // -------------------------------------------------------------------
bgneal@312 11 // Feel free to add more tags
bgneal@312 12 // -------------------------------------------------------------------
bgneal@693 13 // Modified by Brian Neal for SurfGuitar101
bgneal@312 14 mySettings = {
bgneal@312 15 previewParserPath: '/comments/markdown/',
bgneal@312 16 previewParserVar: 'data',
bgneal@312 17 previewInWindow: false,
bgneal@312 18 previewAutoRefresh: false,
bgneal@312 19 previewPosition: 'after',
bgneal@312 20 onShiftEnter: {keepDefault:false, openWith:'\n\n'},
bgneal@312 21 markupSet: [
bgneal@312 22 {name:'Bold', key:'B', openWith:'**', closeWith:'**'},
bgneal@312 23 {name:'Italic', key:'I', openWith:'_', closeWith:'_'},
bgneal@360 24 {name:'Strike', key:'S', openWith:'---', closeWith:'---'},
bgneal@312 25 {separator:'---------------' },
bgneal@693 26 {name:'Bulleted List', openWith:'- ', multiline:true},
bgneal@312 27 {name:'Numeric List', openWith:function(markItUp) {
bgneal@312 28 return markItUp.line+'. ';
bgneal@693 29 }, multiline:true},
bgneal@312 30 {separator:'---------------' },
bgneal@312 31 {name:'Picture', key:'P', replaceWith:'![image]([![Url:!:http://]!])'},
bgneal@312 32 {name:'Link', key:'L', openWith:'[', closeWith:']([![Url:!:http://]!])', placeHolder:'Your text to link here...' },
bgneal@693 33 {separator:'---------------'},
bgneal@693 34 {name:'Quotes', openWith:'> ', multiline:true},
bgneal@693 35 {name:'Code Block / Code', openWith:'(!(\t|!|`)!)', closeWith:'(!(`)!)', multiline:true},
bgneal@312 36 {separator:'---------------'},
bgneal@312 37 {name:'Smilies', className:'smilies', dropMenu: [
bgneal@312 38 {name:'Argh', replaceWith:' :argh: ', className:'col1-1' },
bgneal@312 39 {name:'Grin', replaceWith:' :-D ', className:'col1-2' },
bgneal@312 40 {name:'Razz', replaceWith:' :-P ', className:'col1-3' },
bgneal@312 41 {name:'Confused', replaceWith:' o_O ', className:'col1-4' },
bgneal@312 42 {name:'Cool', replaceWith:' 8^) ', className:'col1-5' },
bgneal@312 43 {name:'Cry', replaceWith:' :-( ', className:'col2-1' },
bgneal@312 44 {name:'Dead', replaceWith:' x_x ', className:'col2-2' },
bgneal@312 45 {name:'Embarrassed', replaceWith:' :-# ', className:'col2-3' },
bgneal@312 46 {name:'LOL', replaceWith:' :lol: ', className:'col2-4' },
bgneal@312 47 {name:'Mad', replaceWith:' X-( ', className:'col2-5' },
bgneal@312 48 {name:'No', replaceWith:' :no: ', className:'col3-1' },
bgneal@312 49 {name:'None', replaceWith:' :-| ', className:'col3-2' },
bgneal@312 50 {name:'Shock', replaceWith:' :shock: ', className:'col3-3' },
bgneal@312 51 {name:'Sigh', replaceWith:' :sigh: ', className:'col3-4' },
bgneal@312 52 {name:'Smile', replaceWith:' :-) ', className:'col3-5' },
bgneal@312 53 {name:'Uh-oh', replaceWith:' :uh-oh: ', className:'col4-1' },
bgneal@312 54 {name:'Whatever', replaceWith:' :whatever: ', className:'col4-2' },
bgneal@312 55 {name:'Wink', replaceWith:' ;-) ', className:'col4-3' },
bgneal@312 56 {name:'Yes', replaceWith:' :yes: ', className:'col4-4' },
bgneal@312 57 {name:'Sleep', replaceWith:' :sleep: ', className:'col4-5' }
bgneal@312 58 ]
bgneal@312 59 },
bgneal@312 60 {separator:'---------------'},
bgneal@312 61 {name:'Preview', call:'preview', className:"preview"}
bgneal@312 62 ]
bgneal@312 63 }
bgneal@312 64
bgneal@312 65 // mIu nameSpace to avoid conflict.
bgneal@312 66 miu = {
bgneal@312 67 markdownTitle: function(markItUp, char) {
bgneal@312 68 heading = '';
bgneal@312 69 n = $.trim(markItUp.selection||markItUp.placeHolder).length;
bgneal@312 70 for(i = 0; i < n; i++) {
bgneal@312 71 heading += char;
bgneal@312 72 }
bgneal@312 73 return '\n'+heading;
bgneal@312 74 }
bgneal@312 75 }
bgneal@312 76
bgneal@312 77 $(document).ready(function() {
bgneal@312 78 $('.markItUp').markItUp(mySettings);
bgneal@312 79
bgneal@312 80 $('#smileys_dialog_popup').dialog({autoOpen:false});
bgneal@312 81 var firstTimeSmiley = true;
bgneal@312 82 $('#more_smileys_link').click(function () {
bgneal@312 83 $('#smileys_dialog_popup').dialog('open');
bgneal@312 84 var smileyTarget = $('.smileyTarget')[0];
bgneal@312 85 if (firstTimeSmiley) {
bgneal@312 86 $.ajax({
bgneal@312 87 url: '/smiley/farm/extra/',
bgneal@312 88 type: 'GET',
bgneal@312 89 dataType: 'html',
bgneal@312 90 success: function(data, textStatus) {
bgneal@312 91 var img = $('#smiley_busy');
bgneal@312 92 img.hide();
bgneal@312 93 img.after(data);
bgneal@312 94 $('#smileys_dialog_popup .smiley_farm img').click(function() {
bgneal@312 95 smileyTarget.value += ' ' + this.alt + ' ';
bgneal@312 96 smileyTarget.focus();
bgneal@312 97 });
bgneal@312 98 firstTimeSmiley = false;
bgneal@312 99 },
bgneal@312 100 error: function (xhr, textStatus, ex) {
bgneal@312 101 alert('Oops, an error occurred: ' + xhr.statusText + ' - ' + xhr.responseText);
bgneal@312 102 }
bgneal@312 103 });
bgneal@312 104 }
bgneal@312 105 return false;
bgneal@312 106 });
bgneal@312 107 $('#markdown_help_dialog_popup').dialog({autoOpen: false, width: 720, height: 600});
bgneal@312 108 var firstTimeMdHelp = true;
bgneal@312 109 $('#markdown_help_link').click(function () {
bgneal@312 110 $('#markdown_help_dialog_popup').dialog('open');
bgneal@312 111 if (firstTimeMdHelp) {
bgneal@312 112 $.ajax({
bgneal@312 113 url: '/core/markdown_help/',
bgneal@312 114 type: 'GET',
bgneal@312 115 dataType: 'html',
bgneal@312 116 success: function(data, textStatus) {
bgneal@312 117 var img = $('#markdown_busy');
bgneal@312 118 img.hide();
bgneal@312 119 img.after(data);
bgneal@312 120 firstTimeMdHelp = false;
bgneal@312 121 },
bgneal@312 122 error: function (xhr, textStatus, ex) {
bgneal@312 123 alert('Oops, an error occurred: ' + xhr.statusText + ' - ' + xhr.responseText);
bgneal@312 124 }
bgneal@312 125 });
bgneal@312 126 }
bgneal@312 127 return false;
bgneal@312 128 });
bgneal@722 129
bgneal@722 130 var $photoProgress = $('#photo-upload-progress');
bgneal@725 131 if ($photoProgress.length) {
bgneal@725 132 var $photoForm = $('#photo-upload-form');
bgneal@725 133 var $postBox = $('#id_body');
bgneal@725 134 var $photoUploadSubmit = $('#photo-upload-submit');
bgneal@722 135
bgneal@725 136 $photoForm.ajaxForm({
bgneal@725 137 beforeSubmit: function(arr, $form, options) {
bgneal@725 138 var fileObj = null;
bgneal@725 139 $.each(arr, function(index, val) {
bgneal@725 140 if (val.name == 'image_file') {
bgneal@725 141 fileObj = val.value;
bgneal@725 142 }
bgneal@725 143 });
bgneal@725 144 if (!fileObj) {
bgneal@725 145 alert("Please choose a file to upload.");
bgneal@725 146 return false;
bgneal@722 147 }
bgneal@725 148 $photoUploadSubmit.attr('disabled', 'disabled').val('Uploading...');
bgneal@725 149 return true;
bgneal@725 150 },
bgneal@725 151 beforeSend: function() {
bgneal@725 152 $photoProgress.progressbar({value: 0});
bgneal@725 153 },
bgneal@725 154 uploadProgress: function(event, position, total, percentComplete) {
bgneal@725 155 if (percentComplete < 100) {
bgneal@725 156 $photoProgress.progressbar({value: percentComplete});
bgneal@725 157 }
bgneal@725 158 else {
bgneal@725 159 $photoProgress.progressbar({value: false});
bgneal@725 160 }
bgneal@725 161 },
bgneal@725 162 success: function(resp, statusText, xhr, $form) {
bgneal@725 163 $photoProgress.progressbar({value: 100});
bgneal@725 164 if (resp.success) {
bgneal@725 165 $postBox.val($postBox.val() + '\n![image](' + resp.url + ')');
bgneal@725 166 alert("Success! The image code was added to your post.");
bgneal@725 167 }
bgneal@725 168 else {
bgneal@725 169 alert('Error: ' + resp.msg);
bgneal@725 170 }
bgneal@725 171 },
bgneal@725 172 complete: function(xhr) {
bgneal@725 173 $photoProgress.progressbar({value: 0});
bgneal@725 174 $photoForm.clearForm();
bgneal@725 175 $photoUploadSubmit.removeAttr('disabled').val('Upload photo');
bgneal@725 176 },
bgneal@725 177 error: function(xhr, textStatus, ex) {
bgneal@725 178 alert('Oops, there was an error: ' + ex);
bgneal@722 179 }
bgneal@725 180 });
bgneal@725 181 }
bgneal@312 182 });