Loading js/maxlength.js +15 −5 Original line number Diff line number Diff line Loading @@ -104,8 +104,6 @@ input = $.trim(input); // making the lineendings with two chars input = ml.twochar_lineending(input); // We do want that the space characters to count as 1, not 6... input = input.replace(' ', ' '); //input = input.split(' ').join(''); // Strips HTML and PHP tags from a string allowed = (((allowed || "") + "") Loading @@ -114,9 +112,12 @@ .join(''); // making sure the allowed arg is a string containing only tags in lowercase (<a><b><c>) var tags = /<\/?([a-z][a-z0-9]*)\b[^>]*>/gi, commentsAndPhpTags = /<!--[\s\S]*?-->|<\?(?:php)?[\s\S]*?\?>/gi; return input.replace(commentsAndPhpTags, '').replace(tags, function($0, $1){ input = input.replace(commentsAndPhpTags, '').replace(tags, function($0, $1){ return allowed.indexOf('<' + $1.toLowerCase() + '>') > -1 ? $0 : ''; }); // Replace all html entities with a single character (#) placeholder. return input.replace(/&([a-z]+);/g, '#'); }; /** Loading @@ -131,8 +132,6 @@ var tags_open = new Array(); // making the lineendings with two chars text = ml.twochar_lineending(text); // We do want that the space characters to count as 1, not 6... text = text.replace(' ', ' '); while (result_text.length < limit && text.length > 0) { switch (text.charAt(0)) { case '<': { Loading Loading @@ -199,6 +198,17 @@ } break; } case '&': { // Don't truncate in the middle of an html entity count it as 1. entities = text.match(/&([a-z]+);/g); if (entities) { nextEntity = entities[0]; result_html += nextEntity; result_text += '#'; text = text.slice(nextEntity.length - 1); break; } } default: { // In this case, we have a character that should also count for the // limit, so append it to both, the html and text result. Loading Loading
js/maxlength.js +15 −5 Original line number Diff line number Diff line Loading @@ -104,8 +104,6 @@ input = $.trim(input); // making the lineendings with two chars input = ml.twochar_lineending(input); // We do want that the space characters to count as 1, not 6... input = input.replace(' ', ' '); //input = input.split(' ').join(''); // Strips HTML and PHP tags from a string allowed = (((allowed || "") + "") Loading @@ -114,9 +112,12 @@ .join(''); // making sure the allowed arg is a string containing only tags in lowercase (<a><b><c>) var tags = /<\/?([a-z][a-z0-9]*)\b[^>]*>/gi, commentsAndPhpTags = /<!--[\s\S]*?-->|<\?(?:php)?[\s\S]*?\?>/gi; return input.replace(commentsAndPhpTags, '').replace(tags, function($0, $1){ input = input.replace(commentsAndPhpTags, '').replace(tags, function($0, $1){ return allowed.indexOf('<' + $1.toLowerCase() + '>') > -1 ? $0 : ''; }); // Replace all html entities with a single character (#) placeholder. return input.replace(/&([a-z]+);/g, '#'); }; /** Loading @@ -131,8 +132,6 @@ var tags_open = new Array(); // making the lineendings with two chars text = ml.twochar_lineending(text); // We do want that the space characters to count as 1, not 6... text = text.replace(' ', ' '); while (result_text.length < limit && text.length > 0) { switch (text.charAt(0)) { case '<': { Loading Loading @@ -199,6 +198,17 @@ } break; } case '&': { // Don't truncate in the middle of an html entity count it as 1. entities = text.match(/&([a-z]+);/g); if (entities) { nextEntity = entities[0]; result_html += nextEntity; result_text += '#'; text = text.slice(nextEntity.length - 1); break; } } default: { // In this case, we have a character that should also count for the // limit, so append it to both, the html and text result. Loading