# all files / Core/Components/GiveFocus/ GiveFocusDirective.js

41.67% Statements 5/12
0% Branches 0/2
0% Functions 0/3
41.67% Lines 5/12

    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

    1

    1

    1

    1

    1
     'use strict';

    // Utilities:
    var _ = require('lodash');

    // Module:
    var Core = require('../../Core');

    var GiveFocusDirective = function () {
        return {
            restrict: 'A',

            scope: {
                focusOn: '='
            },

            link: link
        };

        function link ($scope, $element) {
            $scope.$watch('focusOn', function (currentValue) {
                var input = _.first($element);
                if (currentValue) {
                    input.focus();
                    input.select();
                } else {
                    input.blur();
                }
            });
        }
    };

    Core.directive('tractorGiveFocus', GiveFocusDirective);