From 0786ec5862c79674ae77fcc6db48fed7fd79a90a Mon Sep 17 00:00:00 2001 From: Matthew Harrison-Jones Date: Thu, 25 Jul 2013 16:00:41 +0100 Subject: [PATCH] First pass at creating a usuable modal for the copy to HTML keyboard shortcut. Has an issue where Google Chrome does not persist to keep code selected. --- core/client/assets/lib/jquery-utils.js | 17 +++++++++++++++++ core/client/markdown-actions.js | 3 ++- core/client/tpl/modals/copyToHTML.hbs | 4 ++++ core/client/views/editor.js | 20 ++++++++++++++++++++ 4 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 core/client/tpl/modals/copyToHTML.hbs diff --git a/core/client/assets/lib/jquery-utils.js b/core/client/assets/lib/jquery-utils.js index 2ef35def0d..f82e4c3054 100644 --- a/core/client/assets/lib/jquery-utils.js +++ b/core/client/assets/lib/jquery-utils.js @@ -37,4 +37,21 @@ return this; }; + $.fn.selectText = function () { + var elem = this[0], + range, + selection; + if (document.body.createTextRange) { + range = document.body.createTextRange(); + range.moveToElementText(elem); + range.select(); + } else if (window.getSelection) { + selection = window.getSelection(); + range = document.createRange(); + range.selectNodeContents(elem); + selection.removeAllRanges(); + selection.addRange(range); + } + }; + }()); \ No newline at end of file diff --git a/core/client/markdown-actions.js b/core/client/markdown-actions.js index bf14ab3447..d87c3a4af2 100644 --- a/core/client/markdown-actions.js +++ b/core/client/markdown-actions.js @@ -52,7 +52,8 @@ case "copyHTML": converter = new Showdown.converter(); md = converter.makeHtml(text); - window.prompt("Copy to clipboard: Ctrl+C, Enter", md); + $(".modal-copyToHTML-content").text(md).selectText(); + $(".js-modal").center(); pass = false; break; case "list": diff --git a/core/client/tpl/modals/copyToHTML.hbs b/core/client/tpl/modals/copyToHTML.hbs new file mode 100644 index 0000000000..fc08540921 --- /dev/null +++ b/core/client/tpl/modals/copyToHTML.hbs @@ -0,0 +1,4 @@ +Press Ctrl / Cmd + C to copy the following HTML. +
+
+
\ No newline at end of file diff --git a/core/client/views/editor.js b/core/client/views/editor.js index 283cc70937..4ea83b3518 100644 --- a/core/client/views/editor.js +++ b/core/client/views/editor.js @@ -318,6 +318,14 @@ var view = this; + // Inject modal for HTML to be viewed in + shortcut.add("Ctrl+Alt+C", function () { + view.showHTML(); + }); + shortcut.add("Ctrl+Alt+C", function () { + view.showHTML(); + }); + _.each(MarkdownShortcuts, function (combo) { shortcut.add(combo.key, function () { return view.editor.addMarkdown({style: combo.style}); @@ -327,6 +335,18 @@ this.editor.on('change', function () { view.renderPreview(); }); + }, + + showHTML: function () { + this.addSubview(new Ghost.Views.Modal({ + model: { + title: 'Copied HTML', + content: { + template: 'copyToHTML' + }, + animation: 'fadeIn' + } + })); } });