mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 15:48:43 -05:00
Add keydown hook for widgets (#4308)
This commit is contained in:
parent
3cb8bbb851
commit
5c1e18ecc8
2 changed files with 11 additions and 1 deletions
|
@ -3,6 +3,7 @@
|
|||
const CLICK_ATTRIBUTE_NAME = '_discourse_click_widget';
|
||||
const CLICK_OUTSIDE_ATTRIBUTE_NAME = '_discourse_click_outside_widget';
|
||||
const KEY_UP_ATTRIBUTE_NAME = '_discourse_key_up_widget';
|
||||
const KEY_DOWN_ATTRIBUTE_NAME = '_discourse_key_down_widget';
|
||||
const DRAG_ATTRIBUTE_NAME = '_discourse_drag_widget';
|
||||
|
||||
function buildHook(attributeName, setAttr) {
|
||||
|
@ -30,6 +31,7 @@ function buildHook(attributeName, setAttr) {
|
|||
export const WidgetClickHook = buildHook(CLICK_ATTRIBUTE_NAME);
|
||||
export const WidgetClickOutsideHook = buildHook(CLICK_OUTSIDE_ATTRIBUTE_NAME, 'data-click-outside');
|
||||
export const WidgetKeyUpHook = buildHook(KEY_UP_ATTRIBUTE_NAME);
|
||||
export const WidgetKeyDownHook = buildHook(KEY_DOWN_ATTRIBUTE_NAME);
|
||||
export const WidgetDragHook = buildHook(DRAG_ATTRIBUTE_NAME);
|
||||
|
||||
|
||||
|
@ -105,5 +107,9 @@ WidgetClickHook.setupDocumentCallback = function() {
|
|||
nodeCallback(e.target, KEY_UP_ATTRIBUTE_NAME, w => w.keyUp(e));
|
||||
});
|
||||
|
||||
$(document).on('keydown.discourse-widget', e => {
|
||||
nodeCallback(e.target, KEY_DOWN_ATTRIBUTE_NAME, w => w.keyDown(e));
|
||||
});
|
||||
|
||||
_watchingDocument = true;
|
||||
};
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { WidgetClickHook, WidgetClickOutsideHook, WidgetKeyUpHook, WidgetDragHook } from 'discourse/widgets/hooks';
|
||||
import { WidgetClickHook, WidgetClickOutsideHook, WidgetKeyUpHook, WidgetKeyDownHook, WidgetDragHook } from 'discourse/widgets/hooks';
|
||||
import { h } from 'virtual-dom';
|
||||
import DecoratorHelper from 'discourse/widgets/decorator-helper';
|
||||
|
||||
|
@ -71,6 +71,10 @@ function drawWidget(builder, attrs, state) {
|
|||
properties['widget-key-up'] = new WidgetKeyUpHook(this);
|
||||
}
|
||||
|
||||
if (this.keyDown) {
|
||||
properties['widget-key-down'] = new WidgetKeyDownHook(this);
|
||||
}
|
||||
|
||||
if (this.clickOutside) {
|
||||
properties['widget-click-outside'] = new WidgetClickOutsideHook(this);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue