Skip to content

Commit

Permalink
Add Cmd+K shortcut for showing link dialog.
Browse files Browse the repository at this point in the history
  • Loading branch information
hackerwins committed Sep 29, 2015
1 parent ac20927 commit 205c36d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 28 deletions.
21 changes: 11 additions & 10 deletions src/js/base/module/Editor.js
@@ -1,8 +1,8 @@
define([
'summernote/base/core/agent',
'summernote/base/core/key',
'summernote/base/core/func',
'summernote/base/core/list',
'summernote/base/core/key',
'summernote/base/core/dom',
'summernote/base/core/range',
'summernote/base/core/async',
Expand All @@ -12,7 +12,7 @@ define([
'summernote/base/editing/Table',
'summernote/base/editing/Bullet'
], function (
agent, func, list, key, dom, range, async,
agent, key, func, list, dom, range, async,
History, Style, Typing, Table, Bullet
) {

Expand All @@ -35,8 +35,10 @@ define([
var history = new History($editable);

this.initialize = function () {
var keyMap = options.keyMap[agent.isMac ? 'mac' : 'pc'];
this.bindKeyMap(keyMap);
// bind keymap
if (options.shortcuts) {
this.bindKeyMap();
}

$editable.on('keyup', function (event) {
summernote.triggerEvent('keyup', event);
Expand All @@ -57,7 +59,8 @@ define([
$editable.off('keydown');
};

this.bindKeyMap = function (keyMap) {
this.bindKeyMap = function () {
var keyMap = options.keyMap[agent.isMac ? 'mac' : 'pc'];
$editable.on('keydown', function (event) {
var keys = [];

Expand All @@ -72,12 +75,10 @@ define([

var eventName = keyMap[keys.join('+')];
if (eventName) {
if (self[eventName]) {
self[eventName](options);
event.preventDefault();
}
event.preventDefault();
summernote.invoke(eventName);
} else if (key.isEdit(event.keyCode)) {
self.afterCommand($editable);
self.afterCommand();
}
});
};
Expand Down
1 change: 0 additions & 1 deletion src/js/bs3/module/LinkPopover.js
Expand Up @@ -18,7 +18,6 @@ define([
$editingArea.append($popover);

this.initialize = function () {

summernote.buildButtons($popover.find('.popover-content'), options.popover.link);
$note.on('summernote.keyup summernote.mouseup summernote.change', function (customEvent, event) {
self.update(event.target);
Expand Down
6 changes: 4 additions & 2 deletions src/js/bs3/settings.js
Expand Up @@ -262,7 +262,8 @@ define([
'CTRL+NUM4': 'formatH4',
'CTRL+NUM5': 'formatH5',
'CTRL+NUM6': 'formatH6',
'CTRL+ENTER': 'insertHorizontalRule'
'CTRL+ENTER': 'insertHorizontalRule',
'CTRL+K': 'linkDialog.show'
},

mac: {
Expand Down Expand Up @@ -291,7 +292,8 @@ define([
'CMD+NUM4': 'formatH4',
'CMD+NUM5': 'formatH5',
'CMD+NUM6': 'formatH6',
'CMD+ENTER': 'insertHorizontalRule'
'CMD+ENTER': 'insertHorizontalRule',
'CMD+K': 'linkDialog.show'
}
}
}
Expand Down
30 changes: 15 additions & 15 deletions src/js/summernote.js
Expand Up @@ -20,20 +20,24 @@ define([
this.options = options;

this.initialize = function () {
// create layout info
this.layoutInfo = ui.createLayout($note);

Object.keys(this.options.buttons).forEach(function (key) {
var button = self.options.buttons[key];
self.addButton(key, button);
});

// initialize module
Object.keys(this.options.modules).forEach(function (key) {
var module = new self.options.modules[key](self);
if (module.initialize) {
module.initialize.apply(module);
}
self.addModule(key, module);
});

// add optional buttons
Object.keys(this.options.buttons).forEach(function (key) {
var button = self.options.buttons[key];
self.addButton(key, button);
});

$note.hide();

this.triggerEvent('ready');
Expand Down Expand Up @@ -69,10 +73,6 @@ define([
$note.trigger('summernote.' + namespace, args);
};

this.removeLayout = function ($note) {
$note.editor.remove();
};

this.addModule = function (key, instance) {
this.modules[key] = instance;
};
Expand All @@ -84,8 +84,8 @@ define([
delete this.modules[key];
};

this.addButton = function (key, createHandler) {
this.buttons[key] = createHandler;
this.addButton = function (key, handler) {
this.buttons[key] = handler;
};

this.removeButton = function (key) {
Expand Down Expand Up @@ -131,11 +131,11 @@ define([
var moduleName = hasSeparator && list.head(splits);
var methodName = hasSeparator ? list.last(splits) : list.head(splits);

var module = this.modules[moduleName];
if (module && module[methodName]) {
return module[methodName].apply(module, args);
} else if (this[methodName]) {
var module = this.modules[moduleName || 'editor'];
if (!moduleName && this[methodName]) {
return this[methodName].apply(this, args);
} else if (module && module[methodName]) {
return module[methodName].apply(module, args);
}
};

Expand Down

0 comments on commit 205c36d

Please sign in to comment.