use on-load event to trigger resizable images

instead of timeout, which could get incorrect size information.

closes #5219
This commit is contained in:
MinRK 2014-02-25 10:41:26 -08:00
parent 0117b587ab
commit 983271a36f

View File

@ -564,15 +564,13 @@ var IPython = (function (IPython) {
OutputArea.prototype._dblclick_to_reset_size = function (img) { OutputArea.prototype._dblclick_to_reset_size = function (img) {
// schedule wrapping image in resizable after a delay, // wrap image after it's loaded on the page,
// so we don't end up calling resize on a zero-size object // otherwise the measured initial size will be incorrect
var that = this; img.on("load", function (){
setTimeout(function () {
var h0 = img.height(); var h0 = img.height();
var w0 = img.width(); var w0 = img.width();
if (!(h0 && w0)) { if (!(h0 && w0)) {
// zero size, schedule another timeout // zero size, don't make it resizable
that._dblclick_to_reset_size(img);
return; return;
} }
img.resizable({ img.resizable({
@ -586,7 +584,7 @@ var IPython = (function (IPython) {
img.parent().width(w0); img.parent().width(w0);
img.width(w0); img.width(w0);
}); });
}, 250); });
}; };
var set_width_height = function (img, md, mime) { var set_width_height = function (img, md, mime) {