client/posts: use object URLs in upload form
This commit is contained in:
parent
f9754edcce
commit
cc78766585
1 changed files with 21 additions and 7 deletions
|
@ -18,6 +18,9 @@ class Uploadable extends events.EventTarget {
|
||||||
globalOrder++;
|
globalOrder++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
destroy() {
|
||||||
|
}
|
||||||
|
|
||||||
get type() {
|
get type() {
|
||||||
return 'unknown';
|
return 'unknown';
|
||||||
}
|
}
|
||||||
|
@ -37,13 +40,23 @@ class File extends Uploadable {
|
||||||
this.file = file;
|
this.file = file;
|
||||||
|
|
||||||
this._imageUrl = null;
|
this._imageUrl = null;
|
||||||
let reader = new FileReader();
|
if (URL && URL.createObjectURL) {
|
||||||
reader.readAsDataURL(file);
|
this._imageUrl = URL.createObjectURL(file);
|
||||||
reader.addEventListener('load', e => {
|
} else {
|
||||||
this._imageUrl = e.target.result;
|
let reader = new FileReader();
|
||||||
this.dispatchEvent(
|
reader.readAsDataURL(file);
|
||||||
new CustomEvent('finish', {detail: {uploadable: this}}));
|
reader.addEventListener('load', e => {
|
||||||
});
|
this._imageUrl = e.target.result;
|
||||||
|
this.dispatchEvent(
|
||||||
|
new CustomEvent('finish', {detail: {uploadable: this}}));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
destroy() {
|
||||||
|
if (URL && URL.createObjectURL && URL.revokeObjectURL) {
|
||||||
|
URL.revokeObjectURL(this._imageUrl);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get type() {
|
get type() {
|
||||||
|
@ -184,6 +197,7 @@ class PostUploadView extends events.EventTarget {
|
||||||
if (!this._uploadables.has(uploadable.key)) {
|
if (!this._uploadables.has(uploadable.key)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
uploadable.destroy();
|
||||||
uploadable.rowNode.parentNode.removeChild(uploadable.rowNode);
|
uploadable.rowNode.parentNode.removeChild(uploadable.rowNode);
|
||||||
this._uploadables.delete(uploadable.key);
|
this._uploadables.delete(uploadable.key);
|
||||||
this._emit('change');
|
this._emit('change');
|
||||||
|
|
Loading…
Reference in a new issue