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();
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) {
// 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 keyCodeStr = String.fromCharCode(keyCode).toLowerCase();
for(var i=0; i<extendedEvents.length; i++){
if(keyCodeStr===extendedEvents[i][0]){
extendedEvents[i][1]();
}
}
switch (keyCodeStr) {
case "b":
doClick(buttons.bold);

View file

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

View file

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