├── .editorconfig ├── .jshintrc ├── LICENSE.txt ├── README.md ├── angular-auto-focus.js ├── bower.json └── package.json /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | end_of_line = lf 5 | trim_trailing_whitespace = true 6 | insert_final_newline = true 7 | indent_style = space 8 | indent_size = 4 9 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | } 3 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Myplanet 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # angular-auto-focus 2 | 3 | The HTML autofocus attribute doesn't consistently work across different browsers when an element is inserted into the DOM after the initial page load. angular-auto-focus introduces the auto-focus attribute that works consistently. 4 | 5 | [Demo and documentation](http://myplanet.github.io/angular-auto-focus/) 6 | -------------------------------------------------------------------------------- /angular-auto-focus.js: -------------------------------------------------------------------------------- 1 | (function (root, factory) { 2 | if (typeof define === 'function' && define.amd) { 3 | define([ 'module', 'angular' ], function (module, angular) { 4 | module.exports = factory(angular); 5 | }); 6 | } else if (typeof module === 'object') { 7 | module.exports = factory(require('angular')); 8 | } else { 9 | if (!root.mp) { 10 | root.mp = {}; 11 | } 12 | 13 | root.mp.autoFocus = factory(root.angular); 14 | } 15 | }(this, function (angular) { 16 | 'use strict'; 17 | 18 | return angular.module('mp.autoFocus', []) 19 | .directive('autoFocus', [ '$timeout', function ($timeout) { 20 | return { 21 | restrict: 'A', 22 | 23 | link: function ($scope, $element, $attributes) { 24 | if ($scope.$eval($attributes.autoFocus) !== false) { 25 | var element = $element[0]; 26 | 27 | $timeout(function() { 28 | $scope.$emit('focus', element); 29 | element.focus(); 30 | }); 31 | } 32 | } 33 | }; 34 | } ]); 35 | })); 36 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "angular-auto-focus", 3 | "main": "angular-auto-focus.js", 4 | "homepage": "https://github.com/myplanet/angular-auto-focus", 5 | "authors": [ 6 | "Ates Goral " 7 | ], 8 | "description": "Bullet-proof auto-focusing for Angular", 9 | "moduleType": [ 10 | "amd", 11 | "globals", 12 | "node" 13 | ], 14 | "keywords": [ 15 | "autofocus", 16 | "focus" 17 | ], 18 | "license": "MIT" 19 | } 20 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "angular-auto-focus", 3 | "version": "1.0.4", 4 | "description": "Bullet-proof auto-focusing for Angular", 5 | "main": "angular-auto-focus.js", 6 | "repository": { 7 | "type": "git", 8 | "url": "git://github.com/myplanet/angular-auto-focus.git" 9 | }, 10 | "keywords": [ 11 | "angular", 12 | "autofocus", 13 | "focus" 14 | ], 15 | "author": "Ates Goral ", 16 | "license": "MIT", 17 | "bugs": { 18 | "url": "https://github.com/myplanet/angular-auto-focus/issues" 19 | } 20 | } 21 | --------------------------------------------------------------------------------