Stackedit/public/res/shortcutMgr.js

140 lines
3.9 KiB
JavaScript
Raw Normal View History

2013-09-29 22:28:59 +00:00
define([
"underscore",
"eventMgr",
"settings",
2013-09-30 22:37:58 +00:00
"utils",
"text!html/settingsShortcutEntry.html",
2013-11-05 23:03:38 +00:00
], function(_, eventMgr, settings, utils, settingsShortcutEntryHTML) {
2013-09-29 22:28:59 +00:00
var shortcutMgr = {};
2013-09-30 00:16:01 +00:00
2013-09-29 22:28:59 +00:00
var shortcuts = {
'bold': {
title: 'Strong',
2013-09-30 00:16:01 +00:00
defaultKey: {
2013-09-29 22:28:59 +00:00
win: 'Ctrl-B',
mac: 'Command-B|Ctrl-B',
},
},
'italic': {
2013-09-30 22:37:58 +00:00
title: 'Emphasis',
2013-09-30 00:16:01 +00:00
defaultKey: {
2013-09-29 22:28:59 +00:00
win: 'Ctrl-I',
mac: 'Command-I|Ctrl-I',
},
},
'link': {
2013-09-30 22:37:58 +00:00
title: 'Hyperlink',
2013-09-30 00:16:01 +00:00
defaultKey: {
2013-09-29 22:28:59 +00:00
win: 'Ctrl-L',
mac: 'Command-L|Ctrl-L',
},
},
'quote': {
2013-09-30 22:37:58 +00:00
title: 'Blockquote',
2013-09-30 00:16:01 +00:00
defaultKey: {
2013-09-29 22:28:59 +00:00
win: 'Ctrl-Q',
mac: 'Command-Q|Ctrl-Q',
},
},
'code': {
2013-09-30 22:37:58 +00:00
title: 'Code Sample',
2013-09-30 00:16:01 +00:00
defaultKey: {
2013-09-29 22:28:59 +00:00
win: 'Ctrl-K',
mac: 'Command-K|Ctrl-K',
},
},
'image': {
2013-09-30 22:37:58 +00:00
title: 'Image',
2013-09-30 00:16:01 +00:00
defaultKey: {
2013-09-29 22:28:59 +00:00
win: 'Ctrl-G',
mac: 'Command-G|Ctrl-G',
},
},
'olist': {
2013-09-30 22:37:58 +00:00
title: 'Numbered List',
2013-09-30 00:16:01 +00:00
defaultKey: {
2013-09-29 22:28:59 +00:00
win: 'Ctrl-O',
mac: 'Command-O|Ctrl-O',
},
},
'ulist': {
2013-09-30 22:37:58 +00:00
title: 'Bulleted List',
2013-09-30 00:16:01 +00:00
defaultKey: {
2013-09-29 22:28:59 +00:00
win: 'Ctrl-U',
mac: 'Command-U|Ctrl-U',
},
},
'heading': {
2013-09-30 22:37:58 +00:00
title: 'Heading',
2013-09-30 00:16:01 +00:00
defaultKey: {
2013-09-29 22:28:59 +00:00
win: 'Ctrl-H',
mac: 'Command-H|Ctrl-H',
},
},
'hr': {
2013-09-30 22:37:58 +00:00
title: 'Horizontal Rule',
2013-09-30 00:16:01 +00:00
defaultKey: {
2013-09-29 22:28:59 +00:00
win: 'Ctrl-R',
mac: 'Command-R|Ctrl-R',
},
},
'undo': {
2013-09-30 22:37:58 +00:00
title: 'Undo',
2013-09-30 00:16:01 +00:00
defaultKey: {
2013-09-29 22:28:59 +00:00
win: 'Ctrl-Z',
mac: 'Command-Z',
},
},
'redo': {
title: 'Redo',
2013-09-30 00:16:01 +00:00
defaultKey: {
2013-09-30 22:37:58 +00:00
win: 'Ctrl-Y|Ctrl-Shift-Z',
mac: 'Command-Y|Command-Shift-Z',
2013-09-29 22:28:59 +00:00
},
},
};
2013-09-30 00:16:01 +00:00
2013-09-29 22:28:59 +00:00
_.each(shortcuts, function(shortcut, key) {
2013-09-30 00:16:01 +00:00
shortcut.name = key;
shortcut.bindKey = settings.shortcuts[key] || shortcut.defaultKey;
2013-09-29 22:28:59 +00:00
});
2013-10-12 19:13:29 +00:00
shortcutMgr.getPagedownKeyStrokes = function() {
return _.chain(shortcuts).where({
isPageDown: true
}).map(function(shortcut) {
return [shortcut.name, shortcut.bindKey];
}).object().value();
};
2013-09-29 22:28:59 +00:00
2013-09-30 22:37:58 +00:00
shortcutMgr.addSettingEntries = function() {
var shortcutEntries = _.reduce(shortcuts, function(result, shortcut) {
return result + _.template(settingsShortcutEntryHTML, {
shortcut: shortcut
});
}, '');
var settingsFormElement = document.querySelector('#tabpane-settings-shortcuts .form-horizontal');
settingsFormElement && (settingsFormElement.innerHTML = shortcutEntries);
};
shortcutMgr.loadSettings = function() {
_.each(shortcuts, function(shortcut) {
utils.setInputValue("#input-settings-shortcut-" + shortcut.name, shortcut.bindKey.win);
utils.setInputValue("#input-settings-shortcut-" + shortcut.name + '-mac', shortcut.bindKey.mac);
});
};
2013-10-11 21:47:00 +00:00
shortcutMgr.saveSettings = function(newSettings) {
newSettings.shortcuts = {};
_.each(shortcuts, function(shortcut, key) {
var newShortcut = {};
newShortcut.win = utils.getInputValue("#input-settings-shortcut-" + shortcut.name);
newShortcut.mac = utils.getInputValue("#input-settings-shortcut-" + shortcut.name + '-mac');
newSettings.shortcuts[key] = newShortcut;
});
};
2013-09-29 22:28:59 +00:00
return shortcutMgr;
2014-04-15 23:16:08 +00:00
});