diff --git a/core/admin/assets/js/editor.js b/core/admin/assets/js/editor.js index 8b101c5c99..cbcd359aad 100644 --- a/core/admin/assets/js/editor.js +++ b/core/admin/assets/js/editor.js @@ -149,10 +149,83 @@ } }); + // ## Shortcuts // Zen writing mode shortcut.add("Alt+Shift+Z", function () { $('body').toggleClass('zen'); }); + var MarkdownShortcuts = [ + { + 'key': 'Ctrl+B', + 'style': 'bold' + }, + { + 'key': 'Meta+B', + 'style': 'bold' + }, + { + 'key': 'Ctrl+I', + 'style': 'italic' + }, + { + 'key': 'Meta+I', + 'style': 'italic' + }, + { + 'key': 'Ctrl+Alt+U', + 'style': 'strike' + }, + { + 'key': 'Ctrl+Shift+K', + 'style': 'code' + }, + { + 'key': 'Alt+1', + 'style': 'h1' + }, + { + 'key': 'Alt+2', + 'style': 'h2' + }, + { + 'key': 'Alt+3', + 'style': 'h3' + }, + { + 'key': 'Alt+4', + 'style': 'h4' + }, + { + 'key': 'Alt+5', + 'style': 'h5' + }, + { + 'key': 'Alt+6', + 'style': 'h6' + }, + { + 'key': 'Ctrl+Shift+L', + 'style': 'link' + }, + { + 'key': 'Ctrl+Shift+I', + 'style': 'image' + }, + { + 'key': 'Ctrl+Q', + 'style': 'blockquote' + }, + { + 'key': 'Ctrl+Shift+1', + 'style': 'currentdate' + } + ]; + + $.each(MarkdownShortcuts, function (index, short) { + shortcut.add(short.key, function () { + return editor.addMarkdown({style: short.style}); + }); + }); }); }(jQuery, Showdown, CodeMirror, shortcut)); \ No newline at end of file diff --git a/core/admin/assets/js/markdown-actions.js b/core/admin/assets/js/markdown-actions.js new file mode 100644 index 0000000000..15f059d849 --- /dev/null +++ b/core/admin/assets/js/markdown-actions.js @@ -0,0 +1,53 @@ +/*global console, jQuery, CodeMirror*/ + +// # Surrounds given text with Markdown syntax +(function ($) { + "use strict"; + var Markdown = { + init : function (options, elem) { + var self = this; + self.elem = elem; + + self.style = (typeof options === 'string') ? options : options.style; + + self.options = $.extend({}, CodeMirror.prototype.addMarkdown.options, options); + + self.replace(); + }, + replace: function () { + var text = this.elem.getSelection(), md; + if (this.options.syntax[this.style]) { + md = this.options.syntax[this.style].replace('$1', text); + this.elem.replaceSelection(md); + } else { + console.log("Invalid style."); + } + + } + }; + + CodeMirror.prototype.addMarkdown = function (options) { + var markdown = Object.create(Markdown); + markdown.init(options, this); + }; + + CodeMirror.prototype.addMarkdown.options = { + style: null, + syntax: { + bold: "**$1**", + italic: "_$1_", + strike: "~~$1~~", + code: "`$1`", + h1: "\n# $1\n", + h2: "\n## $1\n", + h3: "\n### $1\n", + h4: "\n#### $1\n", + h5: "\n##### $1\n", + h6: "\n###### $1\n", + link: "[$1](http://)", + image: "!image[$1](http://)", + blockquote: "> $1", + currentDate: new Date().toLocaleString() + } + }; +}(jQuery)); \ No newline at end of file diff --git a/core/admin/views/editor.hbs b/core/admin/views/editor.hbs index 0b972c6b01..ba5efc8884 100644 --- a/core/admin/views/editor.hbs +++ b/core/admin/views/editor.hbs @@ -4,6 +4,7 @@ + {{/contentFor}}