Use link+blob urls for the stylesheet. That'll help me inspect the css.

I wonder if it matters performance-wise.
This commit is contained in:
Nicolas Stepien 2013-02-14 17:28:03 +01:00
parent 270f7f8ec2
commit b91d343679
4 changed files with 44 additions and 23 deletions

View File

@ -733,10 +733,17 @@
return setTimeout($.asap, 25, test, cb);
}
},
addStyle: function(css) {
addStyle: function(css, type) {
var style;
style = $.el('style', {
style = type === 'style' || !window.URL ? $.el('style', {
textContent: css
}) : $.el('link', {
rel: 'stylesheet',
href: URL.createObjectURL(new Blob([css]))
}, {
type: 'text/css'
}, {
title: g.NAMESPACE
});
$.asap((function() {
return d.head;
@ -3505,7 +3512,7 @@
if (checked) {
$.on(window, 'resize', ImageExpand.resize);
if (!ImageExpand.style) {
ImageExpand.style = $.addStyle('');
ImageExpand.style = $.addStyle(null, 'style');
}
return ImageExpand.resize();
} else {
@ -4474,7 +4481,7 @@
}
_Class.prototype.setFile = function(file) {
var fileUrl, img, url,
var fileUrl, img,
_this = this;
this.file = file;
this.el.title = "" + file.name + " (" + ($.bytesToString(file.size)) + ")";
@ -4485,10 +4492,10 @@
this.el.style.backgroundImage = null;
return;
}
if (!(url = window.URL || window.webkitURL)) {
if (!window.URL) {
return;
}
url.revokeObjectURL(this.url);
URL.revokeObjectURL(this.url);
fileUrl = url.createObjectURL(file);
img = $.el('img');
$.on(img, 'load', function() {
@ -4516,17 +4523,16 @@
for (i = _i = 0; 0 <= l ? _i < l : _i > l; i = 0 <= l ? ++_i : --_i) {
ui8a[i] = data.charCodeAt(i);
}
_this.url = url.createObjectURL(new Blob([ui8a], {
_this.url = URL.createObjectURL(new Blob([ui8a], {
type: 'image/png'
}));
_this.el.style.backgroundImage = "url(" + _this.url + ")";
return typeof url.revokeObjectURL === "function" ? url.revokeObjectURL(fileUrl) : void 0;
return URL.revokeObjectURL(fileUrl);
});
return img.src = fileUrl;
};
_Class.prototype.rmFile = function() {
var _base;
QR.resetFileInput();
delete this.file;
this.el.title = null;
@ -4534,7 +4540,10 @@
if (QR.spoiler) {
$('label', this.el).hidden = true;
}
return typeof (_base = window.URL || window.webkitURL).revokeObjectURL === "function" ? _base.revokeObjectURL(this.url) : void 0;
if (!window.URL) {
return;
}
return URL.revokeObjectURL(this.url);
};
_Class.prototype.select = function() {
@ -4599,7 +4608,7 @@
};
_Class.prototype.rm = function() {
var index, _ref;
var index;
QR.resetFileInput();
$.rm(this.el);
index = QR.replies.indexOf(this);
@ -4609,7 +4618,10 @@
(QR.replies[index - 1] || QR.replies[index + 1]).select();
}
QR.replies.splice(index, 1);
return (_ref = window.URL || window.webkitURL) != null ? _ref.revokeObjectURL(this.url) : void 0;
if (!window.URL) {
return;
}
return URL.revokeObjectURL(this.url);
};
return _Class;

View File

@ -83,9 +83,16 @@ $.extend $,
cb()
else
setTimeout $.asap, 25, test, cb
addStyle: (css) ->
style = $.el 'style',
textContent: css
addStyle: (css, type) ->
style = if type is 'style' or !window.URL
$.el 'style',
textContent: css
else
$.el 'link',
rel: 'stylesheet'
href: URL.createObjectURL new Blob [css],
type: 'text/css'
title: g.NAMESPACE
$.asap (-> d.head), ->
$.add d.head, style
style

View File

@ -2134,7 +2134,7 @@ ImageExpand =
if checked
$.on window, 'resize', ImageExpand.resize
unless ImageExpand.style
ImageExpand.style = $.addStyle ''
ImageExpand.style = $.addStyle null, 'style'
ImageExpand.resize()
else
$.off window, 'resize', ImageExpand.resize

View File

@ -351,9 +351,9 @@ QR =
unless /^image/.test file.type
@el.style.backgroundImage = null
return
# XXX Opera does not support window.URL
return unless url = window.URL or window.webkitURL
url.revokeObjectURL @url
# XXX Opera does not support blob URL
return unless window.URL
URL.revokeObjectURL @url
# Create a redimensioned thumbnail.
fileUrl = url.createObjectURL file
@ -388,9 +388,9 @@ QR =
for i in [0...l]
ui8a[i] = data.charCodeAt i
@url = url.createObjectURL new Blob [ui8a], type: 'image/png'
@url = URL.createObjectURL new Blob [ui8a], type: 'image/png'
@el.style.backgroundImage = "url(#{@url})"
url.revokeObjectURL? fileUrl
URL.revokeObjectURL fileUrl
img.src = fileUrl
rmFile: ->
@ -399,7 +399,8 @@ QR =
@el.title = null
@el.style.backgroundImage = null
$('label', @el).hidden = true if QR.spoiler
(window.URL or window.webkitURL).revokeObjectURL? @url
return unless window.URL
URL.revokeObjectURL @url
select: ->
QR.selected?.el.id = null
QR.selected = @
@ -446,7 +447,8 @@ QR =
else if @el.id is 'selected'
(QR.replies[index-1] or QR.replies[index+1]).select()
QR.replies.splice index, 1
(window.URL or window.webkitURL)?.revokeObjectURL @url
return unless window.URL
URL.revokeObjectURL @url
captcha:
init: ->