]> git.nbdom.net Git - nb.git/commitdiff
nb.resize
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 10 Feb 2016 00:04:53 +0000 (00:04 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 10 Feb 2016 00:04:53 +0000 (00:04 +0000)
lib/js/nb.js

index 4ca52f5ddd519d0c9ac1d7a671a1c3d507e45e98..37e17da07f64d227e4cf747a8c4ef47193b2385c 100644 (file)
@@ -19,16 +19,54 @@ function NB() {
     // Used in css to trigger a resize
     $('body').append('<span id="_responsive" style="display:none"></span>');
 
+    //that.resize();
+    //$( window ).resize(that.resize);
+    $(window).on('load resize',that.resize);
+
+  }
+
+  this.resize = function() {
     // Max width for blocks
     var block = $("table, div");
     if (block) {
       var width = $(window).width();
-      if (block.width() > width) {
-        block.css({
-          'display': 'block',
-          'overflow': 'scroll',
-        }).width(width - 10);
-      }
+      var set_width = width - 20;
+      block.each(function(){
+
+        var first_width = $(this).attr('nb.resize');
+        var cur_width = $(this).width();
+        if (cur_width > width) {
+          if (!first_width) {
+            $(this).attr('nb.resize',cur_width);
+          }
+          if (this.tagName == 'TABLE') $(this).css({
+            'display': 'block',
+            'overflow': 'scroll',
+          });
+          $(this).width(set_width);
+          //console.log(this.tagName+' : '+$(this).width()+' / '+width);
+
+        } else {
+
+          if (first_width) {
+
+            if (this.tagName == 'TABLE') {
+              $(this).css({
+                'display': 'table',
+                'overflow': 'visible',
+              });
+
+            } else {
+              $(this).width((set_width < first_width) ? set_width : first_width);
+
+            }
+            //console.log(this.tagName+' : '+$(this).attr('nb.resize'));
+
+          }
+
+        }
+
+      });
     }
 
   }