angular.module('app').directive('autogrow', function () {
    return {
        restrict: 'A',
        link: function postLink(scope, element, attrs) {
            // hidding the scroll of textarea
            element.css('overflow', 'hidden');
            var update = function () {
                element.css("height", "auto");
                var height = element[0].scrollHeight;
                if (height > 0) {
                    element.css("height", height + "px");
                }
            };
            scope.$watch(attrs.ngModel, function () {
                update();
            });
            attrs.$set("ngTrim", "false");
        }
    };
});
angular.module('app').directive('capitalize', function () {
    return {
        require: 'ngModel',
        restric: 'A',
        link: function postLink(scope, element, attrs, modelCtrl) {
            var capitalize = function (inputValue) {
                if (typeof (inputValue) === 'undefined') {
                    inputValue = '';
                }
                var capitalized = inputValue.toUpperCase();
                if (capitalized !== inputValue) {
                    // see where the cursor is before the update so that we can set it back
                    var selection = element[0].selectionStart;
                    modelCtrl.$setViewValue(capitalized);
                    modelCtrl.$render();
                    // set back the cursor after rendering
                    element[0].selectionStart = selection;
                    element[0].selectionEnd = selection;
                }
                return capitalized;
            };
            modelCtrl.$parsers.push(capitalize);
            capitalize(scope[attrs.ngModel]); // capitalize initial value
        }
    };
});