Resize thumbnails on Opera too.
This commit is contained in:
parent
22b1e7f3c1
commit
2c81f67fd4
@ -6297,7 +6297,7 @@
|
|||||||
if (!window.URL) {
|
if (!window.URL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return URL.revokeObjectURL(this.url);
|
return URL.revokeObjectURL(this.URL);
|
||||||
};
|
};
|
||||||
|
|
||||||
_Class.prototype.lock = function(lock) {
|
_Class.prototype.lock = function(lock) {
|
||||||
@ -6372,8 +6372,6 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
_Class.prototype.setFile = function(file) {
|
_Class.prototype.setFile = function(file) {
|
||||||
var fileURL, img, reader,
|
|
||||||
_this = this;
|
|
||||||
this.file = file;
|
this.file = file;
|
||||||
this.filename = "" + file.name + " (" + ($.bytesToString(file.size)) + ")";
|
this.filename = "" + file.name + " (" + ($.bytesToString(file.size)) + ")";
|
||||||
this.nodes.el.title = this.filename;
|
this.nodes.el.title = this.filename;
|
||||||
@ -6381,30 +6379,38 @@
|
|||||||
this.nodes.label.hidden = false;
|
this.nodes.label.hidden = false;
|
||||||
}
|
}
|
||||||
if (window.URL) {
|
if (window.URL) {
|
||||||
URL.revokeObjectURL(this.url);
|
URL.revokeObjectURL(this.URL);
|
||||||
}
|
}
|
||||||
this.showFileData();
|
this.showFileData();
|
||||||
if (!/^image/.test(file.type)) {
|
if (!/^image/.test(file.type)) {
|
||||||
this.nodes.el.style.backgroundImage = null;
|
this.nodes.el.style.backgroundImage = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
return this.setThumbnail();
|
||||||
|
};
|
||||||
|
|
||||||
|
_Class.prototype.setThumbnail = function(fileURL) {
|
||||||
|
var img, reader,
|
||||||
|
_this = this;
|
||||||
if (!window.URL) {
|
if (!window.URL) {
|
||||||
reader = new FileReader();
|
if (!fileURL) {
|
||||||
reader.onload = function(e) {
|
reader = new FileReader();
|
||||||
return _this.nodes.el.style.backgroundImage = "url(" + e.target.result + ")";
|
reader.onload = function(e) {
|
||||||
};
|
return _this.setThumbnail(e.target.result);
|
||||||
reader.readAsDataURL(file);
|
};
|
||||||
return;
|
reader.readAsDataURL(this.file);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fileURL = URL.createObjectURL(this.file);
|
||||||
}
|
}
|
||||||
fileURL = URL.createObjectURL(file);
|
|
||||||
img = $.el('img');
|
img = $.el('img');
|
||||||
img.onload = function() {
|
img.onload = function() {
|
||||||
var applyBlob, c, data, height, i, l, s, ui8a, width, _i;
|
var applyBlob, c, data, height, i, l, s, ui8a, width, _i;
|
||||||
s = 90 * 3;
|
s = 90 * 3;
|
||||||
height = img.height, width = img.width;
|
height = img.height, width = img.width;
|
||||||
if (height < s || width < s) {
|
if (height < s || width < s) {
|
||||||
_this.url = fileURL;
|
_this.URL = fileURL;
|
||||||
_this.nodes.el.style.backgroundImage = "url(" + _this.url + ")";
|
_this.nodes.el.style.backgroundImage = "url(" + _this.URL + ")";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (height <= width) {
|
if (height <= width) {
|
||||||
@ -6418,10 +6424,15 @@
|
|||||||
c.height = img.height = height;
|
c.height = img.height = height;
|
||||||
c.width = img.width = width;
|
c.width = img.width = width;
|
||||||
c.getContext('2d').drawImage(img, 0, 0, width, height);
|
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);
|
URL.revokeObjectURL(fileURL);
|
||||||
applyBlob = function(blob) {
|
applyBlob = function(blob) {
|
||||||
_this.url = URL.createObjectURL(blob);
|
_this.URL = URL.createObjectURL(blob);
|
||||||
return _this.nodes.el.style.backgroundImage = "url(" + _this.url + ")";
|
return _this.nodes.el.style.backgroundImage = "url(" + _this.URL + ")";
|
||||||
};
|
};
|
||||||
if (c.toBlob) {
|
if (c.toBlob) {
|
||||||
c.toBlob(applyBlob);
|
c.toBlob(applyBlob);
|
||||||
@ -6452,7 +6463,7 @@
|
|||||||
if (!window.URL) {
|
if (!window.URL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return URL.revokeObjectURL(this.url);
|
return URL.revokeObjectURL(this.URL);
|
||||||
};
|
};
|
||||||
|
|
||||||
_Class.prototype.showFileData = function(hide) {
|
_Class.prototype.showFileData = function(hide) {
|
||||||
|
|||||||
@ -409,7 +409,7 @@ QR =
|
|||||||
(QR.posts[index-1] or QR.posts[index+1]).select()
|
(QR.posts[index-1] or QR.posts[index+1]).select()
|
||||||
QR.posts.splice index, 1
|
QR.posts.splice index, 1
|
||||||
return unless window.URL
|
return unless window.URL
|
||||||
URL.revokeObjectURL @url
|
URL.revokeObjectURL @URL
|
||||||
lock: (lock=true) ->
|
lock: (lock=true) ->
|
||||||
@isLocked = lock
|
@isLocked = lock
|
||||||
return unless @ is QR.selected
|
return unless @ is QR.selected
|
||||||
@ -459,23 +459,25 @@ QR =
|
|||||||
@filename = "#{file.name} (#{$.bytesToString file.size})"
|
@filename = "#{file.name} (#{$.bytesToString file.size})"
|
||||||
@nodes.el.title = @filename
|
@nodes.el.title = @filename
|
||||||
@nodes.label.hidden = false if QR.spoiler
|
@nodes.label.hidden = false if QR.spoiler
|
||||||
URL.revokeObjectURL @url if window.URL
|
URL.revokeObjectURL @URL if window.URL
|
||||||
@showFileData()
|
@showFileData()
|
||||||
unless /^image/.test file.type
|
unless /^image/.test file.type
|
||||||
@nodes.el.style.backgroundImage = null
|
@nodes.el.style.backgroundImage = null
|
||||||
return
|
return
|
||||||
|
@setThumbnail()
|
||||||
|
setThumbnail: (fileURL) ->
|
||||||
# XXX Opera does not support blob URL
|
# 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.
|
# Create a redimensioned thumbnail.
|
||||||
fileURL = URL.createObjectURL file
|
unless window.URL
|
||||||
img = $.el 'img'
|
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 = =>
|
img.onload = =>
|
||||||
# Generate thumbnails only if they're really big.
|
# Generate thumbnails only if they're really big.
|
||||||
@ -485,8 +487,8 @@ QR =
|
|||||||
s = 90*3
|
s = 90*3
|
||||||
{height, width} = img
|
{height, width} = img
|
||||||
if height < s or width < s
|
if height < s or width < s
|
||||||
@url = fileURL
|
@URL = fileURL
|
||||||
@nodes.el.style.backgroundImage = "url(#{@url})"
|
@nodes.el.style.backgroundImage = "url(#{@URL})"
|
||||||
return
|
return
|
||||||
if height <= width
|
if height <= width
|
||||||
width = s / height * width
|
width = s / height * width
|
||||||
@ -498,10 +500,14 @@ QR =
|
|||||||
c.height = img.height = height
|
c.height = img.height = height
|
||||||
c.width = img.width = width
|
c.width = img.width = width
|
||||||
c.getContext('2d').drawImage img, 0, 0, width, height
|
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
|
URL.revokeObjectURL fileURL
|
||||||
applyBlob = (blob) =>
|
applyBlob = (blob) =>
|
||||||
@url = URL.createObjectURL blob
|
@URL = URL.createObjectURL blob
|
||||||
@nodes.el.style.backgroundImage = "url(#{@url})"
|
@nodes.el.style.backgroundImage = "url(#{@URL})"
|
||||||
if c.toBlob
|
if c.toBlob
|
||||||
c.toBlob applyBlob
|
c.toBlob applyBlob
|
||||||
return
|
return
|
||||||
@ -524,7 +530,7 @@ QR =
|
|||||||
@nodes.label.hidden = true if QR.spoiler
|
@nodes.label.hidden = true if QR.spoiler
|
||||||
@showFileData()
|
@showFileData()
|
||||||
return unless window.URL
|
return unless window.URL
|
||||||
URL.revokeObjectURL @url
|
URL.revokeObjectURL @URL
|
||||||
showFileData: (hide) ->
|
showFileData: (hide) ->
|
||||||
if @file
|
if @file
|
||||||
QR.nodes.filename.textContent = @filename
|
QR.nodes.filename.textContent = @filename
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user