Use objectURLs instead of massively memory consuming dataURL strings.

This commit is contained in:
Nicolas Stepien 2012-01-17 19:15:40 +01:00
parent 771964993a
commit d78381759b
2 changed files with 16 additions and 11 deletions

View File

@ -1331,19 +1331,17 @@
}
_Class.prototype.setFile = function(file) {
var reader,
_this = this;
var url;
this.file = file;
this.el.title = file.name;
if (file.type === 'application/pdf') {
this.el.style.backgroundImage = null;
return;
}
reader = new FileReader();
reader.onload = function() {
return _this.el.style.backgroundImage = "url(" + reader.result + ")";
};
return reader.readAsDataURL(file);
url = window.URL || window.webkitURL;
url.revokeObjectURL(this.url);
this.url = url.createObjectURL(file);
return this.el.style.backgroundImage = "url(" + this.url + ")";
};
_Class.prototype.select = function() {
@ -1360,7 +1358,11 @@
return _results;
};
_Class.prototype.rm = function() {};
_Class.prototype.rm = function() {
var url;
url = window.URL || window.webkitURL;
return url.revokeObjectURL(this.url);
};
return _Class;

View File

@ -1001,9 +1001,10 @@ qr =
if file.type is 'application/pdf'
@el.style.backgroundImage = null
return
reader = new FileReader()
reader.onload = => @el.style.backgroundImage = "url(#{reader.result})"
reader.readAsDataURL file
url = window.URL or window.webkitURL
url.revokeObjectURL @url
@url = url.createObjectURL file
@el.style.backgroundImage = "url(#{@url})"
select: ->
qr.selected?.el.id = null
qr.selected = @
@ -1012,6 +1013,8 @@ qr =
$("[name=#{data}]", qr.el).value = @[data]
rm: ->
# rm reply from qr.replies and the UI
url = window.URL or window.webkitURL
url.revokeObjectURL @url
dialog: ->