Add shortcuts support for emoji toolbar

(CTRL E to open, ESC to close)
This commit is contained in:
Sam 2014-12-08 13:32:26 +11:00
parent c5e07aa320
commit 555b783864
3 changed files with 29 additions and 2 deletions

View file

@ -1214,6 +1214,17 @@
makeSpritedButtonRow(); makeSpritedButtonRow();
var keyEvent = "keydown"; var keyEvent = "keydown";
var extendedEvents = [];
if(window.PagedownCustom){
window.PagedownCustom.appendButtons.concat(window.PagedownCustom.insertButtons).forEach(function(button){
if(button.shortcut){
extendedEvents.push([button.shortcut, button.execute]);
}
});
}
util.addEvent(inputBox, keyEvent, function (key) { util.addEvent(inputBox, keyEvent, function (key) {
// Check to see if we have a button key and, if so execute the callback. // Check to see if we have a button key and, if so execute the callback.
@ -1222,6 +1233,12 @@
var keyCode = key.charCode || key.keyCode; var keyCode = key.charCode || key.keyCode;
var keyCodeStr = String.fromCharCode(keyCode).toLowerCase(); var keyCodeStr = String.fromCharCode(keyCode).toLowerCase();
for(var i=0; i<extendedEvents.length; i++){
if(keyCodeStr===extendedEvents[i][0]){
extendedEvents[i][1]();
}
}
switch (keyCodeStr) { switch (keyCodeStr) {
case "b": case "b":
doClick(buttons.bold); doClick(buttons.bold);

View file

@ -32,6 +32,8 @@ var renderPage = Handlebars.compile(
var closeSelector = function(){ var closeSelector = function(){
$('.emoji-modal, .emoji-modal-wrapper').remove(); $('.emoji-modal, .emoji-modal-wrapper').remove();
$('body, textarea').off('keydown.emoji');
$('#wmd-input').focus();
}; };
var showSelector = function(){ var showSelector = function(){
@ -62,10 +64,18 @@ var showSelector = function(){
composerController.appendText(":" + $(this).attr('title') + ":", {space: true}); composerController.appendText(":" + $(this).attr('title') + ":", {space: true});
closeSelector(); closeSelector();
}); });
$('body, textarea').on('keydown.emoji', function(e){
if(e.which === 27){
closeSelector();
return false;
}
});
}; };
window.PagedownCustom.appendButtons.push({ window.PagedownCustom.appendButtons.push({
id: 'wmd-emoji-button', id: 'wmd-emoji-button',
description: I18n.t("composer.emoji"), description: I18n.t("composer.emoji"),
execute: showSelector execute: showSelector,
shortcut: 'e'
}); });

View file

@ -1,7 +1,7 @@
en: en:
js: js:
composer: composer:
emoji: "Emoji :smile:" emoji: "Emoji :smile: CTRL+ E"
admin_js: admin_js:
admin: admin:
site_settings: site_settings: