-
Notifications
You must be signed in to change notification settings - Fork 0
/
directives.js
41 lines (36 loc) · 1.11 KB
/
directives.js
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
angular.module('notelendar')
.directive('nrFocus', ['$timeout', function ($timeout) {
return function (scope, elem, attrs) {
scope.$watch(attrs.nrFocus, function (val) {
if (val) $timeout(function () { elem[0].focus(); }, 0, false);
});
}
}])
.directive('nrCtrlEnter', function () {
var ENTER_KEY_CODE = 13;
return function (scope, elem, attrs) {
elem.bind('keydown', function (e) {
if (e.ctrlKey && e.keyCode === ENTER_KEY_CODE) {
scope.$apply(attrs.nrCtrlEnter);
}
});
}
})
.directive('nrOverflowTitle', function () {
return function (scope, elem, attrs) {
scope.$watch(
function () {
return elem.html();
},
function () {
var _elem = elem[0];
if (_elem.scrollWidth - _elem.clientWidth > 1
|| _elem.scrollHeight - _elem.clientHeight > 1) {
_elem.title = elem.html();
} else {
_elem.title = '';
}
}
);
};
});