Skip to content

Commit

Permalink
Image: Bring some consistency and clarification to meta update
Browse files Browse the repository at this point in the history
  • Loading branch information
Davit Barbakadze committed Feb 2, 2017
1 parent 498eea4 commit 624da58
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 15 deletions.
17 changes: 5 additions & 12 deletions src/javascript/image/Image.js
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,10 @@ define("moxie/image/Image", [
this.getRuntime().exec.call(this, 'Image', 'destroy');
this.disconnectRuntime();
}
_updateMeta.call(this, null);
if (this.meta && this.meta.thumb) {
// thumb is blob, make sure we destroy it first
this.meta.thumb.data.destroy();
}
this.unbindAll();
}
});
Expand All @@ -587,15 +590,6 @@ define("moxie/image/Image", [
}, 999);


function _updateMeta(data) {
if (this.meta && this.meta.thumb) {
// thumb is blob, make sure we destroy it first
this.meta.thumb.data.destroy();
}
this.meta = data;
}


function _updateInfo(info) {
try {
if (!info) {
Expand All @@ -606,14 +600,13 @@ define("moxie/image/Image", [
this.width = info.width;
this.height = info.height;
this.type = info.type;
this.meta = info.meta;

// update file name, only if empty
if (this.name === '') {
this.name = info.name;
}

_updateMeta.call(this, info.meta);

return true;
} catch(ex) {
this.trigger('error', ex.code);
Expand Down
2 changes: 1 addition & 1 deletion src/javascript/runtime/flash/image/Image.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ define("moxie/runtime/flash/image/Image", [
, info = self.shimExec.call(this, 'Image', 'getInfo')
;

if (info.meta && info.meta.thumb && !(info.meta.thumb.data instanceof Blob)) {
if (info.meta && info.meta.thumb && info.meta.thumb.data && !(self.meta.thumb.data instanceof Blob)) {
info.meta.thumb.data = new Blob(self.uid, info.meta.thumb.data);
}
return info;
Expand Down
3 changes: 2 additions & 1 deletion src/javascript/runtime/html5/image/Image.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ define("moxie/runtime/html5/image/Image", [
_imgInfo = new ImageInfo(_binStr);
}

// this stuff below is definitely having fun with itself
info = {
width: _getImg().width || 0,
height: _getImg().height || 0,
Expand All @@ -89,7 +90,7 @@ define("moxie/runtime/html5/image/Image", [
if (_preserveHeaders) {
info.meta = _imgInfo && _imgInfo.meta || this.meta || {};

// store thumbnail data as blob
// if data was taken from ImageInfo it will be a binary string, so we convert it to blob
if (info.meta && info.meta.thumb && !(info.meta.thumb.data instanceof Blob)) {
info.meta.thumb.data = new Blob(null, {
type: 'image/jpeg',
Expand Down
2 changes: 1 addition & 1 deletion src/javascript/runtime/silverlight/image/Image.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ define("moxie/runtime/silverlight/image/Image", [
});

// save thumb data as blob
if (info.meta && info.meta.thumb && !(info.meta.thumb.data instanceof Blob)) {
if (info.meta && info.meta.thumb && info.meta.thumb.data && !(self.meta.thumb.data instanceof Blob)) {
info.meta.thumb.data = new Blob(self.uid, info.meta.thumb.data);
}
}
Expand Down

0 comments on commit 624da58

Please sign in to comment.