* Date: 28.03.15
* See: http://www.w3schools.com/jquery/jquery_ref_selectors.asp
*/
+var nb = new NB();
function NB() {
this.form_submit_clean = function(f) {
var i = 0;
- var msg = '';
var url = '';
- msg += f.action + '\n';
+ var action = f.getAttribute('action');
+
+ //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;
- msg += p.name + '=' + p.value + '\n';
// NB 02.09.13 url += (url ? '&' : '?') + escape(p.name) + '=' + escape(p.value);
url += (url ? '&' : '?') + encodeURI(p.name) + '=' + encodeURI(p.value);
}
- url = f.action + url;
+ url = (action == '?' ? '' : action) + url;
//document.location = url;
- /*
- if (izi_opt['test_version']) {
- html_msg(''
- + '<a href="#" onclick="window.location=\''+(url)+'\'; return false;">'
- + (url)
- + '</a>'
- );
- return false;
- }
- */
-
//if (url == window.location) return false;
window.location = url;
return false;
if ((xhr.readyState == 4) && (xhr.status == 200)) xhr_content = xhr.responseText;
}
- catch (e) { console.log (e) }
+ catch (e) { console.log ('NB.get_http:'+e) }
return xhr_content;
};
};
- this.json_debug = function(url) {
- $.getJSON(url,function(data) {
- var tag = '';
- if (typeof(data) == 'string') {
- tag = 'span';
- } else if ($.isArray(data)) {
- tag = 'ul';
- } else {
- tag = 'fieldset';
+ 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( nb.data2html(data[i]) );
+ }
+ return items.join('');
}
- var items = [];
- $.each( data, function( key, val ) {
- //console.log(key+' = '+val);
- if (tag == 'span') {
- tag = 'span class="'+key+'"'
- items.push( v );
- } else if (tag == 'ul') {
- items.push( '<li class="'+val+'">'+val+'</li>' );
- } else if (tag == 'fieldset') {
- items.push( '<dl class="'+key+'"><dt>'+key+'</dt><dd>'+val+'</dd>' );
+
+ for (var i=0;i<data.length;i++) {
+ if (typeof(data[i]) != 'string') {
+ //data[i] = nb.data2html(data[i]);
+ items.push( '<li>'+nb.data2html(data[i])+'</li>' );
+ } else {
+ items.push( '<li>'+data[i]+'</li>' );
}
- });
- $( '<'+tag+'/>', {
- //"class": "my-new-list",
- html: items.join( "" )
- }).prependTo( "#msg" );
+ }
+ return '<ul class="_test">' + items.join('') + '</ul>';
+
+ }
+
+ var key = '';
+ var val = '';
+ for (var key in data) {
+ val = data[key];
+ if (typeof(val) != 'string') { val = nb.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('');
+ return '<div class="_test">' + items.join('') + '</div>';
+ return '<dl class="_test">' + items.join('') + '</dl>';
+ return '<div>' + items.join('') + '</div>';
+ }
+
+ this.json2html = function(url) {
+ $.getJSON(url,function(data) {
+ if ($.isArray(data) && data.length == 1) data = data[0];
+ var html = nb.data2html(data);
+ //console.log(nb.data2html(data));
+ if (html != '') $(html).prependTo( "#msg" );
//console.log(typeof(data));
});
}