Skip to content

Instantly share code, notes, and snippets.

@ajshort
Created January 31, 2011 23:29
Show Gist options
  • Select an option

  • Save ajshort/805059 to your computer and use it in GitHub Desktop.

Select an option

Save ajshort/805059 to your computer and use it in GitHub Desktop.
Fixes callback handlers not being passed the correct context.
Index: javascript/core/jquery.ondemand.js
===================================================================
--- javascript/core/jquery.ondemand.js (revision 115901)
+++ javascript/core/jquery.ondemand.js (working copy)
@@ -150,12 +150,15 @@
// This replaces the usual ajax success & complete handlers. They are called after any on demand JS is loaded.
var _ondemandComplete = function(xml, status) {
- var status = $.httpSuccess(xml) ? 'success' : 'error';
+ var status = $.httpSuccess(xml) ? 'success' : 'error';
+ var context = s && s.context || $;
+
if(status == 'success') {
var data = jQuery.httpData(xml, _dataType);
- if(_success) _success(data, status);
+ if(_success) _success.call(context, data, status);
}
- if(_complete) _complete(xml, status);
+
+ if(_complete) _complete.call(context, xml, status);
}
// We remove the success handler and take care of calling it outselves within _ondemandComplete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment