From b88e9ce35f2ca99d6b9d90c2d7d3864dbd0c54f4 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Sat, 16 Apr 2016 19:19:53 +0100 Subject: [PATCH] responsive --- etc/dbs/ui.php | 8 ++-- lib/js/nb.js | 109 +++++++++++++++++++++++++++++++++++-------------- 2 files changed, 82 insertions(+), 35 deletions(-) diff --git a/etc/dbs/ui.php b/etc/dbs/ui.php index 45005f10..764816d0 100644 --- a/etc/dbs/ui.php +++ b/etc/dbs/ui.php @@ -30,7 +30,7 @@ $CONF['ui'] = array( 'contact' => array( 'extras'=> array( - ' pic' => '\'\'', + ' pic' => '\'\'', ), ), @@ -82,7 +82,7 @@ $CONF['ui'] = array( 'node' => array( 'row_parse_post'=> function(&$r) { - $r['graph'] = ''; + $r['graph'] = ''; }, 'extras'=> array( 'ip' => false, @@ -101,7 +101,7 @@ $CONF['ui'] = array( ))"), 'fact' => "(SELECT count(*) FROM fact WHERE fact.idnode=node.id)", 'keyevent' => "(SELECT count(*) FROM keyevent WHERE keyevent.idnode=node.id)", - #'graph' => '\'\'', + #'graph' => '\'\'', ), ), @@ -123,7 +123,7 @@ $CONF['ui'] = array( 'pingdom_check' => array( 'row_parse_post'=> function(&$r) { - $r['View'] = ''; + $r['View'] = ''; }, ), diff --git a/lib/js/nb.js b/lib/js/nb.js index 45ce77a8..51a49bf2 100644 --- a/lib/js/nb.js +++ b/lib/js/nb.js @@ -5,11 +5,15 @@ * See: http://www.w3schools.com/jquery/jquery_ref_selectors.asp */ -function NB() { +function NB(args) { + + // Vars from args + if (typeof(args) != 'undefined') { for (var k in args) { this['o_'+k] = args[k]; } } var that = this; var name = 'Nb'; + // Lib this.ready = function() { // Form clean @@ -26,14 +30,12 @@ function NB() { $('body').prepend(msg); } - // Used in css to trigger a resize - $('body').append(''); + //that.resize(); $( window ).resize(that.resize); + if (that.o_resize) $(window).on('load resize',that.resize); - //that.resize(); - //$( window ).resize(that.resize); - $(window).on('load resize',that.resize); + that.debug('READY !!!'); - } + }; this.wh = function(s) { var item = $(s); @@ -57,7 +59,7 @@ function NB() { return [parseInt(width),parseInt(height)]; } - this.maxhw = function(s) { + this.maximize = function(s) { var height = $(window).height(); var width = $(window).width(); @@ -85,33 +87,39 @@ function NB() { }); } - this.maxhw_resize = function(s) { + this.resize_width = function(s) { var block = $(s); if (!block) return false; - var width = $('body').width(); - var set_width = width - 20; + var width = $('html').width(); + var set_width = width - 30; block.each(function(){ - var first_width = $(this).attr('nb-resize'); var cur_width = $(this).width(); + var first_width = $(this).attr('nb-first-size'); + var new_width; //$(this).css({ 'border': 'solid 1px yellow', }); + // Width to big 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); + new_width = set_width; + //if (!first_width) $(this).attr('nb-first-size',new_width); +//console.log(this.tagName+' : '+$(this).width()+' / '+width); + + //console.log('RESIZE: '+this.tagName+': '+cur_width+' -> '+new_width); + + // Width OK } else { if (first_width) { +/* if (this.tagName == 'TABLE') { $(this).css({ 'display': 'table', @@ -119,35 +127,68 @@ function NB() { }); } else { - $(this).width((set_width < first_width) ? set_width : first_width); +// NB 16.04.16 $(this).width((set_width < first_width) ? set_width : first_width); } - //console.log(this.tagName+' : '+$(this).attr('nb-resize')); +*/ + new_width = first_width; + //console.log('RESTORE FIRST: '+this.tagName+': '+cur_width+' -> '+$(this).attr('nb-first-size')); + + } else { + $(this).attr('nb-first-size',cur_width); } } + if (new_width) { + $(this).width(new_width); + console.log('RESIZE: width='+width+' '+this.tagName+' '+$(this).attr('class')+': '+cur_width+' -> '+new_width); + } + }); } this.resize = function() { - // table to div - if ($('#_responsive').css('content') != 'none') { - that.table2div('table.rows'); - return true; - } else { - $('.block table, table.block, table.rows').addClass('t2d'); - $('.t2d-th').each(function(){ $(this).remove(); }); + if (!that.o_resize) return; + var opt = that.o_resize; + + // Used in css to trigger a resize + if (!$('#'+opt['media_id']).length) $('body').append(''); + + if (opt['table2div']) { + // table to div + if ($('#'+opt['media_id']).css('content') != 'none') { + + $(opt['table2div']).each(function(){ + if (this.tagName=='TABLE') that.table2div(this); + }); + + //that.table2div('table.rows'); + return true; + + } else { + that.table2div(opt['table2div'],'CLEAN'); + + } } // Max width for blocks - that.maxhw_resize('table, div'); + if (opt['resize_width']) that.resize_width(opt['resize_width']); + if (opt['maximize']) that.maximize(opt['maximize']); + + that.debug('RESIZE !!!'); } - this.table2div = function(find) { + this.table2div = function(find,clean) { + + if (clean) { + $('.t2d-th').each(function(){ $(this).remove(); }); + return $(find).addClass('t2d'); + } + var th = [] var t = $(find); @@ -172,6 +213,7 @@ function NB() { }); }); + return t; } this.form_submit_clean = function(f) { @@ -209,8 +251,9 @@ function NB() { } }; - this.debug = function(test) { - console.log(test); + this.debug = function(msg) { + if (!this.o_debug) return; + console.log(msg); }; this.get_http = function(url) { @@ -527,7 +570,10 @@ function NB() { }); } -}; + // <<< FUNCTIONS + if (this.o_ready) this.ready(); + +}; // <<< NB /* Statics */ @@ -558,6 +604,7 @@ jQuery.fn.numAdd = function(num,re) { html = html.replace(m[0],m.slice(1).join('')); $(this).html(html); }); + } jQuery.fn.href2delete = function(minus_one,minus_one_re) { -- 2.47.3