]> git.nbdom.net Git - nb.git/commitdiff
trunc
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Thu, 16 Jun 2016 15:18:30 +0000 (17:18 +0200)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Thu, 16 Jun 2016 15:18:30 +0000 (17:18 +0200)
lib/js/nb.js

index e7241f57e78b8b79b584c5a55d2346a5de6864be..1002dea0008f5af2f52003e4843e2d8776270467 100644 (file)
@@ -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);