Commit | Line | Data |
---|---|---|
0b5469cd C |
1 | (function (angular, $, _) { |
2 | ||
3 | angular.module('crmCxn').factory('crmCxnCheckAddr', function($q, $timeout) { | |
4 | var TIMEOUT = 6000, CHECK_ADDR = 'https://mycivi.org/check-addr'; | |
5 | return function(url) { | |
6 | var dfr = $q.defer(), result = null; | |
7 | ||
8 | function onErr() { | |
9 | if (result !== null) return; | |
10 | result = {url: url, valid: false}; | |
11 | dfr.resolve(result); | |
12 | } | |
13 | ||
14 | $.ajax({ | |
15 | url: CHECK_ADDR, | |
16 | data: {url: url}, | |
17 | jsonp: "callback", | |
18 | dataType: "jsonp" | |
19 | }).fail(onErr) | |
20 | .done(function(response) { | |
21 | if (result !== null) return; | |
22 | result = {url: url, valid: response.result}; | |
23 | dfr.resolve(result); | |
24 | } | |
25 | ); | |
26 | // JSONP may not provide errors directly. | |
27 | $timeout(onErr, TIMEOUT); | |
28 | ||
29 | return dfr.promise; | |
30 | }; | |
31 | }); | |
32 | ||
33 | })(angular, CRM.$, CRM._); |