mirror of
https://github.com/DeviceFarmer/stf.git
synced 2026-04-18 16:13:24 +02:00
23 lines
521 B
JavaScript
23 lines
521 B
JavaScript
module.exports = function focusElementDirective($parse, $timeout) {
|
|
return {
|
|
restrict: 'A',
|
|
link: function (scope, element, attrs) {
|
|
var model = $parse(attrs.focusElement)
|
|
|
|
scope.$watch(model, function (value) {
|
|
if (value === true) {
|
|
$timeout(function () {
|
|
element[0].focus()
|
|
})
|
|
}
|
|
})
|
|
|
|
element.bind('blur', function () {
|
|
if (model && model.assign) {
|
|
scope.$apply(model.assign(scope, false))
|
|
}
|
|
})
|
|
}
|
|
}
|
|
}
|