var angular = require('angular');
require('../modules');
'use strict';

/**
 * 信息发布Detail页面 缓存服务
 */
var module = angular.module('info.directives');

module.directive('addRight', function($timeout) {
  return {
    restrict: 'C',
    link: function(scope, element, attrs) {
      var promise = $timeout(function() {
        var rightWidth = element[0].getBoundingClientRect().width,
          leftWidth = element[0].previousElementSibling.getBoundingClientRect().width,
          screenWidth = screen.width;
        if(leftWidth + rightWidth > screenWidth - 20) {
          element[0].style.width = '50%';
          element[0].style.whiteSpace = 'nowrap';
          element[0].style.overflow = 'hidden';
          element[0].style.textOverflow = 'ellipsis';
        }
      }, 16);

      scope.$on('$destroy', function() {
        $timeout.cancel(promise);
      });
    }
  };
});