1
0
Fork 0
mirror of https://github.com/TryGhost/Ghost-Admin.git synced 2023-12-14 02:33:04 +01:00
Ghost-Admin/app/components/gh-token-input/select-multiple.js
Kevin Ansfield d6058dbf27 Co-located component template files
no issue

Keeps component JS backing files and template files in the same directory which avoids hunting across directories when working with components. Also lets you see all components when looking at one directory, whereas previously template-only or js-only components may not have been obvious without looking at both directories.

- ran [codemod](https://github.com/ember-codemods/ember-component-template-colocation-migrator/) for app-level components
- manually moved in-repo-addon component templates in `lib/koenig-editor`
- removed all explicit `layout` imports as JS/template associations are now made at build-time removing the need for them
- updated `.embercli` to default to new flat component structure
2020-05-18 13:14:08 +01:00

68 lines
1.7 KiB
JavaScript

import $ from 'jquery';
import PowerSelectMultiple from 'ember-power-select/components/power-select-multiple';
import {action} from '@ember/object';
import {bind} from '@ember/runloop';
import {tagName} from '@ember-decorators/component';
// TODO: convert from jQuery to native DOM
const END_ACTIONS = 'click.ghToken mouseup.ghToken touchend.ghToken';
// triggering focus on the search input within ESA's onfocus event breaks the
// drag-n-drop functionality in ember-drag-drop so we watch for events that
// could be the start of a drag and disable the default focus behaviour until
// we get another event signalling the end of a drag
@tagName('div')
class GhTokenInputSelectMultiple extends PowerSelectMultiple {
_canFocus = true;
willDestroyElement() {
super.willDestroyElement(...arguments);
if (this._allowFocusListener) {
$(window).off(END_ACTIONS, this._allowFocusListener);
}
}
// actions
@action
optionMouseDown(event) {
if (event.which === 1 && !event.ctrlKey) {
this._denyFocus(event);
}
}
@action
optionTouchStart(event) {
this._denyFocus(event);
}
@action
handleFocus() {
if (this._canFocus) {
super.handleFocus(...arguments);
}
}
// internal
_denyFocus() {
if (this._canFocus) {
this._canFocus = false;
this._allowFocusListener = bind(this, this._allowFocus);
$(window).on(END_ACTIONS, this._allowFocusListener);
}
}
_allowFocus() {
this._canFocus = true;
$(window).off(END_ACTIONS, this._allowFocusListener);
this._allowFocusListener = null;
}
}
export default GhTokenInputSelectMultiple;