Last active
December 14, 2015 11:50
-
-
Save AnatolyUA/5082344 to your computer and use it in GitHub Desktop.
Revisions
-
AnatolyUA revised this gist
Mar 14, 2013 . 1 changed file with 3 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,8 @@ (function($){ function cutAt(text, min, max) { min = min || 0; if (min == 0) return ""; if(text.length > min){ if (max) { var BEST = ".!?", GOOD = ",;", -
AnatolyUA revised this gist
Mar 12, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -35,6 +35,6 @@ }; jQuery.cutText = function(text, min, max){ return cutAt($('<div/>').html(text).text(), min, max); }; })(jQuery); -
AnatolyUA revised this gist
Mar 12, 2013 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,6 @@ (function($){ function cutAt(text, min, max) { if (min === 0) return ""; if(min && text.length > min){ if (max) { var BEST = ".!?", -
AnatolyUA created this gist
Mar 4, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,39 @@ (function($){ function cutAt(text, min, max) { if(min && text.length > min){ if (max) { var BEST = ".!?", GOOD = ",;", SPACE = " ", HELLIP = "…"; text = text.trim(); var n = max; for (; BEST.indexOf(text[n]) === -1 && n > min; n--){} if (n != min || BEST.indexOf(text[n]) !== -1) return text.substr(0, n + 1); n = max; for (; GOOD.indexOf(text[n]) === -1 && n > min; n--){} if (n != min || GOOD.indexOf(text[n]) !== -1) return text.substr(0, n) + HELLIP; n = max; for (; SPACE.indexOf(text[n]) === -1 && n > min; n--){} if (n != min || SPACE.indexOf(text[n]) !== -1) return text.substr(0, n) + HELLIP; return text.substr(0, max) + HELLIP; } else { return text.substr(0, min) + HELLIP; } } return text; } $.fn.cutText = function(min, max) { return cutAt(this.text(), min, max); }; jQuery.cutText = function(text, min, max){ return cutAt($("<div>" + text + "</div>").text(), min, max); }; })(jQuery);