0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

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.
This commit is contained in:
Matthew Harrison-Jones 2013-07-25 16:00:41 +01:00
parent 273e2172cb
commit 0786ec5862
4 changed files with 43 additions and 1 deletions

View file

@ -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);
}
};
}());

View file

@ -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":

View file

@ -0,0 +1,4 @@
Press Ctrl / Cmd + C to copy the following HTML.
<pre>
<code class="modal-copyToHTML-content"></code>
</pre>

View file

@ -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'
}
}));
}
});