mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 09:36:19 -05:00
Add shortcuts support for emoji toolbar
(CTRL E to open, ESC to close)
This commit is contained in:
parent
c5e07aa320
commit
555b783864
3 changed files with 29 additions and 2 deletions
|
@ -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);
|
||||
|
|
|
@ -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'
|
||||
});
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
en:
|
||||
js:
|
||||
composer:
|
||||
emoji: "Emoji :smile:"
|
||||
emoji: "Emoji :smile: CTRL+ E"
|
||||
admin_js:
|
||||
admin:
|
||||
site_settings:
|
||||
|
|
Loading…
Reference in a new issue