Completed
Push — phpunit ( 7f2080...75f541 )
by Marcos
14:28 queued 10:45
created

js/app/directives/clearbutton2.js   A

Complexity

Total Complexity 7
Complexity/F 1.4

Size

Lines of Code 35
Function Count 5

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
c 1
b 0
f 0
nc 2
dl 0
loc 35
rs 10
wmc 7
mnd 1
bc 7
fnc 5
bpm 1.4
cpm 1.4
noi 0

1 Function

Rating   Name   Duplication   Size   Complexity  
B angular.directive(ꞌclearBtnꞌ) 0 25 1
1
(function () {
2
	'use strict';
3
	/**
4
	 * @ngdoc directive
5
	 * @name passmanApp.directive:clearBtn
6
	 * @description
7
	 * # clearBtn
8
	 */
9
	angular.module('passmanApp')
10
		.directive('clearBtn', ['$parse', function ($parse) {
11
            return {
12
                link: function (scope, elm, attr) {
13
                    elm.wrap("<div style='position: relative'></div>");
14
                    var btn = '<span id=' + Math.round(Math.random() * 1000000000) + ' class="searchclear ng-hide fa fa-times-circle-o"></span>';
15
                    var angularBtn = angular.element(btn);
16
                    elm.after(angularBtn);
17
                    //clear the input
18
                    angularBtn.on("click", function () {
19
                        elm.val('').trigger("change");
20
                        $parse(attr.ngModel).assign(scope, '');
21
                        scope.$apply();
22
                    });
23
24
                    // show  clear btn  on focus
25
                    elm.bind('focus keyup change paste propertychange', function () {
26
                        if (elm.val() && elm.val().length > 0) {
27
                            angularBtn.removeClass("ng-hide");
28
                        } else {
29
                            angularBtn.addClass("ng-hide");
30
                        }
31
                    });
32
                }
33
            };
34
        }]);
35
}());
36
37
38