summaryrefslogtreecommitdiffstats
path: root/public
diff options
context:
space:
mode:
authorGo MAEDA <maeda@farend.jp>2021-01-07 05:39:36 +0000
committerGo MAEDA <maeda@farend.jp>2021-01-07 05:39:36 +0000
commit81efbcaa2f592234ffa22a289f650a3aeb288e3c (patch)
treebed3749f53ee276db5d75a291a22f64643b9920b /public
parentbba8bb223865deb042941c79e38430968a1b915a (diff)
downloadredmine-81efbcaa2f592234ffa22a289f650a3aeb288e3c.tar.gz
redmine-81efbcaa2f592234ffa22a289f650a3aeb288e3c.zip
Add keyboard shortcut to toggle between Edit/Preview tabs (#30459).
Patch by Marius BALTEANU. git-svn-id: http://svn.redmine.org/redmine/trunk@20706 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'public')
-rw-r--r--public/javascripts/jstoolbar/jstoolbar.js35
1 files changed, 34 insertions, 1 deletions
diff --git a/public/javascripts/jstoolbar/jstoolbar.js b/public/javascripts/jstoolbar/jstoolbar.js
index 376698f9a..de4eb997a 100644
--- a/public/javascripts/jstoolbar/jstoolbar.js
+++ b/public/javascripts/jstoolbar/jstoolbar.js
@@ -21,6 +21,7 @@
*/
/* Modified by JP LANG for textile formatting */
+let lastJstPreviewed = null;
function jsToolBar(textarea) {
if (!document.createElement) { return; }
@@ -53,6 +54,8 @@ function jsToolBar(textarea) {
var This = this;
+ this.textarea.onkeydown = function(event) { This.keyboardShortcuts.call(This, event); };
+
this.editTab = new jsTab('Edit', true);
this.editTab.onclick = function(event) { This.hidePreview.call(This, event); return false; };
@@ -401,22 +404,33 @@ jsToolBar.prototype = {
},
showPreview: function(event) {
if (event.target.classList.contains('selected')) { return; }
+ lastJstPreviewed = this.toolbarBlock;
this.preview.setAttribute('style', 'min-height: ' + this.textarea.clientHeight + 'px;')
this.toolbar.classList.add('hidden');
this.textarea.classList.add('hidden');
this.preview.classList.remove('hidden');
this.tabsBlock.getElementsByClassName('tab-edit')[0].classList.remove('selected');
event.target.classList.add('selected');
-
},
hidePreview: function(event) {
if (event.target.classList.contains('selected')) { return; }
this.toolbar.classList.remove('hidden');
this.textarea.classList.remove('hidden');
+ this.textarea.focus();
this.preview.classList.add('hidden');
this.tabsBlock.getElementsByClassName('tab-preview')[0].classList.remove('selected');
event.target.classList.add('selected');
},
+ keyboardShortcuts: function(e) {
+ if (isToogleEditPreviewShortcut(e)) {
+ // Switch to preview only if tab edit is selected when the event triggered.
+ if (this.tabsBlock.querySelector('.tab-edit.selected')) {
+ e.stopPropagation();
+ e.preventDefault();
+ this.tabsBlock.getElementsByClassName('tab-preview')[0].click();
+ }
+ }
+ },
stripBaseURL: function(url) {
if (this.base_url != '') {
var pos = url.indexOf(this.base_url);
@@ -507,3 +521,22 @@ jsToolBar.prototype.tableMenu = function(fn){
});
return false;
};
+
+$(document).keydown(function(e) {
+ if (isToogleEditPreviewShortcut(e)) {
+ if (lastJstPreviewed !== null) {
+ e.preventDefault();
+ e.stopPropagation();
+ lastJstPreviewed.querySelector('.tab-edit').click();
+ lastJstPreviewed = null;
+ }
+ }
+});
+
+function isToogleEditPreviewShortcut(e) {
+ if ((e.metaKey || e.ctrlKey) && e.shiftKey && e.key.toLowerCase() === 'p') {
+ return true;
+ } else {
+ return false;
+ }
+} \ No newline at end of file