Ghost/ghost/admin/app/components/gh-file-input.js
Kevin Ansfield 1ad2c05d37 Bumped eslint-plugin-ghost and fixed linter errors
no issue

- new linting rules that needed fixing:
   - calling `super` in lifecycle hooks
   - no usage of String prototype extensions
2021-07-15 15:27:29 +01:00

52 lines
1.3 KiB
JavaScript

import XFileInput from 'emberx-file-input/components/x-file-input';
// TODO: remove this override and use {{x-file-input}} directly once we've
// upgraded to emberx-file-input@1.2.0
export default XFileInput.extend({
didInsertElement() {
this._super(...arguments);
this.onInsert?.(this.element.querySelector('input[type="file"]'));
},
change(e) {
let action = this.action;
let files = this.files(e);
if (files.length && action) {
action(files, this.resetInput.bind(this));
}
},
/**
* Gets files from event object.
*
* @method
* @private
* @param {$.Event || Event}
*/
files(e) {
return (e.originalEvent || e).testingFiles || e.target.files;
},
/**
* Resets the value of the input so you can select the same file
* multiple times.
*
* NOTE: fixes reset in Firefox which doesn't reset like other browsers
* when doing input.value = null;
*
* @method
*/
resetInput() {
let input = this.element.querySelector('.x-file--input');
input.removeAttribute('value');
input.value = null;
const clone = input.cloneNode(true);
input.parentNode.replaceChild(clone, input);
return clone;
}
});