...
|
...
|
@@ -9,11 +9,16 @@ var cutStr = function(params) { |
|
|
var strCut = '';
|
|
|
var i, curStr, addTxt, strLen;
|
|
|
|
|
|
params.str = params.str.replace(/\s/g, '');
|
|
|
params.str = params.str.replace(/<[^>]*>/g, '');
|
|
|
params.str = params.str.replace(/ /ig, '');
|
|
|
params.str = params.str.replace(/(?=[^>]*(?=<))\s+/g, '');
|
|
|
params.str = params.str.replace(/<(?!a|\/a).*?>/g, '');
|
|
|
|
|
|
strLen = params.str.length || 0;
|
|
|
|
|
|
if (!strLen) {
|
|
|
return '';
|
|
|
}
|
|
|
|
|
|
if (params.type === 2) {
|
|
|
addTxt = '';
|
|
|
} else {
|
...
|
...
|
@@ -22,7 +27,6 @@ var cutStr = function(params) { |
|
|
|
|
|
for (i = 0; i < strLen; i++) {
|
|
|
curStr = params.str.charAt(i);
|
|
|
curStr = params.str.charAt(i);
|
|
|
strLength++;
|
|
|
if (escape(curStr).length > 4) {
|
|
|
// 中文字符的长度经编码之后大于4
|
...
|
...
|
@@ -46,8 +50,12 @@ var cutStr = function(params) { |
|
|
var keywordLabel = function(str, key) {
|
|
|
var reg = new RegExp(key, 'gm');
|
|
|
|
|
|
if (str === '') {
|
|
|
return str;
|
|
|
}
|
|
|
|
|
|
str = str.replace(reg, '<i class="keyword">' + key + '</i>');
|
|
|
return str.replace('www.yohobuy.com', '<a href="http://www.yohobuy.com" class="keyword">www.yohobuy.com</a>');
|
|
|
return str;
|
|
|
};
|
|
|
|
|
|
exports.cutStr = cutStr;
|
...
|
...
|
|