view static/js/markitup/sets/markdown/set.js @ 861:e4f8d87c3d30

Configure Markdown logger to reduce noise in logs. Markdown is logging at the INFO level whenever it loads an extension. This looks like it has been fixed in master at GitHub. But until then we will explicitly configure the MARKDOWN logger to log at WARNING or higher.
author Brian Neal <bgneal@gmail.com>
date Mon, 01 Dec 2014 18:36:27 -0600
parents 682b159f3763
children 4f265f61874b
line wrap: on
line source
// -------------------------------------------------------------------
// markItUp!
// -------------------------------------------------------------------
// Copyright (C) 2008 Jay Salvat
// http://markitup.jaysalvat.com/
// -------------------------------------------------------------------
// MarkDown tags example
// http://en.wikipedia.org/wiki/Markdown
// http://daringfireball.net/projects/markdown/
// -------------------------------------------------------------------
// Feel free to add more tags
// -------------------------------------------------------------------
// Modified by Brian Neal for SurfGuitar101
mySettings = {
	previewParserPath: '/comments/markdown/',
	previewParserVar: 'data',
    previewInWindow: false,
    previewAutoRefresh: false,
    previewPosition: 'after',
	onShiftEnter:		{keepDefault:false, openWith:'\n\n'},
	markupSet: [
		{name:'Bold', key:'B', openWith:'**', closeWith:'**'},
		{name:'Italic', key:'I', openWith:'_', closeWith:'_'},
		{name:'Strike', key:'S', openWith:'---', closeWith:'---'},
		{separator:'---------------' },
		{name:'Bulleted List', openWith:'- ', multiline:true},
		{name:'Numeric List', openWith:function(markItUp) {
			return markItUp.line+'. ';
		}, multiline:true},
		{separator:'---------------' },
		{name:'Picture', key:'P', replaceWith:'![image]([![Url:!:http://]!])'},
		{name:'Link', key:'L', openWith:'[', closeWith:']([![Url:!:http://]!])', placeHolder:'Your text to link here...' },
		{separator:'---------------'},
		{name:'Quotes', openWith:'> ', multiline:true},
		{name:'Code Block / Code', openWith:'(!(\t|!|`)!)', closeWith:'(!(`)!)', multiline:true},
		{separator:'---------------'},
        {name:'Smilies', className:'smilies', dropMenu: [
            {name:'Argh', replaceWith:' :argh: ', className:'col1-1' },
            {name:'Grin', replaceWith:' :-D ', className:'col1-2' },
            {name:'Razz', replaceWith:' :-P ', className:'col1-3' },
            {name:'Confused', replaceWith:' o_O ', className:'col1-4' },
            {name:'Cool', replaceWith:' 8^) ', className:'col1-5' },
            {name:'Cry', replaceWith:' :-( ', className:'col2-1' },
            {name:'Dead', replaceWith:' x_x ', className:'col2-2' },
            {name:'Embarrassed', replaceWith:' :-# ', className:'col2-3' },
            {name:'LOL', replaceWith:' :lol: ', className:'col2-4' },
            {name:'Mad', replaceWith:' X-( ', className:'col2-5' },
            {name:'No', replaceWith:' :no: ', className:'col3-1' },
            {name:'None', replaceWith:' :-| ', className:'col3-2' },
            {name:'Shock', replaceWith:' :shock: ', className:'col3-3' },
            {name:'Sigh', replaceWith:' :sigh: ', className:'col3-4' },
            {name:'Smile', replaceWith:' :-) ', className:'col3-5' },
            {name:'Uh-oh', replaceWith:' :uh-oh: ', className:'col4-1' },
            {name:'Whatever', replaceWith:' :whatever: ', className:'col4-2' },
            {name:'Wink', replaceWith:' ;-) ', className:'col4-3' },
            {name:'Yes', replaceWith:' :yes: ', className:'col4-4' },
            {name:'Sleep', replaceWith:' :sleep: ', className:'col4-5' }
            ]
        },
		{separator:'---------------'},
		{name:'Preview', call:'preview', className:"preview"}
	]
}

// mIu nameSpace to avoid conflict.
miu = {
	markdownTitle: function(markItUp, char) {
		heading = '';
		n = $.trim(markItUp.selection||markItUp.placeHolder).length;
		for(i = 0; i < n; i++) {
			heading += char;
		}
		return '\n'+heading;
	}
}

$(document).ready(function() {
   $('.markItUp').markItUp(mySettings);

   $('#smileys_dialog_popup').dialog({autoOpen:false});
   var firstTimeSmiley = true;
   $('#more_smileys_link').click(function () {
       $('#smileys_dialog_popup').dialog('open');
       var smileyTarget = $('.smileyTarget')[0];
       if (firstTimeSmiley) {
         $.ajax({
            url: '/smiley/farm/extra/',
            type: 'GET',
            dataType: 'html',
            success: function(data, textStatus) {
               var img = $('#smiley_busy');
               img.hide();
               img.after(data);
               $('#smileys_dialog_popup .smiley_farm img').click(function() {
                  smileyTarget.value += ' ' + this.alt + ' ';
                  smileyTarget.focus();
               });
               firstTimeSmiley = false;
            },
            error: function (xhr, textStatus, ex) {
               alert('Oops, an error occurred: ' + xhr.statusText + ' - ' + xhr.responseText);
            }
         });
       }
       return false;
   });
   $('#markdown_help_dialog_popup').dialog({autoOpen: false, width: 720, height: 600});
   var firstTimeMdHelp = true;
   $('#markdown_help_link').click(function () {
       $('#markdown_help_dialog_popup').dialog('open');
       if (firstTimeMdHelp) {
         $.ajax({
            url: '/core/markdown_help/',
            type: 'GET',
            dataType: 'html',
            success: function(data, textStatus) {
               var img = $('#markdown_busy');
               img.hide();
               img.after(data);
               firstTimeMdHelp = false;
            },
            error: function (xhr, textStatus, ex) {
               alert('Oops, an error occurred: ' + xhr.statusText + ' - ' + xhr.responseText);
            }
         });
       }
       return false;
   });

   var $photoProgress = $('#photo-upload-progress');
   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;
               }
            });
            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);
         }
      });
   }
});