| Total Complexity | 11 |
| Complexity/F | 1.38 |
| Lines of Code | 45 |
| Function Count | 8 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | (function () { |
||
| 2 | 'use strict'; |
||
| 3 | |||
| 4 | /** |
||
| 5 | * @ngdoc function |
||
| 6 | * @name passmanApp.controller:MainCtrl |
||
| 7 | * @description |
||
| 8 | * # MainCtrl |
||
| 9 | * Controller of the passmanApp |
||
| 10 | */ |
||
| 11 | angular.module('passmanExtension').directive('ngDebounce', function ($timeout) { |
||
| 12 | return { |
||
| 13 | restrict: 'A', |
||
| 14 | require: 'ngModel', |
||
| 15 | priority: 99, |
||
| 16 | link: function (scope, elm, attr, ngModelCtrl) { |
||
| 17 | if (attr.type === 'radio' || attr.type === 'checkbox') { |
||
| 18 | return; |
||
| 19 | } |
||
| 20 | |||
| 21 | var delay = parseInt(attr.ngDebounce, 10); |
||
| 22 | if (isNaN(delay)) { |
||
| 23 | delay = 1000; |
||
| 24 | } |
||
| 25 | |||
| 26 | elm.unbind('input'); |
||
| 27 | |||
| 28 | var debounce; |
||
| 29 | elm.bind('input', function () { |
||
| 30 | $timeout.cancel(debounce); |
||
| 31 | debounce = $timeout(function () { |
||
| 32 | scope.$apply(function () { |
||
| 33 | ngModelCtrl.$setViewValue(elm.val()); |
||
| 34 | }); |
||
| 35 | }, delay); |
||
| 36 | }); |
||
| 37 | elm.bind('blur', function () { |
||
| 38 | scope.$apply(function () { |
||
| 39 | ngModelCtrl.$setViewValue(elm.val()); |
||
| 40 | }); |
||
| 41 | }); |
||
| 42 | } |
||
| 43 | }; |
||
| 44 | }); |
||
| 45 | }()); |
||
| 46 | |||
| 47 |