From f8a1918fe4461161932b781d6c4e0353d164ba59 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Sun, 3 Apr 2016 06:20:32 +0100 Subject: [PATCH] Bed --- lib/css/db.css | 9 +----- lib/js/nb.js | 83 ++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 74 insertions(+), 18 deletions(-) diff --git a/lib/css/db.css b/lib/css/db.css index 1efb6c75..bea3dbf1 100644 --- a/lib/css/db.css +++ b/lib/css/db.css @@ -46,9 +46,7 @@ table.rows th.key:before { content: "["; } table.rows th.key:after { content: "]"; } -table.rows tr.row { - vertical-align: top; -} +table.rows tr { vertical-align: top; } .db div.rows .row *:not([class~=buttons]):hover { opacity: 0.7; @@ -71,11 +69,6 @@ table.rows tr.row { white-space: normal; text-align: right; } -/* -.rows ul .button { float: right; } -.rows .buttons { text-align: center; } -div.rows div.buttons { float: right; } -*/ /* Menu diff --git a/lib/js/nb.js b/lib/js/nb.js index 557ffab1..b3e1431c 100644 --- a/lib/js/nb.js +++ b/lib/js/nb.js @@ -344,6 +344,65 @@ function NB() { return items.join(''); } + this.j2d = function(url) { + var rows = $(''); + var count = 0; + + $.getJSON(url, function(json) { + + $.each(json, function(i,rec){ + + $.each(rec, function(k,v){ + var row = $('',{'class':k}).appendTo(rows); + + $('
',{'text':k}).appendTo(row) + $('',{'text':v}).appendTo(row) +//console.log(rec); + }); + + count++; + }); + + }); + + return rows; + } + + this.j2t = function(url) { + var rows = $(''); + var count = 0; + + $.getJSON(url, function(json) { + + $.each(json, function(i,rec){ + var row = $('').appendTo(rows); + + if (!count) { + $.each(rec, function(k,v){ + $('').appendTo(rows); + } + + $.each(rec, function(k,v){ + $('').append(row); //if (typeof map != 'undefined') { $.each(row,map); } - else { - } rows.append(row); }); - $(dest).append(rows); - }); + return rows; } -- 2.47.3
',{ + 'text': k, + 'class': k, + }).appendTo(row) + }); + row = $('
',{ + 'text': v, + 'class': k, + }).appendTo(row) +//console.log(rec); + }); + + count++; + }); + + }); + + return rows; + } + this.j2h = function(url,dest,tag='ul',map) { var tags = { @@ -363,8 +422,10 @@ function NB() { if (typeof tags[tag] == 'string') tags[tag] = tags[tag].split('.'); //console.log(tags[tag]); return; + var rows = $('<'+tag+'>'); + $.getJSON(url, function(json) { - var rows = $('<'+tag+'>'); + if (dest) $(dest).append(rows); tag == 'select' && rows.append($('<'+tags[tag]+'>').text('')); //if (typeof map != 'undefined') { json = $.map(json,map); } @@ -372,9 +433,11 @@ function NB() { $.each(json, function(k, v){ - if ($.type(v) == 'object') { v = $.map(v,function(v,k){return v})[0]; v = [v,v]; } - if ($.type(v) == 'string') v = [v,v]; - if (v.length==1) v = [v[0],v[0]] + if (typeof map == 'undefined') { + if ($.type(v) == 'object') { v = $.map(v,function(v,k){return v})[0]; v = [v,v]; } + if ($.type(v) == 'string') v = [v,v]; + if (v.length==1) v = [v[0],v[0]] + } var row = null; var item; @@ -392,21 +455,21 @@ function NB() { //if (row == null) return; - item.text(v[0]); - item.attr('value',v[1]); + if (typeof map == 'undefined') { + item.text(v[0]); + item.attr('value',v[1]); + } + if (typeof map != 'undefined') { (map)(item,v); } //if (tags[tag] == 'td') row = $('