mirror of
https://github.com/redmine/redmine.git
synced 2025-11-14 17:26:06 +01:00
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
This commit is contained in:
@@ -21,6 +21,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* Modified by JP LANG for textile formatting */
|
/* Modified by JP LANG for textile formatting */
|
||||||
|
let lastJstPreviewed = null;
|
||||||
|
|
||||||
function jsToolBar(textarea) {
|
function jsToolBar(textarea) {
|
||||||
if (!document.createElement) { return; }
|
if (!document.createElement) { return; }
|
||||||
@@ -53,6 +54,8 @@ function jsToolBar(textarea) {
|
|||||||
|
|
||||||
var This = this;
|
var This = this;
|
||||||
|
|
||||||
|
this.textarea.onkeydown = function(event) { This.keyboardShortcuts.call(This, event); };
|
||||||
|
|
||||||
this.editTab = new jsTab('Edit', true);
|
this.editTab = new jsTab('Edit', true);
|
||||||
this.editTab.onclick = function(event) { This.hidePreview.call(This, event); return false; };
|
this.editTab.onclick = function(event) { This.hidePreview.call(This, event); return false; };
|
||||||
|
|
||||||
@@ -401,22 +404,33 @@ jsToolBar.prototype = {
|
|||||||
},
|
},
|
||||||
showPreview: function(event) {
|
showPreview: function(event) {
|
||||||
if (event.target.classList.contains('selected')) { return; }
|
if (event.target.classList.contains('selected')) { return; }
|
||||||
|
lastJstPreviewed = this.toolbarBlock;
|
||||||
this.preview.setAttribute('style', 'min-height: ' + this.textarea.clientHeight + 'px;')
|
this.preview.setAttribute('style', 'min-height: ' + this.textarea.clientHeight + 'px;')
|
||||||
this.toolbar.classList.add('hidden');
|
this.toolbar.classList.add('hidden');
|
||||||
this.textarea.classList.add('hidden');
|
this.textarea.classList.add('hidden');
|
||||||
this.preview.classList.remove('hidden');
|
this.preview.classList.remove('hidden');
|
||||||
this.tabsBlock.getElementsByClassName('tab-edit')[0].classList.remove('selected');
|
this.tabsBlock.getElementsByClassName('tab-edit')[0].classList.remove('selected');
|
||||||
event.target.classList.add('selected');
|
event.target.classList.add('selected');
|
||||||
|
|
||||||
},
|
},
|
||||||
hidePreview: function(event) {
|
hidePreview: function(event) {
|
||||||
if (event.target.classList.contains('selected')) { return; }
|
if (event.target.classList.contains('selected')) { return; }
|
||||||
this.toolbar.classList.remove('hidden');
|
this.toolbar.classList.remove('hidden');
|
||||||
this.textarea.classList.remove('hidden');
|
this.textarea.classList.remove('hidden');
|
||||||
|
this.textarea.focus();
|
||||||
this.preview.classList.add('hidden');
|
this.preview.classList.add('hidden');
|
||||||
this.tabsBlock.getElementsByClassName('tab-preview')[0].classList.remove('selected');
|
this.tabsBlock.getElementsByClassName('tab-preview')[0].classList.remove('selected');
|
||||||
event.target.classList.add('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) {
|
stripBaseURL: function(url) {
|
||||||
if (this.base_url != '') {
|
if (this.base_url != '') {
|
||||||
var pos = url.indexOf(this.base_url);
|
var pos = url.indexOf(this.base_url);
|
||||||
@@ -507,3 +521,22 @@ jsToolBar.prototype.tableMenu = function(fn){
|
|||||||
});
|
});
|
||||||
return false;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user