From 41d7cf75c5ea1b29a69ef74b61e8b4fba145e5dd Mon Sep 17 00:00:00 2001 From: Dawa Ometto Date: Sat, 14 Sep 2019 19:02:40 +0200 Subject: [PATCH] Preview hotkeys also for create view (#1426) --- .../public/gollum/javascript/gollum.js.erb | 49 ++++++++++--------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/lib/gollum/public/gollum/javascript/gollum.js.erb b/lib/gollum/public/gollum/javascript/gollum.js.erb index f78c6e58..918b51fa 100755 --- a/lib/gollum/public/gollum/javascript/gollum.js.erb +++ b/lib/gollum/public/gollum/javascript/gollum.js.erb @@ -363,35 +363,40 @@ $(document).ready(function() { }); }; + var previewHotkey = function () { + $('.tabnav-tab').not('.selected').click(); + return false; + }; + + var editorHotkeys = [ + { + name: "saveContents", + bindKey: {win: "Ctrl-s", mac: "Command-s"}, + exec: function() { + $("#gollum-editor-submit").trigger("click"); + } + }, + { + name: "togglePreview", // Ace's hotkeys override Mousetrap, so add the preview hotkey to the editor, too. + bindKey: {win: "ctrl-shift-p", mac: "ctrl-shift-p"}, + exec: previewHotkey + } + ]; + + if ( $('#wiki-wrapper.edit').length || $('#wiki-wrapper.create').length ) { + // Hotkey for moving between Edit and Preview tab + Mousetrap.bind(['ctrl+shift+p'], previewHotkey); + } + if( $('#wiki-wrapper.edit').length ){ $("#gollum-editor-submit").click( function() { window.onbeforeunload = null; } ); $("#gollum-editor-body").one('change', function(){ window.onbeforeunload = function(){ return "Leaving will discard all edits!" }; }); - var previewHotkey = function () { - $('.tabnav-tab').not('.selected').click(); - return false; - }; - - // Hotkey for moving between Edit and Preview tab - Mousetrap.bind(['ctrl+shift+p'], previewHotkey); - $.GollumEditor({ section: window.location.hash.substr(1), - commands: // Ace's keybindings overrule mousetrap, so add some of gollum's keyboard shortcuts to the editor, as well. - [{ - name: "togglePreview", - bindKey: {win: "ctrl-shift-p", mac: "ctrl-shift-p"}, - exec: previewHotkey - }, - { - name: "saveContents", - bindKey: {win: "Ctrl-s", mac: "Command-s"}, - exec: function() { - $("#gollum-editor-submit").trigger("click"); - } - }] + commands: editorHotkeys // Ace's keybindings overrule mousetrap, so add some of gollum's keyboard shortcuts to the editor, as well. }); $("#gollum-editor-submit").click( function(e) { @@ -537,7 +542,7 @@ $(document).ready(function() { $("#gollum-editor-body").one('change', function(){ window.onbeforeunload = function(){ return "Leaving will not create a new page!" }; }); - $.GollumEditor({ NewFile: true, MarkupType: default_markup }); + $.GollumEditor({ NewFile: true, MarkupType: default_markup, commands: editorHotkeys }); } // CriticMarkup