Skip to content
Snippets Groups Projects
Commit 8cf71f53 authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

ubd: update docs; enhance init and renderer

parent e1c490ff
Branches
No related tags found
1 merge request!3Abstract ubd class
...@@ -39,20 +39,22 @@ var ubd = function(){ ...@@ -39,20 +39,22 @@ var ubd = function(){
* @returns {undefined} * @returns {undefined}
*/ */
this.init = function(oConfig){ this.init = function(oConfig){
if(oConfig['domid']){ if (oConfig){
this.setDomid(oConfig['domid']); if(oConfig['domid']){
} this.setDomid(oConfig['domid']);
if(oConfig['url']){ }
this.setUrl(oConfig['url']); if(oConfig['url']){
} this.setUrl(oConfig['url']);
if(oConfig['header']){ }
this.setHeaders(oConfig['header']); if(oConfig['header']){
} this.setHeaders(oConfig['header']);
if(oConfig['renderer']){ }
this.setRenderfunction(oConfig['renderer']); if(oConfig['renderer']){
} this.setRenderfunction(oConfig['renderer']);
if(oConfig['ttl']){ }
this.setTtl(oConfig['ttl']); if(oConfig['ttl']){
this.setTtl(oConfig['ttl']);
}
} }
}, },
...@@ -78,7 +80,7 @@ var ubd = function(){ ...@@ -78,7 +80,7 @@ var ubd = function(){
/** /**
* set a rendering function that visualized data after a http request * 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.setRenderfunction = function(oFunction){
this._sRenderfunction=oFunction; this._sRenderfunction=oFunction;
...@@ -122,25 +124,30 @@ var ubd = function(){ ...@@ -122,25 +124,30 @@ var ubd = function(){
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
/** /**
* show rendered html content into set domid using the render function * show rendered html content into set domid using the render function.
* Optionally you can set a string to display an error message. * 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 * @param {string} sHtml optional: htmlcode of an error message
*/ */
this.render = function(sHtml) { 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; this._oDomObject.innerHTML=out;
}, },
/** /**
* reset timer to update the content in dom id after reaching TTL * reset timer to update the content in dom id after reaching TTL
* used in setTtl * 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(){ this.resetTimer = function(){
clearTimeout(this._oTimer); clearTimeout(this._oTimer);
...@@ -192,6 +199,8 @@ var ubd = function(){ ...@@ -192,6 +199,8 @@ var ubd = function(){
if (arguments) { if (arguments) {
this.init(arguments[0]); this.init(arguments[0]);
} else {
this.init();
} }
}; };
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment