From 137aa531561482154b16916a4bac0b70076158a4 Mon Sep 17 00:00:00 2001 From: Mateusz Uzdowski Date: Fri, 23 Aug 2013 09:39:38 +1200 Subject: [PATCH] Return jQuery deferred object from LeftAndMain's loadFragment. --- admin/javascript/LeftAndMain.js | 2 ++ docs/en/reference/cms-architecture.md | 11 ++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/admin/javascript/LeftAndMain.js b/admin/javascript/LeftAndMain.js index b349f1ba5..3f13a94bc 100644 --- a/admin/javascript/LeftAndMain.js +++ b/admin/javascript/LeftAndMain.js @@ -542,6 +542,8 @@ jQuery.noConflict(); // Store the fragment request so we can abort later, should we get a duplicate request. fragmentXHR[pjaxFragments] = xhr; + + return xhr; }, /** diff --git a/docs/en/reference/cms-architecture.md b/docs/en/reference/cms-architecture.md index 7a2248330..bae6e31ee 100644 --- a/docs/en/reference/cms-architecture.md +++ b/docs/en/reference/cms-architecture.md @@ -319,7 +319,7 @@ Upon the receipt of the response, the fragment will be injected into DOM where a has been found on an element (this element will get completely replaced). Afterwards a `afterloadfragment` event will be triggered. In case of a request error a `loadfragmenterror` will be raised and DOM will not be touched. -You can hook up a response handler that obtains all the details of the XHR request like this: +You can hook up a response handler that obtains all the details of the XHR request via Entwine handler: 'from .cms-container': { onafterloadfragment: function(e, data) { @@ -328,6 +328,15 @@ You can hook up a response handler that obtains all the details of the XHR reque } } +Alternatively you can use the jQuery deferred API: + + $('.cms-container') + .loadFragment('admin/foobar/', 'Fragment1') + .success(function(data, status, xhr) { + // Say 'success'! + alert(status); + }); + ## Ajax Redirects Sometimes, a server response represents a new URL state, e.g. when submitting an "add record" form,