From: Nicolas Boisselier Date: Thu, 16 Jun 2016 15:18:30 +0000 (+0200) Subject: trunc X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=2e49284ca8204826f643355f40a17ba41b355009;p=nb.git trunc --- diff --git a/lib/js/nb.js b/lib/js/nb.js index e7241f57..1002dea0 100644 --- a/lib/js/nb.js +++ b/lib/js/nb.js @@ -281,6 +281,12 @@ function NB(args) { }; + this.str_trunc = function(text,max) { + max = (typeof max === 'undefined') ? 30 : max; + if (text.length>max) text = text.substring(0,(max/2)+1) + '.. ' + text.substring(text.length-(max/2),text.length); + return text; + }; + this.str2a = function(elems,compact,class_exp_file) { compact = (typeof compact === 'undefined') ? true : compact; class_exp_file = (typeof class_exp_file === 'undefined') ? 'doc|dir|path' : class_exp_file; @@ -305,19 +311,7 @@ function NB(args) { } if (compact) { - //text = text.replace(/^((?:\w+:\/+)?[^\/]+\/)(.*?)(\/?[^\/]+\/?)$/,'$1..$3'); - var max = 30; - if (text.length>max) text = text.substring(0,(max/2)+1) + '.. ' + text.substring(text.length-(max/2),text.length); - /* - text = text.replace(/^((?:\w+:\/+)?[^\/]+\/)(.*?)(\/?[^\/]+\/?)$/,function(match,p1,p2,p3){ - if (p1.length>max) p1 = p1.substring(0,max); - if (p3.length>max) p3 = p3.substring(p3.length-max,p3.length); - return p1+' ..'+p3; - console.log(p1+' | '+p2+' | '+p3); - return match; - return p1+p2.substring(0,10); - }); - */ + text = that.str_trunc(text); } //console.log(text);