Files
meanTorrent/modules/core/client/directives/auto-focus.client.directive.js
Michael Leanos baa291af4e fix(core): Directive file naming convention (#1558)
Renames show-error & autofocus directives to conform to naming
conventions.

Fixes: https://github.com/meanjs/mean/issues/1233
2016-10-11 20:45:06 -07:00

29 lines
594 B
JavaScript

(function () {
'use strict';
// Focus the element on page load
// Unless the user is on a small device, because this could obscure the page with a keyboard
angular.module('core')
.directive('autofocus', autofocus);
autofocus.$inject = ['$timeout', '$window'];
function autofocus($timeout, $window) {
var directive = {
restrict: 'A',
link: link
};
return directive;
function link(scope, element, attrs) {
if ($window.innerWidth >= 800) {
$timeout(function() {
element[0].focus();
}, 100);
}
}
}
}());