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:
parent
273e2172cb
commit
0786ec5862
4 changed files with 43 additions and 1 deletions
17
core/client/assets/lib/jquery-utils.js
vendored
17
core/client/assets/lib/jquery-utils.js
vendored
|
@ -37,4 +37,21 @@
|
||||||
return this;
|
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);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
}());
|
}());
|
|
@ -52,7 +52,8 @@
|
||||||
case "copyHTML":
|
case "copyHTML":
|
||||||
converter = new Showdown.converter();
|
converter = new Showdown.converter();
|
||||||
md = converter.makeHtml(text);
|
md = converter.makeHtml(text);
|
||||||
window.prompt("Copy to clipboard: Ctrl+C, Enter", md);
|
$(".modal-copyToHTML-content").text(md).selectText();
|
||||||
|
$(".js-modal").center();
|
||||||
pass = false;
|
pass = false;
|
||||||
break;
|
break;
|
||||||
case "list":
|
case "list":
|
||||||
|
|
4
core/client/tpl/modals/copyToHTML.hbs
Normal file
4
core/client/tpl/modals/copyToHTML.hbs
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
Press Ctrl / Cmd + C to copy the following HTML.
|
||||||
|
<pre>
|
||||||
|
<code class="modal-copyToHTML-content"></code>
|
||||||
|
</pre>
|
|
@ -318,6 +318,14 @@
|
||||||
|
|
||||||
var view = this;
|
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) {
|
_.each(MarkdownShortcuts, function (combo) {
|
||||||
shortcut.add(combo.key, function () {
|
shortcut.add(combo.key, function () {
|
||||||
return view.editor.addMarkdown({style: combo.style});
|
return view.editor.addMarkdown({style: combo.style});
|
||||||
|
@ -327,6 +335,18 @@
|
||||||
this.editor.on('change', function () {
|
this.editor.on('change', function () {
|
||||||
view.renderPreview();
|
view.renderPreview();
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
showHTML: function () {
|
||||||
|
this.addSubview(new Ghost.Views.Modal({
|
||||||
|
model: {
|
||||||
|
title: 'Copied HTML',
|
||||||
|
content: {
|
||||||
|
template: 'copyToHTML'
|
||||||
|
},
|
||||||
|
animation: 'fadeIn'
|
||||||
|
}
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue