From b362ea0fcc992d0468772384ee77be7069d24dc7 Mon Sep 17 00:00:00 2001 From: Brad Dunbar Date: Tue, 4 Mar 2014 11:35:31 -0500 Subject: [PATCH] Fix #3015 - History#stop cleans up iframe. --- backbone.js | 8 ++++++++ test/collection.js | 18 +++++++++++------- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/backbone.js b/backbone.js index 99713a8b9..5fcda3f05 100644 --- a/backbone.js +++ b/backbone.js @@ -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; diff --git a/test/collection.js b/test/collection.js index a3b9209cc..0f9d0d4cd 100644 --- a/test/collection.js +++ b/test/collection.js @@ -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() { @@ -1358,4 +1361,5 @@ collection.first().set({id: 1}, {silent: true}); equal(collection.get(1), collection.first()); }); + })();