Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added ajax:stopped event firing

Added: handling onComplete where firing element is inside the element that will be updated
  • Loading branch information...
commit cdb973d20675668ecf26ab0dd65f3eabb7b50991 1 parent 5e5e57b
@mathieurousseau mathieurousseau authored
Showing with 17 additions and 4 deletions.
  1. +17 −4 src/rails.js
View
21 src/rails.js
@@ -85,7 +85,10 @@
var method, url, params;
var event = element.fire("ajax:before");
- if (event.stopped) return false;
+ if (event.stopped) {
+ element.fire("ajax:stopped");
+ return false;
+ }
if (element.tagName.toLowerCase() === 'form') {
method = element.readAttribute('method') || 'post';
@@ -106,9 +109,19 @@
evalScripts: true,
onCreate: function(response) { element.fire("ajax:create", response); },
- onComplete: function(response) { element.fire("ajax:complete", response); },
- onSuccess: function(response) { element.fire("ajax:success", response); },
- onFailure: function(response) { element.fire("ajax:failure", response); }
+ onComplete: function(request) {
+ if(!$(element).descendantOf(document)){
+ if(!$("rails_reserved_garbage")){
+ (document.body).insert('<div style="display:none;" id="rails_reserved_garbage"></div>');
+ }
+ $("rails_reserved_garbage").update(element);
+ }
+ element.fire("ajax:complete", request);
+ $("rails_reserved_garbage").remove(element);
+ },
+ onSuccess: function(request) { element.fire("ajax:success", request); },
+ onFailure: function(request) { element.fire("ajax:failure", request); }
+
});
element.fire("ajax:after");
Please sign in to comment.
Something went wrong with that request. Please try again.