mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-28 22:43:30 +03:00
1ad2c05d37
no issue - new linting rules that needed fixing: - calling `super` in lifecycle hooks - no usage of String prototype extensions
52 lines
1.3 KiB
JavaScript
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;
|
|
}
|
|
});
|