Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

Commit

Permalink
Merge pull request #10 from kjarmicki/issue#9
Browse files Browse the repository at this point in the history
Issue #9. Guard against non-existing iframes in resize.
  • Loading branch information
sveisvei committed Nov 24, 2014
2 parents 77235eb + 4c58078 commit 4d21b3d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/iframe.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,12 @@ Iframe.prototype.remove = function() {
Iframe.prototype.resize = function(w, h) {
if (w) { this.width = w; }
if (h) { this.height = h; }
this.element.style.width = validSize(this.width);
this.element.style.height = validSize(this.height);

if (this.element && this.element.style) {
this.element.style.width = validSize(this.width);
this.element.style.height = validSize(this.height);
}

return this;
};

Expand Down
11 changes: 11 additions & 0 deletions test/iframe.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,15 @@ describe('iframe', function () {
expect(iframe.element.style.width).to.equal('250px');
expect(iframe.element.style.height).to.equal('200px');
});

it('should not throw an error when resizing if element was removed', function() {
var iframe = new Iframe('resize-test', {width:100, height:100, iframeUrl:'about:blank'});
var fakeParent = document.createElement('div');

iframe.makeIframe();
fakeParent.appendChild(iframe.wrapper);
iframe.remove();
expect(iframe.resize).to.not.throw(Error);
});

});

0 comments on commit 4d21b3d

Please sign in to comment.