Resize thumbnails on Opera too.

This commit is contained in:
Nicolas Stepien 2013-03-07 22:09:32 +01:00
parent 22b1e7f3c1
commit 2c81f67fd4
2 changed files with 50 additions and 33 deletions

View File

@ -6297,7 +6297,7 @@
if (!window.URL) {
return;
}
return URL.revokeObjectURL(this.url);
return URL.revokeObjectURL(this.URL);
};
_Class.prototype.lock = function(lock) {
@ -6372,8 +6372,6 @@
};
_Class.prototype.setFile = function(file) {
var fileURL, img, reader,
_this = this;
this.file = file;
this.filename = "" + file.name + " (" + ($.bytesToString(file.size)) + ")";
this.nodes.el.title = this.filename;
@ -6381,30 +6379,38 @@
this.nodes.label.hidden = false;
}
if (window.URL) {
URL.revokeObjectURL(this.url);
URL.revokeObjectURL(this.URL);
}
this.showFileData();
if (!/^image/.test(file.type)) {
this.nodes.el.style.backgroundImage = null;
return;
}
return this.setThumbnail();
};
_Class.prototype.setThumbnail = function(fileURL) {
var img, reader,
_this = this;
if (!window.URL) {
reader = new FileReader();
reader.onload = function(e) {
return _this.nodes.el.style.backgroundImage = "url(" + e.target.result + ")";
};
reader.readAsDataURL(file);
return;
if (!fileURL) {
reader = new FileReader();
reader.onload = function(e) {
return _this.setThumbnail(e.target.result);
};
reader.readAsDataURL(this.file);
}
} else {
fileURL = URL.createObjectURL(this.file);
}
fileURL = URL.createObjectURL(file);
img = $.el('img');
img.onload = function() {
var applyBlob, c, data, height, i, l, s, ui8a, width, _i;
s = 90 * 3;
height = img.height, width = img.width;
if (height < s || width < s) {
_this.url = fileURL;
_this.nodes.el.style.backgroundImage = "url(" + _this.url + ")";
_this.URL = fileURL;
_this.nodes.el.style.backgroundImage = "url(" + _this.URL + ")";
return;
}
if (height <= width) {
@ -6418,10 +6424,15 @@
c.height = img.height = height;
c.width = img.width = width;
c.getContext('2d').drawImage(img, 0, 0, width, height);
if (!window.URL) {
_this.nodes.el.style.backgroundImage = "url(" + (c.toDataURL()) + ")";
delete _this.URL;
return;
}
URL.revokeObjectURL(fileURL);
applyBlob = function(blob) {
_this.url = URL.createObjectURL(blob);
return _this.nodes.el.style.backgroundImage = "url(" + _this.url + ")";
_this.URL = URL.createObjectURL(blob);
return _this.nodes.el.style.backgroundImage = "url(" + _this.URL + ")";
};
if (c.toBlob) {
c.toBlob(applyBlob);
@ -6452,7 +6463,7 @@
if (!window.URL) {
return;
}
return URL.revokeObjectURL(this.url);
return URL.revokeObjectURL(this.URL);
};
_Class.prototype.showFileData = function(hide) {

View File

@ -409,7 +409,7 @@ QR =
(QR.posts[index-1] or QR.posts[index+1]).select()
QR.posts.splice index, 1
return unless window.URL
URL.revokeObjectURL @url
URL.revokeObjectURL @URL
lock: (lock=true) ->
@isLocked = lock
return unless @ is QR.selected
@ -459,23 +459,25 @@ QR =
@filename = "#{file.name} (#{$.bytesToString file.size})"
@nodes.el.title = @filename
@nodes.label.hidden = false if QR.spoiler
URL.revokeObjectURL @url if window.URL
URL.revokeObjectURL @URL if window.URL
@showFileData()
unless /^image/.test file.type
@nodes.el.style.backgroundImage = null
return
@setThumbnail()
setThumbnail: (fileURL) ->
# XXX Opera does not support blob URL
unless window.URL
reader = new FileReader()
reader.onload = (e) =>
@nodes.el.style.backgroundImage = "url(#{e.target.result})"
reader.readAsDataURL file
return
# Create a redimensioned thumbnail.
fileURL = URL.createObjectURL file
img = $.el 'img'
unless window.URL
unless fileURL
reader = new FileReader()
reader.onload = (e) =>
@setThumbnail e.target.result
reader.readAsDataURL @file
else
fileURL = URL.createObjectURL @file
img = $.el 'img'
img.onload = =>
# Generate thumbnails only if they're really big.
@ -485,8 +487,8 @@ QR =
s = 90*3
{height, width} = img
if height < s or width < s
@url = fileURL
@nodes.el.style.backgroundImage = "url(#{@url})"
@URL = fileURL
@nodes.el.style.backgroundImage = "url(#{@URL})"
return
if height <= width
width = s / height * width
@ -498,10 +500,14 @@ QR =
c.height = img.height = height
c.width = img.width = width
c.getContext('2d').drawImage img, 0, 0, width, height
unless window.URL
@nodes.el.style.backgroundImage = "url(#{c.toDataURL()})"
delete @URL
return
URL.revokeObjectURL fileURL
applyBlob = (blob) =>
@url = URL.createObjectURL blob
@nodes.el.style.backgroundImage = "url(#{@url})"
@URL = URL.createObjectURL blob
@nodes.el.style.backgroundImage = "url(#{@URL})"
if c.toBlob
c.toBlob applyBlob
return
@ -524,7 +530,7 @@ QR =
@nodes.label.hidden = true if QR.spoiler
@showFileData()
return unless window.URL
URL.revokeObjectURL @url
URL.revokeObjectURL @URL
showFileData: (hide) ->
if @file
QR.nodes.filename.textContent = @filename