forked from johngeorgewright/angular-xml
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathangular-xml.js
More file actions
55 lines (48 loc) · 1.27 KB
/
angular-xml.js
File metadata and controls
55 lines (48 loc) · 1.27 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
(function(ng) {
'use strict';
var X2JS = require('x2js');
function responseIsXml(response) {
var contentType = response.headers('content-type');
if (contentType) {
return contentType.search(/\Wxml/i) > -1;
} else {
return false;
}
}
function xmlHttpInterceptorFactory($q, x2js) {
function responseHandler(response) {
if (response && responseIsXml(response)) {
response.data = x2js.xml_str2json(response.data);
return response;
} else {
return $q.when(response);
}
}
function responseErrorHandler(response) {
if (response && responseIsXml(response)) {
response.data = x2js.xml_str2json(response.data);
}
return $q.reject(response);
}
return {
response: responseHandler,
responseError: responseErrorHandler
};
}
function configProvider($provide) {
$provide.factory('xmlHttpInterceptor', ['$q', 'x2js', xmlHttpInterceptorFactory]);
}
function X2JSProvider() {
this.config = {};
this.$get = ['X2JS', function (X2JS) {
return new X2JS(this.config);
}];
}
if (ng) {
ng
.module('xml', [])
.config(['$provide', configProvider])
.provider('x2js', X2JSProvider)
.value('X2JS', X2JS);
}
}(angular));