Skip to content
This repository has been archived by the owner on Mar 20, 2021. It is now read-only.

Commit

Permalink
Add dispose logic for jQuery objects
Browse files Browse the repository at this point in the history
Partial fix for #37
  • Loading branch information
kpdecker committed Jul 10, 2014
1 parent c9fb8d8 commit d4e4fcf
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions lib/jquery/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 8 additions & 1 deletion lib/jquery/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};
};

Expand Down
3 changes: 2 additions & 1 deletion lib/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
},
Expand Down

0 comments on commit d4e4fcf

Please sign in to comment.