bgneal@312: // ------------------------------------------------------------------- bgneal@312: // markItUp! bgneal@312: // ------------------------------------------------------------------- bgneal@312: // Copyright (C) 2008 Jay Salvat bgneal@312: // http://markitup.jaysalvat.com/ bgneal@312: // ------------------------------------------------------------------- bgneal@312: // MarkDown tags example bgneal@312: // http://en.wikipedia.org/wiki/Markdown bgneal@312: // http://daringfireball.net/projects/markdown/ bgneal@312: // ------------------------------------------------------------------- bgneal@312: // Feel free to add more tags bgneal@312: // ------------------------------------------------------------------- bgneal@693: // Modified by Brian Neal for SurfGuitar101 bgneal@312: mySettings = { bgneal@312: previewParserPath: '/comments/markdown/', bgneal@312: previewParserVar: 'data', bgneal@312: previewInWindow: false, bgneal@312: previewAutoRefresh: false, bgneal@312: previewPosition: 'after', bgneal@312: onShiftEnter: {keepDefault:false, openWith:'\n\n'}, bgneal@312: markupSet: [ bgneal@312: {name:'Bold', key:'B', openWith:'**', closeWith:'**'}, bgneal@312: {name:'Italic', key:'I', openWith:'_', closeWith:'_'}, bgneal@360: {name:'Strike', key:'S', openWith:'---', closeWith:'---'}, bgneal@312: {separator:'---------------' }, bgneal@693: {name:'Bulleted List', openWith:'- ', multiline:true}, bgneal@312: {name:'Numeric List', openWith:function(markItUp) { bgneal@312: return markItUp.line+'. '; bgneal@693: }, multiline:true}, bgneal@312: {separator:'---------------' }, bgneal@312: {name:'Picture', key:'P', replaceWith:'![image]([![Url:!:http://]!])'}, bgneal@312: {name:'Link', key:'L', openWith:'[', closeWith:']([![Url:!:http://]!])', placeHolder:'Your text to link here...' }, bgneal@693: {separator:'---------------'}, bgneal@693: {name:'Quotes', openWith:'> ', multiline:true}, bgneal@693: {name:'Code Block / Code', openWith:'(!(\t|!|`)!)', closeWith:'(!(`)!)', multiline:true}, bgneal@312: {separator:'---------------'}, bgneal@312: {name:'Smilies', className:'smilies', dropMenu: [ bgneal@312: {name:'Argh', replaceWith:' :argh: ', className:'col1-1' }, bgneal@312: {name:'Grin', replaceWith:' :-D ', className:'col1-2' }, bgneal@312: {name:'Razz', replaceWith:' :-P ', className:'col1-3' }, bgneal@312: {name:'Confused', replaceWith:' o_O ', className:'col1-4' }, bgneal@312: {name:'Cool', replaceWith:' 8^) ', className:'col1-5' }, bgneal@312: {name:'Cry', replaceWith:' :-( ', className:'col2-1' }, bgneal@312: {name:'Dead', replaceWith:' x_x ', className:'col2-2' }, bgneal@312: {name:'Embarrassed', replaceWith:' :-# ', className:'col2-3' }, bgneal@312: {name:'LOL', replaceWith:' :lol: ', className:'col2-4' }, bgneal@312: {name:'Mad', replaceWith:' X-( ', className:'col2-5' }, bgneal@312: {name:'No', replaceWith:' :no: ', className:'col3-1' }, bgneal@312: {name:'None', replaceWith:' :-| ', className:'col3-2' }, bgneal@312: {name:'Shock', replaceWith:' :shock: ', className:'col3-3' }, bgneal@312: {name:'Sigh', replaceWith:' :sigh: ', className:'col3-4' }, bgneal@312: {name:'Smile', replaceWith:' :-) ', className:'col3-5' }, bgneal@312: {name:'Uh-oh', replaceWith:' :uh-oh: ', className:'col4-1' }, bgneal@312: {name:'Whatever', replaceWith:' :whatever: ', className:'col4-2' }, bgneal@312: {name:'Wink', replaceWith:' ;-) ', className:'col4-3' }, bgneal@312: {name:'Yes', replaceWith:' :yes: ', className:'col4-4' }, bgneal@312: {name:'Sleep', replaceWith:' :sleep: ', className:'col4-5' } bgneal@312: ] bgneal@312: }, bgneal@312: {separator:'---------------'}, bgneal@312: {name:'Preview', call:'preview', className:"preview"} bgneal@312: ] bgneal@312: } bgneal@312: bgneal@312: // mIu nameSpace to avoid conflict. bgneal@312: miu = { bgneal@312: markdownTitle: function(markItUp, char) { bgneal@312: heading = ''; bgneal@312: n = $.trim(markItUp.selection||markItUp.placeHolder).length; bgneal@312: for(i = 0; i < n; i++) { bgneal@312: heading += char; bgneal@312: } bgneal@312: return '\n'+heading; bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: $(document).ready(function() { bgneal@312: $('.markItUp').markItUp(mySettings); bgneal@312: bgneal@312: $('#smileys_dialog_popup').dialog({autoOpen:false}); bgneal@312: var firstTimeSmiley = true; bgneal@312: $('#more_smileys_link').click(function () { bgneal@312: $('#smileys_dialog_popup').dialog('open'); bgneal@312: var smileyTarget = $('.smileyTarget')[0]; bgneal@312: if (firstTimeSmiley) { bgneal@312: $.ajax({ bgneal@312: url: '/smiley/farm/extra/', bgneal@312: type: 'GET', bgneal@312: dataType: 'html', bgneal@312: success: function(data, textStatus) { bgneal@312: var img = $('#smiley_busy'); bgneal@312: img.hide(); bgneal@312: img.after(data); bgneal@312: $('#smileys_dialog_popup .smiley_farm img').click(function() { bgneal@312: smileyTarget.value += ' ' + this.alt + ' '; bgneal@312: smileyTarget.focus(); bgneal@312: }); bgneal@312: firstTimeSmiley = false; bgneal@312: }, bgneal@312: error: function (xhr, textStatus, ex) { bgneal@312: alert('Oops, an error occurred: ' + xhr.statusText + ' - ' + xhr.responseText); bgneal@312: } bgneal@312: }); bgneal@312: } bgneal@312: return false; bgneal@312: }); bgneal@312: $('#markdown_help_dialog_popup').dialog({autoOpen: false, width: 720, height: 600}); bgneal@312: var firstTimeMdHelp = true; bgneal@312: $('#markdown_help_link').click(function () { bgneal@312: $('#markdown_help_dialog_popup').dialog('open'); bgneal@312: if (firstTimeMdHelp) { bgneal@312: $.ajax({ bgneal@312: url: '/core/markdown_help/', bgneal@312: type: 'GET', bgneal@312: dataType: 'html', bgneal@312: success: function(data, textStatus) { bgneal@312: var img = $('#markdown_busy'); bgneal@312: img.hide(); bgneal@312: img.after(data); bgneal@312: firstTimeMdHelp = false; bgneal@312: }, bgneal@312: error: function (xhr, textStatus, ex) { bgneal@312: alert('Oops, an error occurred: ' + xhr.statusText + ' - ' + xhr.responseText); bgneal@312: } bgneal@312: }); bgneal@312: } bgneal@312: return false; bgneal@312: }); bgneal@722: bgneal@722: var $photoProgress = $('#photo-upload-progress'); bgneal@722: var $photoForm = $('#photo-upload-form'); bgneal@722: var $postBox = $('#id_body'); bgneal@722: var $photoUploadSubmit = $('#photo-upload-submit'); bgneal@722: bgneal@722: $photoForm.ajaxForm({ bgneal@722: beforeSubmit: function(arr, $form, options) { bgneal@722: var fileObj = null; bgneal@722: $.each(arr, function(index, val) { bgneal@722: if (val.name == 'image_file') { bgneal@722: fileObj = val.value; bgneal@722: } bgneal@722: }); bgneal@722: if (!fileObj) { bgneal@722: alert("Please choose a file to upload."); bgneal@722: return false; bgneal@722: } bgneal@722: $photoUploadSubmit.attr('disabled', 'disabled').val('Uploading...'); bgneal@722: return true; bgneal@722: }, bgneal@722: beforeSend: function() { bgneal@722: $photoProgress.progressbar({value: 0}); bgneal@722: }, bgneal@722: uploadProgress: function(event, position, total, percentComplete) { bgneal@722: if (percentComplete < 100) { bgneal@722: $photoProgress.progressbar({value: percentComplete}); bgneal@722: } bgneal@722: else { bgneal@722: $photoProgress.progressbar({value: false}); bgneal@722: } bgneal@722: }, bgneal@722: success: function(resp, statusText, xhr, $form) { bgneal@722: $photoProgress.progressbar({value: 100}); bgneal@722: if (resp.success) { bgneal@722: $postBox.val($postBox.val() + '\n![image](' + resp.url + ')'); bgneal@722: alert("Success! The image code was added to your post."); bgneal@722: } bgneal@722: else { bgneal@722: alert('Error: ' + resp.msg); bgneal@722: } bgneal@722: }, bgneal@722: complete: function(xhr) { bgneal@722: $photoProgress.progressbar({value: 0}); bgneal@722: $photoForm.clearForm(); bgneal@722: $photoUploadSubmit.removeAttr('disabled').val('Upload photo'); bgneal@722: }, bgneal@722: error: function(xhr, textStatus, ex) { bgneal@722: alert('Oops, there was an error: ' + ex); bgneal@722: } bgneal@722: }); bgneal@312: });