From d4e4fcf1c3d9238529b82c086944193301cb2964 Mon Sep 17 00:00:00 2001 From: kpdecker Date: Thu, 10 Jul 2014 01:51:02 -0500 Subject: [PATCH] Add dispose logic for jQuery objects Partial fix for #37 --- lib/jquery/ajax.js | 3 +++ lib/jquery/index.js | 9 ++++++++- lib/page.js | 3 ++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/jquery/ajax.js b/lib/jquery/ajax.js index 70343c9..57e3533 100644 --- a/lib/jquery/ajax.js +++ b/lib/jquery/ajax.js @@ -59,6 +59,9 @@ module.exports = exports = function Ajax(window, exec, ajaxCache) { this.removeAllListeners(); }; + ajax.dispose = function() { + window = window.$.ajax = undefined; + }; window.$.ajax = function(options) { var originalUrl = options.url, diff --git a/lib/jquery/index.js b/lib/jquery/index.js index f9088c5..45459b4 100644 --- a/lib/jquery/index.js +++ b/lib/jquery/index.js @@ -121,10 +121,17 @@ module.exports = exports = function jQuery(window, html, exec, ajaxCache) { window.jQuery = window.Zepto = window.$ = $; + var ajaxInstance = ajax(window, exec, ajaxCache); return { $: $, root: root, - ajax: ajax(window, exec, ajaxCache) + ajax: ajaxInstance, + + dispose: function() { + ajaxInstance.dispose(); + + window = window.jQuery = window.Zepto = window.$ = undefined; + } }; }; diff --git a/lib/page.js b/lib/page.js index bddfbbc..9ad84e4 100644 --- a/lib/page.js +++ b/lib/page.js @@ -234,6 +234,7 @@ module.exports = exports = function(options) { function loadPage(src) { $ = page.$ = jQuery(window, src, exec, ajaxCache); + toCleanup.push($); pending.push('beforeExec', 1); if (options.beforeExec) { @@ -321,7 +322,7 @@ module.exports = exports = function(options) { options = callback = window = baseContext = context = toReset = toCleanup = location = $ = - window.FruitLoops = + window.FruitLoops = window.emit = window.onEmit = window.loadInContext = emitCallbacks = scripts = page.window = page.emit = page.$ = undefined; },