From 94a0f308560bbe4b996cde06fb84e9bf013d6a23 Mon Sep 17 00:00:00 2001 From: benweet Date: Sat, 12 Oct 2013 20:13:29 +0100 Subject: [PATCH] Added shortcut for synchronize button --- bower.json | 2 +- public/res/config.js | 2 +- public/res/core.js | 4 ++- public/res/extensions/buttonSync.js | 30 +++++++++++++------- public/res/html/buttonSyncSettingsBlock.html | 9 ++++++ public/res/shortcutMgr.js | 8 ++++++ public/res/styles/main.less | 13 +++++++-- 7 files changed, 52 insertions(+), 16 deletions(-) diff --git a/bower.json b/bower.json index 2a45afa4..28b32f8c 100644 --- a/bower.json +++ b/bower.json @@ -19,7 +19,7 @@ "requirejs-text": "~2.0.10", "bootstrap-tour": "~0.6.0", "ace": "#51b7cb67a63998c9c0b7d089a85c60e032a7cc17", - "pagedown-ace": "git@github.com:benweet/pagedown-ace.git#master", + "pagedown-ace": "git@github.com:benweet/pagedown-ace.git#7805f240f343b5b2a05a5b9c0d4a3f5091e7a49b", "pagedown-extra": "git@github.com:jmcmanus/pagedown-extra.git#cca554948c362affb1cbab3bacc3861e2d90d426", "crel": "git@github.com:KoryNunn/crel.git#8dbda04b129fc0aec01a2a080d1cab26816e11c1", "waitForImages": "git@github.com:alexanderdickson/waitForImages.git#~1.4.2", diff --git a/public/res/config.js b/public/res/config.js index 1748319b..8e3dcdea 100644 --- a/public/res/config.js +++ b/public/res/config.js @@ -24,7 +24,7 @@ var WELCOME_DOCUMENT_TITLE = "Welcome document"; var DOWNLOAD_PROXY_URL = "https://stackedit-download-proxy.herokuapp.com/"; var PICASA_PROXY_URL = "https://stackedit-picasa-proxy.herokuapp.com/"; var SSH_PROXY_URL = "https://stackedit-ssh-proxy.herokuapp.com/"; -var HTMLTOPDF_URL = "http://benweet.insomnia247.nl/stackedit-htmltopdf/"; +var HTMLTOPDF_URL = "https://stackedit-htmltopdf.herokuapp.com/"; // Use by Google's client.js var delayedFunction = undefined; diff --git a/public/res/core.js b/public/res/core.js index 1ae4bcee..d52ee475 100644 --- a/public/res/core.js +++ b/public/res/core.js @@ -473,7 +473,9 @@ define([ } if(!lightMode) { - editor = new Markdown.Editor(converter); + editor = new Markdown.Editor(converter, undefined, { + keyStrokes: shortcutMgr.getPagedownKeyStrokes() + }); // Custom insert link dialog editor.hooks.set("insertLinkDialog", function(callback) { core.insertLinkCallback = callback; diff --git a/public/res/extensions/buttonSync.js b/public/res/extensions/buttonSync.js index 562bff74..e237639c 100644 --- a/public/res/extensions/buttonSync.js +++ b/public/res/extensions/buttonSync.js @@ -4,21 +4,25 @@ define([ "crel", "utils", "classes/Extension", + "mousetrap", "text!html/buttonSyncSettingsBlock.html", -], function($, _, crel, utils, Extension, buttonSyncSettingsBlockHTML) { +], function($, _, crel, utils, Extension, mousetrap, buttonSyncSettingsBlockHTML) { - var buttonSync = new Extension("buttonSync", 'Button "Synchronize"'); + var buttonSync = new Extension("buttonSync", 'Button "Synchronize"', false, true); buttonSync.settingsBlock = buttonSyncSettingsBlockHTML; buttonSync.defaultConfig = { - syncPeriod: 180000 + syncPeriod: 180000, + syncShortcut: 'mod+s' }; buttonSync.onLoadSettings = function() { utils.setInputValue("#input-sync-period", buttonSync.config.syncPeriod); + utils.setInputValue("#input-sync-shortcut", buttonSync.config.syncShortcut); }; buttonSync.onSaveSettings = function(newConfig, event) { newConfig.syncPeriod = utils.getInputIntValue("#input-sync-period", event, 0); + newConfig.syncShortcut = utils.getInputTextValue("#input-sync-shortcut", event); }; var synchronizer = undefined; @@ -45,12 +49,10 @@ define([ // Run sync periodically var lastSync = 0; buttonSync.onPeriodicRun = function() { - if(viewerMode === true || !buttonSync.config.syncPeriod || lastSync + buttonSync.config.syncPeriod > utils.currentTime) { + if(!buttonSync.config.syncPeriod || lastSync + buttonSync.config.syncPeriod > utils.currentTime) { return; } - if(synchronizer.sync() === true) { - lastSync = utils.currentTime; - } + synchronizer.sync() && (lastSync = utils.currentTime); }; buttonSync.onCreateButton = function() { @@ -60,9 +62,10 @@ define([ }, crel('i', { class: 'icon-refresh' })); - $button = $(button).click(function() { - if(!$(this).hasClass("disabled")) { - synchronizer.sync(); + $button = $(button); + $button.click(function() { + if(!$button.hasClass("disabled")) { + synchronizer.sync() && (lastSync = utils.currentTime); } }); return button; @@ -84,6 +87,13 @@ define([ isOffline = isOfflineParameter; updateButtonState(); }; + + buttonSync.onReady = function() { + mousetrap.bind(buttonSync.config.syncShortcut, function(e) { + synchronizer.sync() && (lastSync = utils.currentTime); + e.preventDefault(); + }); + }; return buttonSync; diff --git a/public/res/html/buttonSyncSettingsBlock.html b/public/res/html/buttonSyncSettingsBlock.html index a886382c..94ffbd96 100644 --- a/public/res/html/buttonSyncSettingsBlock.html +++ b/public/res/html/buttonSyncSettingsBlock.html @@ -8,4 +8,13 @@ class="col-lg-5 form-control" placeholder="180000"> ms +
+ +
+ +
+
\ No newline at end of file diff --git a/public/res/shortcutMgr.js b/public/res/shortcutMgr.js index 024eac17..81e5b90a 100644 --- a/public/res/shortcutMgr.js +++ b/public/res/shortcutMgr.js @@ -261,6 +261,14 @@ define([ shortcut.exec && aceEditor.commands.addCommand(_.pick(shortcut, 'name', 'bindKey', 'exec', 'readOnly', 'multiSelectAction')); }); }; + + shortcutMgr.getPagedownKeyStrokes = function() { + return _.chain(shortcuts).where({ + isPageDown: true + }).map(function(shortcut) { + return [shortcut.name, shortcut.bindKey]; + }).object().value(); + }; shortcutMgr.addSettingEntries = function() { var shortcutEntries = _.reduce(shortcuts, function(result, shortcut) { diff --git a/public/res/styles/main.less b/public/res/styles/main.less index 64b1e3b4..ea86f602 100644 --- a/public/res/styles/main.less +++ b/public/res/styles/main.less @@ -171,16 +171,23 @@ a { .transition(~"background-color ease-in-out .15s, color ease-in-out .15s, z-index ease-in-out .15s"); } -.btn-default:hover { +.btn-default:hover, +.btn-default:focus, +.btn-default:active { background-color: @btn-default-hover-bg; } -.btn-primary:hover { +.btn-primary:hover, +.btn-primary:focus, +.btn-primary:active { color: @btn-primary-color; background-color: @btn-primary-hover-bg; } -.btn-success:hover, .open .dropdown-toggle.btn-success { +.btn-success:hover, +.btn-success:focus, +.btn-success:active, +.open .dropdown-toggle.btn-success { color: @btn-success-color; background-color: @bg-navbar-hover !important; // important to override .nav > li > a:hover }