]> git.nbdom.net Git - nb.git/commitdiff
url trunc
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 5 Aug 2015 23:50:28 +0000 (00:50 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 5 Aug 2015 23:50:28 +0000 (00:50 +0100)
lib/js/nb.js

index cb8c8ef284b33afd2ed82ac22b8c63cc7b643b7f..f2f07592bd08072ee6a29e94dd88a1d6f6314037 100644 (file)
@@ -82,13 +82,13 @@ function NB() {
   this.str2a = function(elems,compact=true,class_exp_file='dir|path') {
     $(elems).each(function(){
 
-      html = $(this).html();
-      if (html == '') return;
+      var text = $(this).text();
+      if (text == '') return;
 
       // Search /home
-      url = html
-      if (html.match(/^~/)) {
-        ua = navigator.userAgent
+      var url = text
+      if (text.match(/^~/)) {
+        var ua = navigator.userAgent
         if (ua.match(/Macintosh/)) { url = url.replace(/^~/,'/Users/') }
         else                       { url = url.replace(/^~/,'/home/')  }
         //console.log(url);
@@ -99,9 +99,24 @@ function NB() {
         if (this.className.match(re) && !url.match(/^\w+:/)) url = 'file://'+encodeURI(url);
       }
 
-      if (compact) html = html.replace(/^((?:\w+:\/+)?[^\/]+\/)(.*?)(\/?[^\/]+)$/,'$1..$3');
+      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);
+        });
+        */
+      }
+      //console.log(text);
 
-      $(this).html('<a href="'+url+'" class="small" target="_blank">'+html+'</a>');
+      $(this).html('<a href="'+url+'" class="small" target="_blank">'+text+'</a>');
 
     });