mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-24 11:22:19 +03:00
d14c432264
closes https://github.com/TryGhost/Ghost/issues/11707 - Firefox is different to every other browser and doesn't allow file input values to be reset by doing `input.value = null` - outcome of reset not working is that Firefox won't trigger the change event when the same file is re-selected - fixed by cloning the input element and replacing it
43 lines
1.1 KiB
JavaScript
43 lines
1.1 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({
|
|
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;
|
|
input.parentNode.replaceChild(input.cloneNode(true), input);
|
|
}
|
|
});
|