Standardized on non-jQuery file dialog triggers

no issue

- we had a mix of legacy jQuery triggers and native triggers for file input clicks and jQuery hasn't been required to do this in our target browsers for quite a long time now so it made sense to update all click triggers to avoid old patterns being replicated
- cleaned up some conditionals with optional-chaining
- removed use of `run.bind(this)` for methods that use `@action` because the binding is already handled for us
This commit is contained in:
Kevin Ansfield 2022-05-26 11:05:14 +01:00
parent aaef8f7d44
commit 8fee5f155b
8 changed files with 31 additions and 74 deletions

View File

@ -1,4 +1,3 @@
import $ from 'jquery';
import ModalComponent from 'ghost-admin/components/modal-base';
import copyTextToClipboard from 'ghost-admin/utils/copy-text-to-clipboard';
import {action, computed} from '@ember/object';
@ -222,12 +221,7 @@ export default ModalComponent.extend({
* @param {MouseEvent} event - MouseEvent fired by the button click
*/
triggerFileDialog(event) {
// simulate click to open file dialog
// using jQuery because IE11 doesn't support MouseEvent
$(event.target)
.closest('.gh-setting-action')
.find('input[type="file"]')
.click();
event?.target.closest('.gh-setting-action')?.find('input[type="file"]')?.click();
},
deleteCustomIcon() {

View File

@ -2,7 +2,6 @@ import classic from 'ember-classic-decorator';
import {action, computed} from '@ember/object';
import {inject as service} from '@ember/service';
/* eslint-disable ghost/ember/alias-model-in-controller */
import $ from 'jquery';
import Controller from '@ember/controller';
import generatePassword from 'ghost-admin/utils/password-generator';
import validator from 'validator';
@ -67,12 +66,7 @@ export default class GeneralController extends Controller {
*/
@action
triggerFileDialog(event) {
// simulate click to open file dialog
// using jQuery because IE11 doesn't support MouseEvent
$(event.target)
.closest('.gh-setting-action')
.find('input[type="file"]')
.click();
event?.target.closest('.gh-setting-action')?.find('input[type="file"]')?.click();
}
/**

View File

@ -1,7 +1,6 @@
import classic from 'ember-classic-decorator';
import {inject as service} from '@ember/service';
/* eslint-disable ghost/ember/alias-model-in-controller */
import $ from 'jquery';
import Controller from '@ember/controller';
import RSVP from 'rsvp';
import config from 'ghost-admin/config/environment';
@ -161,11 +160,7 @@ export default class LabsController extends Controller {
@action
triggerFileDialog(event) {
// simulate click to open file dialog
// using jQuery because IE11 doesn't support MouseEvent
$(event.target)
.closest('.gh-setting-action')
.find('input[type="file"]')
.click();
event?.target.closest('.gh-setting-action')?.find('input[type="file"]')?.click();
}
// TODO: convert to ember-concurrency task

View File

@ -1,4 +1,3 @@
import $ from 'jquery';
import Component from '@glimmer/component';
import {
IMAGE_EXTENSIONS,
@ -82,17 +81,6 @@ export default class KoenigCardBeforeAfterComponent extends Component {
}
}
_triggerFileDialog(event) {
let target = event && event.target || this.element;
// simulate click to open file dialog
// using jQuery because IE11 doesn't support MouseEvent
$(target)
.closest('.__mobiledoc-card')
.find('input[type="file"]')
.trigger('click');
}
setupListeners() {
this.updateImageDimensions();
const handleResize = () => {
@ -189,6 +177,15 @@ export default class KoenigCardBeforeAfterComponent extends Component {
this._triggerFileDialog();
}
_triggerFileDialog(event) {
const target = event?.target || this.element;
const cardElem = target.closest('.__mobiledoc-card');
const fileInput = cardElem?.querySelector('input[type="file"]');
fileInput?.click();
}
@action
uploadFailed() {
}

View File

@ -123,9 +123,7 @@ export default class KoenigCardFileComponent extends Component {
const cardElem = target.closest('.__mobiledoc-card');
const fileInput = cardElem?.querySelector('input[type="file"]');
if (fileInput) {
fileInput.click();
}
fileInput?.click();
}
@action

View File

@ -1,4 +1,3 @@
import $ from 'jquery';
import Component from '@ember/component';
import EmberObject, {action, computed, set} from '@ember/object';
import classic from 'ember-classic-decorator';
@ -68,7 +67,7 @@ export default class KoenigCardGallery extends Component {
title: 'Add images',
icon: 'koenig/kg-add',
iconClass: 'fill-white',
action: run.bind(this, this._triggerFileDialog)
action: this.triggerFileDialog
}]
};
}
@ -184,7 +183,12 @@ export default class KoenigCardGallery extends Component {
@action
triggerFileDialog(event) {
this._triggerFileDialog(event);
const target = event?.target || this.element;
const cardElem = target.closest('.__mobiledoc-card');
const fileInput = cardElem?.querySelector('input[type="file"]');
fileInput?.click();
}
@action
@ -340,17 +344,6 @@ export default class KoenigCardGallery extends Component {
this._registerOrRefreshDragDropHandler();
}
_triggerFileDialog(event) {
let target = event && event.target || this.element;
// simulate click to open file dialog
// using jQuery because IE11 doesn't support MouseEvent
$(target)
.closest('.__mobiledoc-card')
.find('input[type="file"]')
.click();
}
// - rename container so that it's more explicit when we have an initial file
// drop container vs a drag reorder+file drop container?
_registerOrRefreshDragDropHandler() {

View File

@ -1,4 +1,3 @@
import $ from 'jquery';
import Component from '@ember/component';
import classic from 'ember-classic-decorator';
import {
@ -137,7 +136,7 @@ export default class KoenigCardImage extends Component {
title: 'Replace image',
icon: 'koenig/kg-replace',
iconClass: 'fill-white',
action: run.bind(this, this._triggerFileDialog)
action: this.triggerFileDialog
}];
}
@ -219,7 +218,12 @@ export default class KoenigCardImage extends Component {
*/
@action
triggerFileDialog(event) {
this._triggerFileDialog(event);
const target = event?.target || this.element;
const cardElem = target.closest('.__mobiledoc-card');
const fileInput = cardElem?.querySelector('input[type="file"]');
fileInput?.click();
}
@action
@ -377,17 +381,6 @@ export default class KoenigCardImage extends Component {
save(payload, false);
}
_triggerFileDialog(event) {
let target = event && event.target || this.element;
// simulate click to open file dialog
// using jQuery because IE11 doesn't support MouseEvent
$(target)
.closest('.__mobiledoc-card')
.find('input[type="file"]')
.click();
}
_editLink(event) {
event.preventDefault();
event.stopPropagation();

View File

@ -1,4 +1,3 @@
import $ from 'jquery';
import Browser from 'mobiledoc-kit/utils/browser';
import Component from '@glimmer/component';
import {
@ -276,18 +275,12 @@ export default class KoenigCardProductComponent extends Component {
*/
@action
triggerFileDialog(event) {
this._triggerFileDialog(event);
}
const target = event?.target || this.element;
_triggerFileDialog(event) {
let target = event && event.target || this.element;
const cardElem = target.closest('.__mobiledoc-card');
const fileInput = cardElem?.querySelector('input[type="file"]');
// simulate click to open file dialog
// using jQuery because IE11 doesn't support MouseEvent
$(target)
.closest('.__mobiledoc-card')
.find('input[type="file"]')
.click();
fileInput?.click();
}
@action