diff --git a/public_html/javascript/ubd.class.js b/public_html/javascript/ubd.class.js index 2d8de8029c7f36d894d345e0452a9944a971c0b9..69ea642bfac355f2ebfc664243ab31c7c82e9f65 100644 --- a/public_html/javascript/ubd.class.js +++ b/public_html/javascript/ubd.class.js @@ -39,20 +39,22 @@ var ubd = function(){ * @returns {undefined} */ this.init = function(oConfig){ - if(oConfig['domid']){ - this.setDomid(oConfig['domid']); - } - if(oConfig['url']){ - this.setUrl(oConfig['url']); - } - if(oConfig['header']){ - this.setHeaders(oConfig['header']); - } - if(oConfig['renderer']){ - this.setRenderfunction(oConfig['renderer']); - } - if(oConfig['ttl']){ - this.setTtl(oConfig['ttl']); + if (oConfig){ + if(oConfig['domid']){ + this.setDomid(oConfig['domid']); + } + if(oConfig['url']){ + this.setUrl(oConfig['url']); + } + if(oConfig['header']){ + this.setHeaders(oConfig['header']); + } + if(oConfig['renderer']){ + this.setRenderfunction(oConfig['renderer']); + } + if(oConfig['ttl']){ + this.setTtl(oConfig['ttl']); + } } }, @@ -78,7 +80,7 @@ var ubd = function(){ /** * set a rendering function that visualized data after a http request - * @param {string|function} oFunction + * @param {string|function} oFunction reference to a function ... or false to disable rendering */ this.setRenderfunction = function(oFunction){ this._sRenderfunction=oFunction; @@ -122,25 +124,30 @@ var ubd = function(){ // ---------------------------------------------------------------------- /** - * show rendered html content into set domid using the render function - * Optionally you can set a string to display an error message. + * show rendered html content into set domid using the render function. + * If no rendering function was set then the response will be written + * directly. + * You can override both by giving a parameter (a string with html) + * to write that one directly. It can be used to show an error message. + * + * TODO: + * other output places than innerHTML by detecting the tag e.g. + * to use input or textarea. * * @param {string} sHtml optional: htmlcode of an error message */ this.render = function(sHtml) { - let out = sHtml ? sHtml : this._sRenderfunction(this._body); + let out = sHtml ? sHtml : + (this._sRenderfunction + ? this._sRenderfunction(this._body) + : this._body + ); this._oDomObject.innerHTML=out; }, /** * reset timer to update the content in dom id after reaching TTL * used in setTtl - * - * WIP: repeating the update braks out from current instance. - * But what works is - * var oUbd=new ubd(...) - * by setting ttl = 0 and - * window.setInterval("oUbd.update();", 3000); */ this.resetTimer = function(){ clearTimeout(this._oTimer); @@ -192,6 +199,8 @@ var ubd = function(){ if (arguments) { this.init(arguments[0]); + } else { + this.init(); } }; \ No newline at end of file