-
Notifications
You must be signed in to change notification settings - Fork 4
/
ng-phpdebugbar.js
42 lines (41 loc) · 1.58 KB
/
ng-phpdebugbar.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
(function() {
'use strict';
var handle_phpdebugbar_response = function(response) {
if (phpdebugbar && phpdebugbar.ajaxHandler) {
// We have a debugbar and an ajaxHandler
// Dig through response to look for the
// debugbar id.
var headers = response && response.headers && response.headers();
if (!headers) {
return;
}
// Not very elegant, but this is how the debugbar.js defines the header.
var headerName = phpdebugbar.ajaxHandler.headerName + '-id';
var debugBarID = headers[headerName];
if (debugBarID) {
// A debugBarID was found! Now we just pass the
// id to the debugbar to load the data
phpdebugbar.loadDataSet(debugBarID, ('ajax'));
}
}
};
angular.module('ng-phpdebugbar', [])
.factory('phpDebugBarInterceptor', ['$q', function($q) {
return {
'response': function(response) {
handle_phpdebugbar_response(response);
return response;
},
'responseError': function(rejection) {
handle_phpdebugbar_response(rejection);
return $q.reject(rejection);
}
};
}])
.config(['$httpProvider',
function($httpProvider) {
// Adds our debug interceptor to all $http requests
$httpProvider.interceptors.push('phpDebugBarInterceptor');
}
]);
})();