]> git.nbdom.net Git - nb.git/commitdiff
responsive
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Sat, 16 Apr 2016 18:19:53 +0000 (19:19 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Sat, 16 Apr 2016 18:19:53 +0000 (19:19 +0100)
etc/dbs/ui.php
lib/js/nb.js

index 45005f105db664b284c39864ebbd2376bc362877..764816d08e4362a858147b30b9e87db1ba756b03 100644 (file)
@@ -30,7 +30,7 @@ $CONF['ui'] = array(
 
     'contact' => array(
       'extras'=> array(
-      ' pic' => '\'<img src="/scripts/gravatar/?email=\' || contact.email || \'" />\'',
+      ' pic' => '\'<img alt="" src="/scripts/gravatar/?email=\' || contact.email || \'" />\'',
       ),
     ),
 
@@ -82,7 +82,7 @@ $CONF['ui'] = array(
 
     'node' => array(
       'row_parse_post'=> function(&$r) {
-        $r['graph'] = '<a target="_blank" href="/graphite/?Hosts='.$r['id'].'"><img src="/images/graphite.png" /></a>';
+        $r['graph'] = '<a target="_blank" href="/graphite/?Hosts='.$r['id'].'"><img alt="" src="/images/graphite.png" /></a>';
       },
       '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' => '\'<a target="_blank" href="/graphite/?Hosts=\' || id || \'"><img src="/images/graphite.png" /></a>\'',
+        #'graph' => '\'<a target="_blank" href="/graphite/?Hosts=\' || id || \'"><img alt="" src="/images/graphite.png" /></a>\'',
       ),
 
     ),
@@ -123,7 +123,7 @@ $CONF['ui'] = array(
 
     'pingdom_check' => array(
       'row_parse_post'=> function(&$r) {
-        $r['View'] = '<a target="_blank" class="pingdom_check_report" href="https://my.pingdom.com/reports/uptime#check='.$r['id'].'"><img src="/images/graphite.png" /></a>';
+        $r['View'] = '<a target="_blank" class="pingdom_check_report" href="https://my.pingdom.com/reports/uptime#check='.$r['id'].'"><img alt="" src="/images/graphite.png" /></a>';
       },
     ),
 
index 45ce77a8a17ef11f6fa80d3b7dc0d5803bfcd12f..51a49bf264fdd9625a2bc4cc7f5c0302337327d8 100644 (file)
@@ -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('<span id="_responsive" style="display:none"></span>');
+    //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('<span id="'+opt['media_id']+'" style="display:none"></span>');
+
+    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) {