-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathangular-pwned-directive.js
More file actions
33 lines (33 loc) · 964 Bytes
/
angular-pwned-directive.js
File metadata and controls
33 lines (33 loc) · 964 Bytes
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
angular.module('angular.pwned', [])
.directive('pwned', ['$http', '$timeout', function($http, $timeout) {
return {
require: 'ngModel',
link: function postLink(scope, ele, attrs, c) {
var timerId = null;
var timerDelay = 1000; // Delay time in milliseconds
scope.$watch(attrs.ngModel, function(newValue, oldValue) {
if( timerId != null ) {
$timeout.cancel(timerId);
timerId = null;
}
function doGet() {
$http({
method:'GET',
url:'https://haveibeenpwned.com/api/v2/breachedaccount/' + ele[0].value
}).success(function(data, status, headers, cfg) {
timerId = null;
scope[attrs.pwned] = data;
c.$setValidity('ispwned', false);
}).error(function(data, status, headers, cfg) {
timerId = null;
scope[attrs.pwned] = undefined;
c.$setValidity('ispwned', true);
});
}
if (ele[0].value !== "") {
timerId = $timeout(doGet, timerDelay);
}
})
}
}
}]);