From 642c27451f3bc4314f10e755d17c8d5922ae0c0f Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Wed, 10 Feb 2016 00:04:53 +0000 Subject: [PATCH] nb.resize --- lib/js/nb.js | 50 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/lib/js/nb.js b/lib/js/nb.js index 4ca52f5d..37e17da0 100644 --- a/lib/js/nb.js +++ b/lib/js/nb.js @@ -19,16 +19,54 @@ function NB() { // Used in css to trigger a resize $('body').append(''); + //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')); + + } + + } + + }); } } -- 2.47.3