Skip to content

Commit

Permalink
Merge pull request #3041 from braddunbar/iframe-cleanup
Browse files Browse the repository at this point in the history
Fix #3015 - History#stop cleans up iframe.
  • Loading branch information
jashkenas committed Mar 4, 2014
2 parents 5552443 + b362ea0 commit e0233d8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
8 changes: 8 additions & 0 deletions backbone.js
Original file line number Diff line number Diff line change
Expand Up @@ -1494,11 +1494,19 @@
return detachEvent('on' + eventName, listener);
};

// Remove window listeners.
if (this._hasPushState) {
removeEventListener('popstate', this.checkUrl, false);
} else if (this._wantsHashChange && this._hasHashChange && !this.iframe) {
removeEventListener('hashchange', this.checkUrl, false);
}

// Clean up the iframe if necessary.
if (this.iframe) {
document.body.removeChild(this.iframe.frameElement);
this.iframe = null;
}

// Some environments will throw when clearing an undefined interval.
if (this._checkUrlInterval) clearInterval(this._checkUrlInterval);
History.started = false;
Expand Down
18 changes: 11 additions & 7 deletions test/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,17 @@
});

test("clone preserves model and comparator", 3, function() {
var Model = Backbone.Model.extend(),
comparator = function() {};
var Model = Backbone.Model.extend();
var comparator = function(model){ return model.id; };

var col = (new Backbone.Collection([{id: 1}], {model: Model, comparator: comparator})).clone();
col.add({id: 2});
ok(col.at(0) instanceof Model);
ok(col.at(1) instanceof Model);
strictEqual(col.comparator, comparator);
var collection = new Backbone.Collection([{id: 1}], {
model: Model,
comparator: comparator
}).clone();
collection.add({id: 2});
ok(collection.at(0) instanceof Model);
ok(collection.at(1) instanceof Model);
strictEqual(collection.comparator, comparator);
});

test("get", 6, function() {
Expand Down Expand Up @@ -1358,4 +1361,5 @@
collection.first().set({id: 1}, {silent: true});
equal(collection.get(1), collection.first());
});

})();

0 comments on commit e0233d8

Please sign in to comment.