Ng crop text filter (2 Chinese and 1 English)

From , 5 Years ago, written in JavaScript, viewed 227 times.
URL https://pastebin.vip/view/8fe0093b
  1. /* globals angular: false */
  2.  
  3. angular.module(window.appModule).filter('cut', function () {
  4.     return function (value, wordwise, max, tail) {
  5.         if (!value) return '';
  6.         if(!wordwise){
  7.             return value;
  8.         }
  9.         max = parseInt(max, 10);
  10.         if (!max) return value;
  11.         str_cut = new String();
  12.         for(var i = 0,str_length = 0;i<value.length;i++)
  13.         {
  14.             var  a = value.charAt(i);
  15.             str_length++;
  16.             if(escape(a).length > 4)
  17.             {
  18.                 //中文字符的长度经编码之后大于4
  19.                 str_length++;
  20.             }
  21.             str_cut = str_cut.concat(a);
  22.             if(str_length>=max)
  23.             {
  24.                 return str_cut+ (tail || ' …');
  25.             }
  26.         }
  27.         return value
  28.     };
  29. });

Reply to "Ng crop text filter (2 Chinese and 1 English)"

Here you can reply to the paste above

captcha

https://burned.cc - Burn After Reading Website