Source: directives/limitar-texto/limitar_texto.js

/**
 * @ngdoc directives
 * @name LimitarTexto
 * @module s4c.directives.limitartexto.LimitarTexto
 *
 * @description
 * `s4cLimitarTexto` Componente para limitação de campo texto
 *
 *@example
 *   <div class="md-tile-left" s4c-limitar-texto>
 *
 */
(function () {
    'use strict';

    function s4cLimitarTexto($timeout) {
        return {
            restrict: 'A',
            link: function (scope, element, attrs) {
                $timeout(function () {
                    var base = Math.floor(element[0].parentNode.clientWidth / 10);
                    if (base > 0 && scope.node.texto.length > base) {
                        scope.node.texto = scope.node.texto.substr(0, scope.node.texto.length - ((scope.node.texto.length - base) * 2)) + '...';
                    }
                })
            }
        }
    }

    angular.module('s4c.components.limitartexto', [])
        .directive('s4cLimitarTexto', s4cLimitarTexto);

}());