-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathangular-auto-focus.js
35 lines (31 loc) · 1.07 KB
/
angular-auto-focus.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
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define([ 'module', 'angular' ], function (module, angular) {
module.exports = factory(angular);
});
} else if (typeof module === 'object') {
module.exports = factory(require('angular'));
} else {
if (!root.mp) {
root.mp = {};
}
root.mp.autoFocus = factory(root.angular);
}
}(this, function (angular) {
'use strict';
return angular.module('mp.autoFocus', [])
.directive('autoFocus', [ '$timeout', function ($timeout) {
return {
restrict: 'A',
link: function ($scope, $element, $attributes) {
if ($scope.$eval($attributes.autoFocus) !== false) {
var element = $element[0];
$timeout(function() {
$scope.$emit('focus', element);
element.focus();
});
}
}
};
} ]);
}));