Skip to content

Commit

Permalink
dia.Paper: cancel previous background image load (#1551)
Browse files Browse the repository at this point in the history
  • Loading branch information
kumilingus authored Oct 14, 2021
1 parent cb2a9db commit 37e2a4f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/dia/Paper.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
getByPath,
sortElements,
isString,
guid,
normalizeEvent,
omit,
result,
Expand Down Expand Up @@ -2481,6 +2482,11 @@ export const Paper = View.extend({
return;
}

if (!this._background || this._background.id !== opt.id) {
// Draw only the last image requested (see drawBackground())
return;
}

opt = opt || {};

var backgroundImage;
Expand Down Expand Up @@ -2547,6 +2553,7 @@ export const Paper = View.extend({

if (opt.image) {
opt = this._background = cloneDeep(opt);
guid(opt);
var img = document.createElement('img');
img.onload = this.drawBackgroundImage.bind(this, img, opt);
img.src = opt.image;
Expand Down
22 changes: 22 additions & 0 deletions test/jointjs/paper.js
Original file line number Diff line number Diff line change
Expand Up @@ -1770,6 +1770,28 @@ QUnit.module('paper', function(hooks) {
);
});

QUnit.test('image cancellation', function(assert) {

assert.expect(1);

var done = assert.async();
var paper = this.paper;

paper.drawBackground({ image: bgImageDataURL });
paper.drawBackground({ image: null });

setTimeout(
function() {
assert.equal(
getUrlFromAttribute(paper.$background.css('backgroundImage')),
null
);
done();
},
0
);
});

QUnit.test('opacity', function(assert) {

assert.expect(1);
Expand Down

0 comments on commit 37e2a4f

Please sign in to comment.