Permalink
Browse files

added support for ajax response pre-processors

  • Loading branch information...
1 parent f637ca1 commit 4abba5a3b113663ef0cf069a3bd3a40267d846ef @juzna committed Jan 13, 2011
Showing with 24 additions and 0 deletions.
  1. +9 −0 src/prototype/ajax/ajax.js
  2. +15 −0 src/prototype/ajax/request.js
View
9 src/prototype/ajax/ajax.js
@@ -44,5 +44,14 @@ var Ajax = {
getHeaderCreators: function() {
return Ajax._headerCreators;
+ },
+
+ /**
+ * List of pre-processors which will be executed on received ajax responses. It may change them
+ */
+ _responsePreProcessors: [],
+
+ addResponsePreProcessor: function(cb) {
+ Ajax._responsePreProcessors.push(cb);
}
};
View
15 src/prototype/ajax/request.js
@@ -305,6 +305,21 @@ Ajax.Request = Class.create(Ajax.Base, {
var state = Ajax.Request.Events[readyState], response = new Ajax.Response(this);
if (state == 'Complete') {
+ // Execute pre-processors first
+ var shouldEnd = false;
+ Ajax._responsePreProcessors.each(function(cb) {
+ if(cb(this) === false) {
+ shouldEnd = true;
+ return $break;
+ }
+ }, this);
+ if(shouldEnd) {
+ // avoid memory leak in MSIE: clean up
+ this.transport.onreadystatechange = Prototype.emptyFunction;
+
+ return;
+ }
+
try {
this._complete = true;
(this.options['on' + response.status]

0 comments on commit 4abba5a

Please sign in to comment.