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
- $('form').submit(function(e){
- //e.preventDefault();
- return that.form_submit_clean(this);
- });
-
- // Add msg div
- var msg = $('<div id="nb-msg"></div>');
- if ($('h1').length) {
- msg.insertAfter('h1:first');
- } else {
- $('body').prepend(msg);
- }
-
- //that.resize(); $( window ).resize(that.resize);
- if (that.o_resize) $(window).on('load resize',that.resize);
-
- that.debug('READY !!!');
-
- };
-
- this.wh = function(s) {
- var item = $(s);
- if (!item) return [0,0]
-
- var width = item.width();
- var height = item.height();
-
- /*
- */
- width -= $(item).css('paddingLeft').replace(/px/,'');
- width -= $(item).css('paddingRight').replace(/px/,'');
- height -= $(item).css('paddingTop').replace(/px/,'');
- height -= $(item).css('paddingBottom').replace(/px/,'');
-
- width -= $(item).css('marginLeft').replace(/px/,'');
- width -= $(item).css('marginRight').replace(/px/,'');
- height -= $(item).css('marginTop').replace(/px/,'');
- height -= $(item).css('marginBottom').replace(/px/,'');
- //console.log(width+'/'+height);
- return [parseInt(width),parseInt(height)];
- }
-
- this.basicauth_logout = function() {
- var userAgent = navigator.userAgent.toLowerCase();
-
- if (userAgent.indexOf("msie") != -1) {
- document.execCommand("ClearAuthenticationCache", false);
- }
-
- xhr_objectCarte = null;
-
- if(window.XMLHttpRequest)
- xhr_object = new XMLHttpRequest();
- else if(window.ActiveXObject)
- xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
- else
- alert ("Your browser doesn't support XMLHTTPREQUEST");
-
- xhr_object.open ('GET', '/logout', false, '\0', 'password');
- xhr_object.send ("");
- xhr_object = null;
-
- document.location = window.location;
- return false;
- }
-
- this.maximize = function(s) {
- var height = $(window).height();
- var width = $(window).width();
-
- $(s).each(function(){
- w = width;
- h = height;
-
- // fixed margins
- h -= 20; w -= 20;
-
- // remove what is above
- var pos = $(this).position(); if (pos) h -= parseInt(pos.top);
-
- // remove what is after
- $(this).next().
- add($(this).parent().next())
- .each(function(){ h -= $(this).height(); });
-
- // apply
- $(this).height(h); $(this).width(w);
- $(this).css({
- 'overflow':'auto',
- });
- if (this.tagName == 'TABLE') $(this).css('display','block');
- });
- }
-
- this.resize_width = function(s) {
- var block = $(s);
- if (!block) return false;
-
- var width = $('html').width();
- var set_width = width - 30;
- block.each(function(){
-
- var cur_width = $(this).width();
- var first_width = $(this).attr('nb-first-size');
- var new_width;
+ // 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
+ $('form').submit(function(e){
+ //e.preventDefault();
+ return that.form_submit_clean(this);
+ });
+
+ // Add msg div
+ var msg = $('<div id="nb-msg"></div>');
+ if ($('h1').length) {
+ msg.insertAfter('h1:first');
+ } else {
+ $('body').prepend(msg);
+ }
+
+ //that.resize(); $( window ).resize(that.resize);
+ if (that.o_resize) $(window).on('load resize',that.resize);
+
+ that.debug('READY !!!');
+
+ };
+
+ this.wh = function(s) {
+ var item = $(s);
+ if (!item) return [0,0]
+
+ var width = item.width();
+ var height = item.height();
+
+ /*
+ */
+ width -= $(item).css('paddingLeft').replace(/px/,'');
+ width -= $(item).css('paddingRight').replace(/px/,'');
+ height -= $(item).css('paddingTop').replace(/px/,'');
+ height -= $(item).css('paddingBottom').replace(/px/,'');
+
+ width -= $(item).css('marginLeft').replace(/px/,'');
+ width -= $(item).css('marginRight').replace(/px/,'');
+ height -= $(item).css('marginTop').replace(/px/,'');
+ height -= $(item).css('marginBottom').replace(/px/,'');
+ //console.log(width+'/'+height);
+ return [parseInt(width),parseInt(height)];
+ }
+
+ this.basicauth_logout = function() {
+ var userAgent = navigator.userAgent.toLowerCase();
+
+ if (userAgent.indexOf("msie") != -1) {
+ document.execCommand("ClearAuthenticationCache", false);
+ }
+
+ xhr_objectCarte = null;
+
+ if(window.XMLHttpRequest)
+ xhr_object = new XMLHttpRequest();
+ else if(window.ActiveXObject)
+ xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
+ else
+ alert ("Your browser doesn't support XMLHTTPREQUEST");
+
+ xhr_object.open ('GET', '/logout', false, '\0', 'password');
+ xhr_object.send ("");
+ xhr_object = null;
+
+ document.location = window.location;
+ return false;
+ }
+
+ this.maximize = function(s) {
+ var height = $(window).height();
+ var width = $(window).width();
+
+ $(s).each(function(){
+ w = width;
+ h = height;
+
+ // fixed margins
+ h -= 20; w -= 20;
+
+ // remove what is above
+ var pos = $(this).position(); if (pos) h -= parseInt(pos.top);
+
+ // remove what is after
+ $(this).next().
+ add($(this).parent().next())
+ .each(function(){ h -= $(this).height(); });
+
+ // apply
+ $(this).height(h); $(this).width(w);
+ $(this).css({
+ 'overflow':'auto',
+ });
+ if (this.tagName == 'TABLE') $(this).css('display','block');
+ });
+ }
+
+ this.resize_width = function(s) {
+ var block = $(s);
+ if (!block) return false;
+
+ var width = $('html').width();
+ var set_width = width - 30;
+ block.each(function(){
+
+ 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) {
+ // Width to big
+ if (cur_width > width) {
- if (this.tagName == 'TABLE') $(this).css({
- 'display': 'block',
- 'overflow': 'scroll',
- });
+ if (this.tagName == 'TABLE') $(this).css({
+ 'display': 'block',
+ 'overflow': 'scroll',
+ });
- new_width = set_width;
- //if (!first_width) $(this).attr('nb-first-size',new_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);
+ //console.log('RESIZE: '+this.tagName+': '+cur_width+' -> '+new_width);
- // Width OK
- } else {
+ // Width OK
+ } else {
- if (first_width) {
+ if (first_width) {
/*
- if (this.tagName == 'TABLE') {
- $(this).css({
- 'display': 'table',
- 'overflow': 'visible',
- });
+ if (this.tagName == 'TABLE') {
+ $(this).css({
+ 'display': 'table',
+ 'overflow': 'visible',
+ });
- } else {
+ } else {
// NB 16.04.16 $(this).width((set_width < first_width) ? set_width : first_width);
- }
+ }
*/
- new_width = first_width;
- //console.log('RESTORE FIRST: '+this.tagName+': '+cur_width+' -> '+$(this).attr('nb-first-size'));
+ 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);
- } 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);
+ }
- if (new_width) {
- $(this).width(new_width);
- console.log('RESIZE: width='+width+' '+this.tagName+' '+$(this).attr('class')+': '+cur_width+' -> '+new_width);
- }
+ });
- });
+ }
- }
+ this.resize = function() {
- this.resize = function() {
+ if (!that.o_resize) return;
+ var opt = that.o_resize;
- 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>');
- // 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') {
- if (opt['table2div']) {
- // table to div
- if ($('#'+opt['media_id']).css('content') != 'none') {
+ $(opt['table2div']).each(function(){
+ if (this.tagName=='TABLE') that.table2div(this);
+ });
- $(opt['table2div']).each(function(){
- if (this.tagName=='TABLE') that.table2div(this);
- });
+ //that.table2div('table.rows');
+ return true;
- //that.table2div('table.rows');
- return true;
+ } else {
+ that.table2div(opt['table2div'],'CLEAN');
- } else {
- that.table2div(opt['table2div'],'CLEAN');
-
- }
- }
-
- // Max width for blocks
- if (opt['resize_width']) that.resize_width(opt['resize_width']);
- if (opt['maximize']) that.maximize(opt['maximize']);
-
- that.debug('RESIZE !!!');
- }
+ }
+ }
- this.table2div = function(find,clean) {
-
- if (clean) {
- $('.t2d-th').each(function(){ $(this).remove(); });
- return $(find).addClass('t2d');
- }
-
- var th = []
-
- var t = $(find);
- if ($(t).hasClass('t2d')) return false;
- $(t).addClass('t2d');
-
- $(t.find('thead')).each(function(){
- $(this).find('th').each(function(){
- //$(this).find('a').remove();
- th.push($(this).html());
- });
- });
-
- //console.log(th.length);
-
- $(t.find('tbody tr')).each(function(){
- var i = 0;
- $(this).find('td').each(function(){
- if (typeof th[i] != 'undefined' && th[i] != '') $(this).prepend('<label class="t2d-th">'+th[i]+'</label>');
- //$(this).css('display','block');
- i++
- });
- });
-
- return t;
- }
-
- this.form_submit_clean = function(f) {
- var i = 0;
- var url = '';
- var action = f.getAttribute('action');
- var method = f.getAttribute('method');
- if (method != 'get') return true;
-
- //if (typeof(action) == 'undefined') action = '';
-
- for(i=0;i<f.length;i++) {
- var p = f[i];
- if (!p.name) continue;
- if (p.value=='') continue;
- if (p.value=='undefined') continue;
- // NB 02.09.13 url += (url ? '&' : '?') + escape(p.name) + '=' + escape(p.value);
- url += (url ? '&' : '?') + encodeURI(p.name) + '=' + encodeURI(p.value);
- }
-
- url = (action == '?' ? '' : action) + url;
-
- //document.location = url;
-
- //if (url == window.location) return false;
- f.reset();
- window.location = url;
- return false;
- }
-
- this.form_clear = function(form) {
- var e;
- for(i=0;i<form.length;i++) {
- e = form.elements[i];
- if (e.style.display == 'none') continue;
- if (e.type != 'text') continue;
- e.value = ''
- }
- };
-
- this.debug = function(msg) {
- if (!this.o_debug) return;
- console.log(msg);
- };
-
- this.get_http = function(url) {
-
- var xhr_content='';
- // try when from other domain, ex google cache
- try {
- var xhr;
- if(document.all && !window.opera) { //Internet Explorer
- xhr = new ActiveXObject("Microsoft.XMLHTTP") ;
- //xhr = new ActiveXObject("Msxml2.XMLHTTP") ;
- } else { //Mozilla
- xhr = new XMLHttpRequest();
- }
- xhr.onreadystatechange = function() {};
- xhr.open("GET", url, false);
- xhr.send(null);
- if ((xhr.readyState == 4) && (xhr.status == 200)) xhr_content = xhr.responseText;
- }
-
- catch (e) { console.log ('NB.get_http:'+e) }
- return xhr_content;
-
- };
-
- this.str_trunc = function(text,max) {
- max = (typeof max === 'undefined') ? 30 : max;
- if (text.length>max) text = text.substring(0,(max/2)+1) + '.. ' + text.substring(text.length-(max/2),text.length);
- return text;
- };
-
- this.e2links = function(elems,compact,class_exp_file) {
- compact = (typeof compact === 'undefined') ? true : compact;
- class_exp_file = (typeof class_exp_file === 'undefined') ? 'doc|dir|path' : class_exp_file;
- $(elems).each(function(){
-
- var text = $(this).text();
- if (text == '') return;
- if (text != $(this).html()) return; // contents html
-
- // Search /home
- var url = text
- if (text.match(/^~/)) {
- var ua = navigator.userAgent
- if (ua.match(/Macintosh/)) { url = url.replace(/^~/,'/Users/') }
- else { url = url.replace(/^~/,'/home/') }
- //console.log(url);
- }
-
- if (class_exp_file) {
- var re = new RegExp(class_exp_file);
- if (this.className.match(re) && !url.match(/^\w+:/)) url = 'file://'+encodeURI(url);
- }
-
- if (compact) text = that.str_trunc(text);
- //console.log(text);
-
- $(this).html('<a href="'+url+'" class="small" target="_blank">'+text+'</a>');
-
- });
-
- };
+ // Max width for blocks
+ if (opt['resize_width']) that.resize_width(opt['resize_width']);
+ if (opt['maximize']) that.maximize(opt['maximize']);
+
+ that.debug('RESIZE !!!');
+ }
+
+ this.table2div = function(find,clean) {
+
+ if (clean) {
+ $('.t2d-th').each(function(){ $(this).remove(); });
+ return $(find).addClass('t2d');
+ }
+
+ var th = []
+
+ var t = $(find);
+ if ($(t).hasClass('t2d')) return false;
+ $(t).addClass('t2d');
+
+ $(t.find('thead')).each(function(){
+ $(this).find('th').each(function(){
+ //$(this).find('a').remove();
+ th.push($(this).html());
+ });
+ });
+
+ //console.log(th.length);
+
+ $(t.find('tbody tr')).each(function(){
+ var i = 0;
+ $(this).find('td').each(function(){
+ if (typeof th[i] != 'undefined' && th[i] != '') $(this).prepend('<label class="t2d-th">'+th[i]+'</label>');
+ //$(this).css('display','block');
+ i++
+ });
+ });
+
+ return t;
+ }
+
+ this.form_submit_clean = function(f) {
+ var i = 0;
+ var url = '';
+ var action = f.getAttribute('action');
+ var method = f.getAttribute('method');
+ if (method != 'get') return true;
+
+ //if (typeof(action) == 'undefined') action = '';
+
+ for(i=0;i<f.length;i++) {
+ var p = f[i];
+ if (!p.name) continue;
+ if (p.value=='') continue;
+ if (p.value=='undefined') continue;
+ // NB 02.09.13 url += (url ? '&' : '?') + escape(p.name) + '=' + escape(p.value);
+ url += (url ? '&' : '?') + encodeURI(p.name) + '=' + encodeURI(p.value);
+ }
+
+ url = (action == '?' ? '' : action) + url;
+
+ //document.location = url;
+
+ //if (url == window.location) return false;
+ f.reset();
+ window.location = url;
+ return false;
+ }
+
+ this.form_clear = function(form) {
+ var e;
+ for(i=0;i<form.length;i++) {
+ e = form.elements[i];
+ if (e.style.display == 'none') continue;
+ if (e.type != 'text') continue;
+ e.value = ''
+ }
+ };
+
+ this.debug = function(msg) {
+ if (!this.o_debug) return;
+ console.log(msg);
+ };
+
+ this.get_http = function(url) {
+
+ var xhr_content='';
+ // try when from other domain, ex google cache
+ try {
+ var xhr;
+ if(document.all && !window.opera) { //Internet Explorer
+ xhr = new ActiveXObject("Microsoft.XMLHTTP") ;
+ //xhr = new ActiveXObject("Msxml2.XMLHTTP") ;
+ } else { //Mozilla
+ xhr = new XMLHttpRequest();
+ }
+ xhr.onreadystatechange = function() {};
+ xhr.open("GET", url, false);
+ xhr.send(null);
+ if ((xhr.readyState == 4) && (xhr.status == 200)) xhr_content = xhr.responseText;
+ }
+
+ catch (e) { console.log ('NB.get_http:'+e) }
+ return xhr_content;
+
+ };
+
+ this.str_trunc = function(text,max) {
+ max = (typeof max === 'undefined') ? 30 : max;
+ if (text.length>max) text = text.substring(0,(max/2)+1) + '.. ' + text.substring(text.length-(max/2),text.length);
+ return text;
+ };
+
+ this.e2links = function(elems,compact,class_exp_file) {
+ compact = (typeof compact === 'undefined') ? true : compact;
+ class_exp_file = (typeof class_exp_file === 'undefined') ? 'doc|dir|path' : class_exp_file;
+ $(elems).each(function(){
+
+ var text = $(this).text();
+ if (text == '') return;
+ if (text != $(this).html()) return; // contents html
+
+ // Search /home
+ var url = text
+ if (text.match(/^~/)) {
+ var ua = navigator.userAgent
+ if (ua.match(/Macintosh/)) { url = url.replace(/^~/,'/Users/') }
+ else { url = url.replace(/^~/,'/home/') }
+ //console.log(url);
+ }
+
+ if (class_exp_file) {
+ var re = new RegExp(class_exp_file);
+ if (this.className.match(re) && !url.match(/^\w+:/)) url = 'file://'+encodeURI(url);
+ }
+
+ if (compact) text = that.str_trunc(text);
+ //console.log(text);
+
+ $(this).html('<a href="'+url+'" class="small" target="_blank">'+text+'</a>');
+
+ });
+
+ };
this.html_select = function(ar) {
- console.log(json);
- var select = $('<select>');
- // JSON.parse(json)
+ console.log(json);
+ var select = $('<select>');
+ // JSON.parse(json)
$.each(ar, function(val, text) {
- select.append(
+ select.append(
$('<option></option>').val(val).html(text)
);
});
- return select;
+ return select;
}
this.urlParam = function(name) {
}
}
- this.data2html = function(data) {
-
- if (typeof(data) == 'string') {
- //if (data == '') return ' ';
- return data;
- }
-
- var items = [];
-
- if ($.isArray(data)) {
- if (!data.length) return '';
-
- if (typeof(data[0]) == 'object') {
- for (var i=0;i<data.length;i++) {
- items.push( that.data2html(data[i]) );
- }
- return items.join('');
- }
-
- for (var i=0;i<data.length;i++) {
- if (typeof(data[i]) != 'string') {
- //data[i] = that.data2html(data[i]);
- items.push( '<li>'+that.data2html(data[i])+'</li>' );
- } else {
- items.push( '<li>'+data[i]+'</li>' );
- }
- }
- return '<ul class="_test">' + items.join('') + '</ul>';
-
- }
-
- var key = '';
- var val = '';
- for (var key in data) {
- val = data[key];
- if (typeof(val) != 'string') { val = that.data2html(val); }
- //items.push( '<col class="key">' + key + '</col><col class="val">' + val + '</col>' );
- items.push( '<dl class="_test"><dt>' + key + '</dt><dd>' + val + '</dd></dl>' );
- //items.push( '<dt>' + key + '</dt><dd>' + val + '</dd>' );
- }
-
- //return '<colgroup class="_test">' + items.join('') + '</colgroup>';
- return items.join('');
- }
+ this.data2html = function(data) {
+
+ if (typeof(data) == 'string') {
+ //if (data == '') return ' ';
+ return data;
+ }
+
+ var items = [];
+
+ if ($.isArray(data)) {
+ if (!data.length) return '';
+
+ if (typeof(data[0]) == 'object') {
+ for (var i=0;i<data.length;i++) {
+ items.push( that.data2html(data[i]) );
+ }
+ return items.join('');
+ }
+
+ for (var i=0;i<data.length;i++) {
+ if (typeof(data[i]) != 'string') {
+ //data[i] = that.data2html(data[i]);
+ items.push( '<li>'+that.data2html(data[i])+'</li>' );
+ } else {
+ items.push( '<li>'+data[i]+'</li>' );
+ }
+ }
+ return '<ul class="_test">' + items.join('') + '</ul>';
+
+ }
+
+ var key = '';
+ var val = '';
+ for (var key in data) {
+ val = data[key];
+ if (typeof(val) != 'string') { val = that.data2html(val); }
+ //items.push( '<col class="key">' + key + '</col><col class="val">' + val + '</col>' );
+ items.push( '<dl class="_test"><dt>' + key + '</dt><dd>' + val + '</dd></dl>' );
+ //items.push( '<dt>' + key + '</dt><dd>' + val + '</dd>' );
+ }
+
+ //return '<colgroup class="_test">' + items.join('') + '</colgroup>';
+ return items.join('');
+ }
this.j2d = function(url) {
- var rows = $('<table>');
- var count = 0;
+ var rows = $('<table>');
+ var count = 0;
- $.getJSON(url, function(json) {
+ $.getJSON(url, function(json) {
- $.each(json, function(i,rec){
+ $.each(json, function(i,rec){
- $.each(rec, function(k,v){
- var row = $('<tr>',{'class':k}).appendTo(rows);
+ $.each(rec, function(k,v){
+ var row = $('<tr>',{'class':k}).appendTo(rows);
- $('<th>',{'text':k}).appendTo(row)
- $('<td>',{'text':v}).appendTo(row)
+ $('<th>',{'text':k}).appendTo(row)
+ $('<td>',{'text':v}).appendTo(row)
//console.log(rec);
- });
+ });
- count++;
- });
+ count++;
+ });
- });
+ });
- return rows;
- }
+ return rows;
+ }
this.j2t = function(url) {
- var rows = $('<table>');
- var count = 0;
-
- $.getJSON(url, function(json) {
-
- $.each(json, function(i,rec){
- var row = $('<tr>').appendTo(rows);
-
- if (!count) {
- $.each(rec, function(k,v){
- $('<th>',{
- 'text': k,
- 'class': k,
- }).appendTo(row)
- });
- row = $('<tr>').appendTo(rows);
- }
-
- $.each(rec, function(k,v){
- $('<td>',{
- 'text': v,
- 'class': k,
- }).appendTo(row)
+ var rows = $('<table>');
+ var count = 0;
+
+ $.getJSON(url, function(json) {
+
+ $.each(json, function(i,rec){
+ var row = $('<tr>').appendTo(rows);
+
+ if (!count) {
+ $.each(rec, function(k,v){
+ $('<th>',{
+ 'text': k,
+ 'class': k,
+ }).appendTo(row)
+ });
+ row = $('<tr>').appendTo(rows);
+ }
+
+ $.each(rec, function(k,v){
+ $('<td>',{
+ 'text': v,
+ 'class': k,
+ }).appendTo(row)
//console.log(rec);
- });
+ });
- count++;
- });
+ count++;
+ });
- });
+ });
- return rows;
- }
+ return rows;
+ }
this.j2h = function(url,dest,tag='ul',map) {
- var tags = {
- 'table' : 'tr.td',
- 'select' : 'option',
- 'ul' : 'li',
- }
-
- var m;
- if (m = tag.match(/^(\w+)\.(.*)$/)) {
- tag = m[1];
- tags[m[1]] = m[2];
- } else if(typeof tags[tag] == 'undefined' || tags[tag] == null) {
- tags[tag] = tag;
- }
-
- if (typeof tags[tag] == 'string') tags[tag] = tags[tag].split('.');
+ var tags = {
+ 'table' : 'tr.td',
+ 'select' : 'option',
+ 'ul' : 'li',
+ }
+
+ var m;
+ if (m = tag.match(/^(\w+)\.(.*)$/)) {
+ tag = m[1];
+ tags[m[1]] = m[2];
+ } else if(typeof tags[tag] == 'undefined' || tags[tag] == null) {
+ tags[tag] = tag;
+ }
+
+ if (typeof tags[tag] == 'string') tags[tag] = tags[tag].split('.');
//console.log(tags[tag]); return;
- var rows = $('<'+tag+'>');
+ var rows = $('<'+tag+'>');
- $.getJSON(url, function(json) {
- if (dest) $(dest).append(rows);
- tag == 'select' && rows.append($('<'+tags[tag]+'>').text(''));
+ $.getJSON(url, function(json) {
+ if (dest) $(dest).append(rows);
+ tag == 'select' && rows.append($('<'+tags[tag]+'>').text(''));
- //if (typeof map != 'undefined') { json = $.map(json,map); }
- //console.log(json.toSource());
+ //if (typeof map != 'undefined') { json = $.map(json,map); }
+ //console.log(json.toSource());
- $.each(json, function(k, v){
+ $.each(json, function(k, v){
- 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]]
- }
+ 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;
- $.each(tags[tag],function(i,t){
+ var row = null;
+ var item;
+ $.each(tags[tag],function(i,t){
//console.log(t+': '+row);
- item = $('<'+t+'>');
- if (row == null) {
- row = item;
- } else {
- row.append(item);
- }
- });
- //row = $('<'+tags[tag]+'>');
+ item = $('<'+t+'>');
+ if (row == null) {
+ row = item;
+ } else {
+ row.append(item);
+ }
+ });
+ //row = $('<'+tags[tag]+'>');
- //if (row == null) return;
+ //if (row == null) return;
- if (typeof map == 'undefined') {
- 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 = $('<tr>').append(row);
- //if (typeof map != 'undefined') { $.each(row,map); }
+ if (typeof map != 'undefined') { (map)(item,v); }
+ //if (tags[tag] == 'td') row = $('<tr>').append(row);
+ //if (typeof map != 'undefined') { $.each(row,map); }
- rows.append(row);
+ rows.append(row);
- });
+ });
- });
- return rows;
+ });
+ return rows;
- }
+ }
- this.json2html = function(url) {
- $.getJSON(url,function(data) {
- if ($.isArray(data) && data.length == 1) data = data[0];
- var html = that.data2html(data);
- //console.log(that.data2html(data));
- if (html != '') $(html).prependTo( "#nb-msg" );
- //console.log(typeof(data));
- });
- }
+ this.json2html = function(url) {
+ $.getJSON(url,function(data) {
+ if ($.isArray(data) && data.length == 1) data = data[0];
+ var html = that.data2html(data);
+ //console.log(that.data2html(data));
+ if (html != '') $(html).prependTo( "#nb-msg" );
+ //console.log(typeof(data));
+ });
+ }
- this.dump = function (arr,level) {
- var dumped_text = "";
- if(!level) level = 0;
+ this.dump = function (arr,level) {
+ var dumped_text = "";
+ if(!level) level = 0;
- //The padding given at the beginning of the line.
- var level_padding = "";
- for(var j=0;j<level+1;j++) level_padding += " ";
+ //The padding given at the beginning of the line.
+ var level_padding = "";
+ for(var j=0;j<level+1;j++) level_padding += " ";
- if(typeof(arr) == 'object') { //Array/Hashes/Objects
- for(var item in arr) {
+ if(typeof(arr) == 'object') { //Array/Hashes/Objects
+ for(var item in arr) {
var value = arr[item];
if(typeof(value) == 'object') { //If it is an array,
- dumped_text += level_padding + "'" + item + "' ...\n";
- dumped_text += dump(value,level+1);
+ dumped_text += level_padding + "'" + item + "' ...\n";
+ dumped_text += dump(value,level+1);
} else {
- dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
+ dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
+ }
+ }
+ } else { //Stings/Chars/Numbers etc.
+ dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
+ }
+ return dumped_text;
+ }
+
+ this.msg = function(msg) {
+ $('<p>'+msg+'</p>').prependTo( "#nb-msg" );
+ }
+
+ this.reload_head_js = function() {
+ $("head script").each(function(){
+ var oldScript = this.getAttribute("src");
+ $(this).remove();
+ var newScript;
+ newScript = document.createElement('script');
+ newScript.type = 'text/javascript';
+ newScript.src = oldScript;
+ document.getElementsByTagName("head")[0].appendChild(newScript);
+ });
}
- }
- } else { //Stings/Chars/Numbers etc.
- dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
- }
- return dumped_text;
- }
-
- this.msg = function(msg) {
- $('<p>'+msg+'</p>').prependTo( "#nb-msg" );
- }
-
- this.reload_head_js = function() {
- $("head script").each(function(){
- var oldScript = this.getAttribute("src");
- $(this).remove();
- var newScript;
- newScript = document.createElement('script');
- newScript.type = 'text/javascript';
- newScript.src = oldScript;
- document.getElementsByTagName("head")[0].appendChild(newScript);
- });
- }
-
- // <<< FUNCTIONS
- if (this.o_ready) this.ready();
+
+ // <<< FUNCTIONS
+ if (this.o_ready) this.ready();
}; // <<< NB
/*
- Statics
+ Statics
*/
NB.reload_head_js = NB.prototype.reload_head_js
NB.get_http = NB.prototype.get_http
//NB.test = function() { console.log(that.dump('zaza'))}
//NB.prototype.your_method = function() { }
jQuery.fn.numAdd = function(num,re) {
- if (typeof num == 'undefined') num = 1; num = parseInt(num);
- if (typeof re == 'undefined') re = new RegExp('([\+\-]?\\d+)');
- if (typeof re == 'string') re = new RegExp(re);
- //var re = new RegExp(exp);
-
- return this.each(function() {
- var html = $(this).html();
- var m = html.match(re);
- if (!m || m.length<2) return;
-
- for (var i=1;i<m.length;i++) {
- if (!m[i].match(/^[\+\-]?\d+$/)) continue;
- m[i] = parseInt(m[i]) + num;
- }
- //console.log(m);
-
- html = html.replace(m[0],m.slice(1).join(''));
- $(this).html(html);
- });
+ if (typeof num == 'undefined') num = 1; num = parseInt(num);
+ if (typeof re == 'undefined') re = new RegExp('([\+\-]?\\d+)');
+ if (typeof re == 'string') re = new RegExp(re);
+ //var re = new RegExp(exp);
+
+ return this.each(function() {
+ var html = $(this).html();
+ var m = html.match(re);
+ if (!m || m.length<2) return;
+
+ for (var i=1;i<m.length;i++) {
+ if (!m[i].match(/^[\+\-]?\d+$/)) continue;
+ m[i] = parseInt(m[i]) + num;
+ }
+ //console.log(m);
+
+ html = html.replace(m[0],m.slice(1).join(''));
+ $(this).html(html);
+ });
}
jQuery.fn.href2delete = function(minus_one,minus_one_re) {
- return this.each(function() {
- var href = $(this).attr('href');
- //console.log(href);
- $(this).attr('href','javascript:void(0)');
-
- $(this).click(function(){
- $(this).addClass('loading');
- $(this).parent().parent().remove();
- $.ajax({
- url: href,
- type: 'DELETE',
- success: function(result) {
- if (minus_one) $(minus_one).numAdd(-1,minus_one_re);
- $(this).removeClass('loading');
- }
- });
- });
- });
+ return this.each(function() {
+ var href = $(this).attr('href');
+ //console.log(href);
+ $(this).attr('href','javascript:void(0)');
+
+ $(this).click(function(){
+ $(this).addClass('loading');
+ $(this).parent().parent().remove();
+ $.ajax({
+ url: href,
+ type: 'DELETE',
+ success: function(result) {
+ if (minus_one) $(minus_one).numAdd(-1,minus_one_re);
+ $(this).removeClass('loading');
+ }
+ });
+ });
+ });
}