diff --git a/dist/jaxon.core.js b/dist/jaxon.core.js index 0ac54b8..b1b5ded 100644 --- a/dist/jaxon.core.js +++ b/dist/jaxon.core.js @@ -7,7 +7,7 @@ file, or by specifying the appropriate configuration options on a per call basis. */ -const jaxon = {}; +var jaxon = {}; /* Class: jaxon.config @@ -393,123 +393,110 @@ jaxon.tools.array = { jaxon.tools.dom = { - /* - Function: jaxon.tools.dom.$ - - Shorthand for finding a uniquely named element within the document. - - Parameters: - sId - (string): - The unique name of the element (specified by the ID attribute), not to be confused - with the name attribute on form elements. - - Returns: - object - The element found or null. - - Note: - This function uses the which allows to operate on the - main window document as well as documents from contained iframes and child windows. - - See also: - and - */ + /** + * Shorthand for finding a uniquely named element within the document. + * + * Note: + * This function uses the which allows to operate on the + * main window document as well as documents from contained iframes and child windows. + * + * @param {string} sId - The unique name of the element (specified by the ID attribute) + * Not to be confused with the name attribute on form elements. + * + * @returns {object} - The element found or null. + * + * @see and + */ $: function(sId) { if (!sId) return null; - //sId not an string so return it maybe its an object. - if (typeof sId != 'string') + + if (typeof sId !== 'string') return sId; const oDoc = jaxon.config.baseDocument; - const obj = oDoc.getElementById(sId); if (obj) return obj; - if (oDoc.all) return oDoc.all[sId]; return obj; }, - /* - Function: jaxon.tools.dom.getBrowserHTML - - Insert the specified string of HTML into the document, then extract it. - This gives the browser the ability to validate the code and to apply any transformations it deems appropriate. - - Parameters: - sValue - (string): - A block of html code or text to be inserted into the browser's document. + /** + * Create a div as workspace for the getBrowserHTML() function. + * + * @returns {object} - The workspace DOM element. + */ + _getWorkspace: function() { + const elWorkspace = jaxon.$('jaxon_temp_workspace'); + if (elWorkspace) { + return elWorkspace; + } - Returns: - The (potentially modified) html code or text. - */ - getBrowserHTML: function(sValue) { + // Workspace not found. Must be ceated. const oDoc = jaxon.config.baseDocument; if (!oDoc.body) - return ''; + return null; - const elWorkspace = jaxon.$('jaxon_temp_workspace'); - if (!elWorkspace) { - elWorkspace = oDoc.createElement('div'); - elWorkspace.setAttribute('id', 'jaxon_temp_workspace'); - elWorkspace.style.display = 'none'; - elWorkspace.style.visibility = 'hidden'; - oDoc.body.appendChild(elWorkspace); - } + const elNewWorkspace = oDoc.createElement('div'); + elNewWorkspace.setAttribute('id', 'jaxon_temp_workspace'); + elNewWorkspace.style.display = 'none'; + elNewWorkspace.style.visibility = 'hidden'; + oDoc.body.appendChild(elNewWorkspace); + return elNewWorkspace; + }, + + /** + * Insert the specified string of HTML into the document, then extract it. + * This gives the browser the ability to validate the code and to apply any transformations it deems appropriate. + * + * @param {string} sValue - A block of html code or text to be inserted into the browser's document. + * + * @returns {string} - The (potentially modified) html code or text. + */ + getBrowserHTML: function(sValue) { + const elWorkspace = jaxon.tools.dom._getWorkspace(); elWorkspace.innerHTML = sValue; const browserHTML = elWorkspace.innerHTML; elWorkspace.innerHTML = ''; - return browserHTML; }, - /* - Function: jaxon.tools.dom.willChange - - Tests to see if the specified data is the same as the current value of the element's attribute. - - Parameters: - element - (string or object): - The element or it's unique name (specified by the ID attribute) - attribute - (string): - The name of the attribute. - newData - (string): - The value to be compared with the current value of the specified element. - - Returns: - true - The specified value differs from the current attribute value. - false - The specified value is the same as the current value. - */ + /** + * Tests to see if the specified data is the same as the current value of the element's attribute. + * + * @param {string|object} element - The element or it's unique name (specified by the ID attribute) + * @param {string} ttribute - The name of the attribute. + * @param {string} newData - The value to be compared with the current value of the specified element. + * + * @returns {true} - The specified value differs from the current attribute value. + * @returns {false} - The specified value is the same as the current value. + */ willChange: function(element, attribute, newData) { - if ('string' == typeof element) + if ('string' === typeof element) element = jaxon.$(element); - if (element) { - let oldData; - // eval('oldData=element.' + attribute); - oldData = element[attribute]; - return (newData != oldData); + if (!element) { + return false; } - return false; + return (newData != element[attribute]); }, - /* - Function: jaxon.tools.dom.findFunction - - Find a function using its name as a string. - - Parameters: - sFuncName - (string): The name of the function to find. - - Returns: - Functiion - The function with the given name. - */ + /** + * Find a function using its name as a string. + * + * @param {string} sFuncName - The name of the function to find. + * + * @returns {object} - The function + */ findFunction: function (sFuncName) { let context = window; - const namespaces = sFuncName.split("."); - for(const i = 0; i < namespaces.length && context != undefined; i++) { - context = context[namespaces[i]]; + const names = sFuncName.split("."); + const length = names.length; + + for(let i = 0; i < length && (context); i++) { + context = context[names[i]]; } return context; } @@ -1103,22 +1090,16 @@ jaxon.cmd.delay = { jaxon.cmd.event = { - /* - Function: jaxon.cmd.event.setEvent - - Set an event handler. - - Parameters: - - command - (object): Response command object. - - id: Element ID - - prop: Event - - data: Code - - Returns: - - true - The operation completed successfully. - */ + /** + * Set an event handler. + * + * @param {object} command - Response command object. + * - id: Element ID + * - prop: Event + * - data: Code + * + * @returns {true} - The operation completed successfully. + */ setEvent: function(command) { command.fullName = 'setEvent'; const sEvent = jaxon.tools.string.addOnPrefix(command.prop); @@ -1129,22 +1110,16 @@ jaxon.cmd.event = { return true; }, - /* - Function: jaxon.cmd.event.addHandler - - Add an event handler to the specified target. - - Parameters: - - command - (object): Response command object. - - id: The id of, or the target itself - - prop: The name of the event. - - data: The name of the function to be called - - Returns: - - true - The operation completed successfully. - */ + /** + * Add an event handler to the specified target. + * + * @param {object} command - Response command object. + * - id: The id of, or the target itself + * - prop: The name of the event. + * - data: The name of the function to be called + * + * @returns {true} - The operation completed successfully. + */ addHandler: function(command) { command.fullName = 'addHandler'; const sFuncName = command.data; @@ -1154,22 +1129,16 @@ jaxon.cmd.event = { return jaxon.cmd.event._addHandler(oTarget, sEvent, sFuncName); }, - /* - Function: jaxon.cmd.event.removeHandler - - Remove an event handler from an target. - - Parameters: - - command - (object): Response command object. - - id: The id of, or the target itself - - prop: The name of the event. - - data: The name of the function to be removed - - Returns: - - true - The operation completed successfully. - */ + /** + * Remove an event handler from an target. + * + * @param {object} command - Response command object. + * - id: The id of, or the target itself + * - prop: The name of the event. + * - data: The name of the function to be called + * + * @returns {true} - The operation completed successfully. + */ removeHandler: function(command) { command.fullName = 'removeHandler'; const sFuncName = command.data; @@ -1186,12 +1155,12 @@ if(window.addEventListener) { }; jaxon.cmd.event._addHandler = function(target, event, func) { - target.addEventListener(event, window[func], false); + target.addEventListener(event, jaxon.tools.dom.findFunction(func), false); return true; }; jaxon.cmd.event._removeHandler = function(target, event, func) { - target.removeEventListener(event, window[func], false); + target.removeEventListener(event, jaxon.tools.dom.findFunction(func), false); return true; }; } else { @@ -1200,12 +1169,12 @@ if(window.addEventListener) { }; jaxon.cmd.event._addHandler = function(target, event, func) { - target.attachEvent(event, window[func]); + target.attachEvent(event, jaxon.tools.dom.findFunction(func)); return true; }; jaxon.cmd.event._removeHandler = function(target, event, func) { - target.detachEvent(event, window[func]); + target.detachEvent(event, jaxon.tools.dom.findFunction(func)); return true; }; } diff --git a/dist/jaxon.core.min.js b/dist/jaxon.core.min.js index f3092b3..9dbe795 100644 --- a/dist/jaxon.core.min.js +++ b/dist/jaxon.core.min.js @@ -1,4 +1,4 @@ -const jaxon={config:{},debug:{verbose:{}},ajax:{},tools:{},cmd:{}};jaxon.config.setDefault=function(e,t){void 0===jaxon.config[e]&&(jaxon.config[e]=t)},jaxon.config.setDefault("commonHeaders",{"If-Modified-Since":"Sat, 1 Jan 2000 00:00:00 GMT"}),jaxon.config.setDefault("postHeaders",{}),jaxon.config.setDefault("getHeaders",{}),jaxon.config.setDefault("waitCursor",!1),jaxon.config.setDefault("statusMessages",!1),jaxon.config.setDefault("baseDocument",document),jaxon.config.setDefault("requestURI",jaxon.config.baseDocument.URL),jaxon.config.setDefault("defaultMode","asynchronous"),jaxon.config.setDefault("defaultHttpVersion","HTTP/1.1"),jaxon.config.setDefault("defaultContentType","application/x-www-form-urlencoded"),jaxon.config.setDefault("defaultResponseDelayTime",1e3),jaxon.config.setDefault("defaultExpirationTime",1e4),jaxon.config.setDefault("defaultMethod","POST"),jaxon.config.setDefault("defaultRetry",5),jaxon.config.setDefault("defaultReturnValue",!1),jaxon.config.setDefault("maxObjectDepth",20),jaxon.config.setDefault("maxObjectSize",2e3),jaxon.config.setDefault("responseQueueSize",1e3),jaxon.config.setDefault("requestQueueSize",1e3),jaxon.config.status={update:function(){return{onRequest:function(){window.status="Sending Request..."},onWaiting:function(){window.status="Waiting for Response..."},onProcessing:function(){window.status="Processing..."},onComplete:function(){window.status="Done."}}},dontUpdate:function(){return{onRequest:function(){},onWaiting:function(){},onProcessing:function(){},onComplete:function(){}}}},jaxon.config.cursor={update:function(){return{onWaiting:function(){jaxon.config.baseDocument.body&&(jaxon.config.baseDocument.body.style.cursor="wait")},onComplete:function(){jaxon.config.baseDocument.body.style.cursor="auto"}}},dontUpdate:function(){return{onWaiting:function(){},onComplete:function(){}}}},jaxon.tools.ajax={createRequest:function(){return"undefined"!=typeof XMLHttpRequest?jaxon.tools.ajax.createRequest=function(){return new XMLHttpRequest}:"undefined"!=typeof ActiveXObject?jaxon.tools.ajax.createRequest=function(){try{return new ActiveXObject("Msxml2.XMLHTTP.4.0")}catch(e){return jaxon.tools.ajax.createRequest=function(){try{return new ActiveXObject("Msxml2.XMLHTTP")}catch(e){return jaxon.tools.ajax.createRequest=function(){return new ActiveXObject("Microsoft.XMLHTTP")},jaxon.tools.ajax.createRequest()}},jaxon.tools.ajax.createRequest()}}:window.createRequest?jaxon.tools.ajax.createRequest=function(){return window.createRequest()}:jaxon.tools.ajax.createRequest=function(){throw{code:10002}},jaxon.tools.ajax.createRequest()}},jaxon.tools.array={is_in:function(e,t){let n=0;const o=e.length;for(;n1&&1==arguments[1],n=arguments.length>2?arguments[2]:"";"string"==typeof e&&(e=jaxon.$(e));const o={};return e&&e.childNodes&&jaxon.tools.form._getValues(o,e.childNodes,t,n),o},_getValues:function(e,t,n,o){const a=t.length;for(let r=0;r=e.size},push:function(e,t){if(jaxon.tools.queue.full(e))throw{code:10003};return e.elements[e.end]=t,++e.end>=e.size&&(e.end=0),++e.count},pushFront:function(e,t){if(jaxon.tools.queue.full(e))throw{code:10003};return jaxon.tools.queue.empty(e)?jaxon.tools.queue.push(e,t):(--e.start<0&&(e.start=e.size-1),e.elements[e.start]=t,++e.count)},pop:function(e){if(jaxon.tools.queue.empty(e))return null;let t=e.elements[e.start];return delete e.elements[e.start],++e.start>=e.size&&(e.start=0),e.count--,t},peek:function(e){return jaxon.tools.queue.empty(e)?null:e.elements[e.start]}},jaxon.tools.string={doubleQuotes:function(e){return void 0!==e&&e.replace(new RegExp("'","g"),'"')},singleQuotes:function(e){return void 0!==e&&e.replace(new RegExp('"',"g"),"'")},stripOnPrefix:function(e){return 0==(e=e.toLowerCase()).indexOf("on")&&(e=e.replace(/on/,"")),e},addOnPrefix:function(e){return 0!=(e=e.toLowerCase()).indexOf("on")&&(e="on"+e),e}},String.prototype.supplant||(String.prototype.supplant=function(e){return this.replace(/\{([^{}]*)\}/g,(function(t,n){const o=e[n];return"string"==typeof o||"number"==typeof o?o:t}))}),jaxon.tools.upload={createIframe:function(e){const t="jaxon_upload_"+e.upload.id;return jaxon.cmd.node.remove(t),jaxon.cmd.node.insert(e.upload.form,"iframe",t),e.upload.iframe=jaxon.tools.dom.$(t),e.upload.iframe.name=t,e.upload.iframe.style.display="none",e.upload.form.method="POST",e.upload.form.enctype="multipart/form-data",e.upload.form.action=jaxon.config.requestURI,e.upload.form.target=t,!0},_initialize:function(e){if(!e.upload)return!1;e.upload={id:e.upload,input:null,form:null,ajax:e.ajax};const t=jaxon.tools.dom.$(e.upload.id);if(!t)return console.log("Unable to find input field for file upload with id "+e.upload.id),!1;if("file"!==t.type)return console.log("The upload input field with id "+e.upload.id+" is not of type file"),!1;if(0===t.files.length)return console.log("There is no file selected for upload in input field with id "+e.upload.id),!1;if(void 0===t.name)return console.log("The upload input field with id "+e.upload.id+" has no name attribute"),!1;if(e.upload.input=t,e.upload.form=t.form,0!=e.upload.ajax)return!0;if(!t.form){let n=t;for(;null!==n&&"FORM"!==n.nodeName;)n=n.parentNode;if(null===n)return console.log("The upload input field with id "+e.upload.id+" is not in a form"),!1;e.upload.form=n}return jaxon.tools.upload.createIframe(e),!0},initialize:function(e){jaxon.tools.upload._initialize(e),e.upload&&e.upload.ajax&&e.upload.input||e.append("postHeaders",{"content-type":e.contentType})}},jaxon.cmd.delay={popAsyncRequest:function(e){return jaxon.tools.queue.empty(e)||"synchronous"===jaxon.tools.queue.peek(e).mode?null:jaxon.tools.queue.pop(e)},retry:function(e,t){let n=e.retries;if(n){if(--n,1>n)return!1}else n=t;return e.retries=n,e.requeue=!0,!0},setWakeup:function(e,t){null!==e.timeout&&(clearTimeout(e.timeout),e.timeout=null),e.timout=setTimeout((function(){jaxon.ajax.response.process(e)}),t)},confirmCallback:function(e,t,n){if(!0===n)for(;t>0&&e.response.count>1&&null!==jaxon.tools.queue.pop(e.response);)--t;!0===e.requeue?jaxon.cmd.delay.setWakeup(e.response,30):jaxon.ajax.response.process(e.response)},confirm:function(e,t,n){return e.requeue=!0,jaxon.ajax.message.confirm(n,"",(function(){jaxon.cmd.delay.confirmCallback(e,t,!1)}),(function(){jaxon.cmd.delay.confirmCallback(e,t,!0)})),e.requeue=!1,!1}},jaxon.cmd.event={setEvent:function(e){e.fullName="setEvent";const t=jaxon.tools.string.addOnPrefix(e.prop),n=jaxon.tools.string.doubleQuotes(e.data);return("string"==typeof e.id?jaxon.$(e.id):e.id)[t]=new Function("e",n),!0},addHandler:function(e){e.fullName="addHandler";const t=e.data,n=jaxon.cmd.event.getName(e.prop),o="string"==typeof e.id?jaxon.$(e.id):e.id;return jaxon.cmd.event._addHandler(o,n,t)},removeHandler:function(e){e.fullName="removeHandler";const t=e.data,n=jaxon.cmd.event.getName(e.prop),o="string"==typeof e.id?jaxon.$(e.id):e.id;return jaxon.cmd.event._removeHandler(o,n,t)}},window.addEventListener?(jaxon.cmd.event.getName=function(e){return jaxon.tools.string.stripOnPrefix(e)},jaxon.cmd.event._addHandler=function(e,t,n){return e.addEventListener(t,window[n],!1),!0},jaxon.cmd.event._removeHandler=function(e,t,n){return e.removeEventListener(t,window[n],!1),!0}):(jaxon.cmd.event.getName=function(e){return jaxon.tools.string.addOnPrefix(e)},jaxon.cmd.event._addHandler=function(e,t,n){return e.attachEvent(t,window[n]),!0},jaxon.cmd.event._removeHandler=function(e,t,n){return e.detachEvent(t,window[n]),!0}),jaxon.cmd.form={getInput:function(e,t,n){return void 0===window.addEventListener?jaxon.cmd.form.getInput=function(e,t,n){return jaxon.config.baseDocument.createElement('')}:jaxon.cmd.form.getInput=function(e,t,n){const o=jaxon.config.baseDocument.createElement("input");return o.setAttribute("type",e),o.setAttribute("name",t),o.setAttribute("id",n),o},jaxon.cmd.form.getInput(e,t,n)},createInput:function(e){e.fullName="createInput";const t=e.id,n=e.type,o=e.data,a=e.prop;"string"==typeof t&&(t=jaxon.$(t));const r=jaxon.cmd.form.getInput(n,o,a);return t&&r&&t.appendChild(r),!0},insertInput:function(e){e.fullName="insertInput";const t=e.id,n=e.type,o=e.data,a=e.prop;"string"==typeof t&&(t=jaxon.$(t));const r=jaxon.cmd.form.getInput(n,o,a);return r&&t&&t.parentNode&&t.parentNode.insertBefore(r,t),!0},insertInputAfter:function(e){e.fullName="insertInputAfter";const t=e.id,n=e.type,o=e.data,a=e.prop;"string"==typeof t&&(t=jaxon.$(t));const r=jaxon.cmd.form.getInput(n,o,a);return r&&t&&t.parentNode&&t.parentNode.insertBefore(r,t.nextSibling),!0}},jaxon.cmd.node={assign:function(element,property,data){switch("string"==typeof element&&(element=jaxon.$(element)),property){case"innerHTML":element.innerHTML=data;break;case"outerHTML":if(void 0===element.outerHTML){const e=jaxon.config.baseDocument.createRange();e.setStartBefore(element);const t=e.createContextualFragment(data);element.parentNode.replaceChild(t,element)}else element.outerHTML=data;break;default:jaxon.tools.dom.willChange(element,property,data)&&eval("element."+property+" = data;")}return!0},append:function(element,property,data){return"string"==typeof element&&(element=jaxon.$(element)),window.insertAdjacentHTML||element.insertAdjacentHTML?"innerHTML"==property?element.insertAdjacentHTML("beforeend",data):"outerHTML"==property?element.insertAdjacentHTML("afterend",data):element[property]+=data:eval("element."+property+" += data;"),!0},prepend:function(element,property,data){return"string"==typeof element&&(element=jaxon.$(element)),eval("element."+property+" = data + element."+property),!0},replace:function(element,sAttribute,aData){const sReplace=aData.r,sSearch="innerHTML"===sAttribute?jaxon.tools.dom.getBrowserHTML(aData.s):aData.s;"string"==typeof element&&(element=jaxon.$(element)),eval("var txt = element."+sAttribute);let bFunction=!1;"function"==typeof txt&&(txt=txt.join(""),bFunction=!0);let start=txt.indexOf(sSearch);if(start>-1){let newTxt=[];for(;start>-1;){const e=start+sSearch.length;newTxt.push(txt.substr(0,start)),newTxt.push(sReplace),txt=txt.substr(e,txt.length-e),start=txt.indexOf(sSearch)}newTxt.push(txt),newTxt=newTxt.join(""),(bFunction||jaxon.tools.dom.willChange(element,sAttribute,newTxt))&&eval("element."+sAttribute+"=newTxt;")}return!0},remove:function(e){return"string"==typeof e&&(e=jaxon.$(e)),e&&e.parentNode&&e.parentNode.removeChild&&e.parentNode.removeChild(e),!0},create:function(e,t,n){"string"==typeof e&&(e=jaxon.$(e));const o=jaxon.config.baseDocument.createElement(t);return o.setAttribute("id",n),e&&e.appendChild(o),!0},insert:function(e,t,n){"string"==typeof e&&(e=jaxon.$(e));const o=jaxon.config.baseDocument.createElement(t);return o.setAttribute("id",n),e.parentNode.insertBefore(o,e),!0},insertAfter:function(e,t,n){"string"==typeof e&&(e=jaxon.$(e));const o=jaxon.config.baseDocument.createElement(t);return o.setAttribute("id",n),e.parentNode.insertBefore(o,e.nextSibling),!0},contextAssign:function(command){command.fullName="context assign";const code=[];return code.push("this."),code.push(command.prop),code.push(" = data;"),code=code.join(""),command.context.jaxonDelegateCall=function(data){eval(code)},command.context.jaxonDelegateCall(command.data),!0},contextAppend:function(command){command.fullName="context append";const code=[];return code.push("this."),code.push(command.prop),code.push(" += data;"),code=code.join(""),command.context.jaxonDelegateCall=function(data){eval(code)},command.context.jaxonDelegateCall(command.data),!0},contextPrepend:function(command){command.fullName="context prepend";const code=[];return code.push("this."),code.push(command.prop),code.push(" = data + this."),code.push(command.prop),code.push(";"),code=code.join(""),command.context.jaxonDelegateCall=function(data){eval(code)},command.context.jaxonDelegateCall(command.data),!0}},jaxon.cmd.script={includeScriptOnce:function(e){e.fullName="includeScriptOnce";const t=e.data,n=jaxon.config.baseDocument.getElementsByTagName("script"),o=n.length;for(let e=0;e0?returnVariable+" = ":"")+origFun+"("+args+"); ";let code="wrapper = function("+args+") { ";returnVariable.length>0&&(code+=" let "+returnVariable+" = null;");let separator="";const bLen=codeBlocks.length;for(let e=0;e0&&(code+=" return "+returnVariable+";"),code+=" } ";let wrapper=null;return context.jaxonDelegateCall=function(){eval(code)},context.jaxonDelegateCall(),wrapper}},jaxon.cmd.style={add:function(e,t){const n=jaxon.config.baseDocument,o=n.getElementsByTagName("head")[0],a=o.getElementsByTagName("link"),r=!1,s=a.length;for(let n=0;n0?skip-=1:0!=remove&&(remove>0&&(remove-=1),element.removeChild(children[e])))},endResponse:function(e){jxnElm=[]}},jaxon.ajax.callback={create:function(){const e=jaxon.config,t=jaxon.ajax.callback,n={timers:{}};return n.timers.onResponseDelay=t.setupTimer(arguments.length>0?arguments[0]:e.defaultResponseDelayTime),n.timers.onExpiration=t.setupTimer(arguments.length>1?arguments[1]:e.defaultExpirationTime),n.onPrepare=null,n.onRequest=null,n.onResponseDelay=null,n.onExpiration=null,n.beforeResponseProcessing=null,n.onFailure=null,n.onRedirect=null,n.onSuccess=null,n.onComplete=null,n},setupTimer:function(e){return{timer:null,delay:e}},clearTimer:function(e,t){if(void 0!==e.timers)void 0!==e.timers[t]&&clearTimeout(e.timers[t].timer);else for(let n=0;n0;)try{return o.ajax.request.prepare(n)?(--n.requestRetry,o.ajax.request.submit(n)):null}catch(e){if(jaxon.ajax.callback.execute([jaxon.callback,n.callback],"onFailure",n),0===n.requestRetry)throw e}}},jaxon.ajax.response={received:function(e){const t=jaxon,n=t.ajax.callback,o=t.callback,a=e.callback;if(e.aborted)return null;e.response=t.tools.queue.create(t.config.responseQueueSize),n.clearTimer([o,a],"onExpiration"),n.clearTimer([o,a],"onResponseDelay"),n.execute([o,a],"beforeResponseProcessing",e);const r=t.ajax.response.processor(e);return null==r?(n.execute([o,a],"onFailure",e),void t.ajax.response.complete(e)):r(e)},complete:function(e){if(jaxon.ajax.callback.execute([jaxon.callback,e.callback],"onComplete",e),e.cursor.onComplete(),e.status.onComplete(),delete e.functionName,delete e.requestURI,delete e.requestData,delete e.requestRetry,delete e.request,delete e.response,delete e.set,delete e.open,delete e.setRequestHeaders,delete e.setCommonRequestHeaders,delete e.setPostRequestHeaders,delete e.setGetRequestHeaders,delete e.applyRequestHeaders,delete e.finishRequest,delete e.status,delete e.cursor,"synchronous"==e.mode){let e=jaxon.tools.queue,t=jaxon.cmd.delay;for(e.pop(t.q.send),e.pop(t.q.recv);null!=(recvRequest=t.popAsyncRequest(t.q.recv));)jaxon.ajax.response.received(recvRequest);for(;null!=(nextRequest=t.popAsyncRequest(t.q.send));)jaxon.ajax.request.submit(nextRequest);null!=(nextRequest=e.peek(t.q.send))&&jaxon.ajax.request.submit(nextRequest)}},process:function(e){null!=e.timeout&&(clearTimeout(e.timeout),e.timeout=null);let t=null;for(;null!=(t=jaxon.tools.queue.pop(e));){try{if(0==jaxon.ajax.handler.execute(t))return 1==t.requeue?jaxon.tools.queue.pushFront(e,t):delete t,!1}catch(e){console.log(e)}delete t}return!0},processFragment:function(e,t,n,o){const r=jaxon.tools;for(nodeName in e)if("jxnobj"==nodeName)for(a in e[nodeName]){if(parseInt(a)!=a)continue;const n=e[nodeName][a];n.fullName="*unknown*",n.sequence=t,n.response=o.response,n.request=o,n.context=o.context,r.queue.push(o.response,n),++t}else if("jxnrv"==nodeName)n=e[nodeName];else{if("debugmsg"!=nodeName)throw{code:10004,data:command.fullName};txt=e[nodeName]}return n},processor:function(e){if(void 0!==e.responseProcessor)return e.responseProcessor;let t=e.request.getResponseHeader("content-type");if(!t)return null;let n="";if(0<=t.indexOf("application/json"))n=e.request.responseText;else if(0<=t.indexOf("text/html")){n=e.request.responseText;let t=n.indexOf('{"jxnobj"');if(t<0)return null;t>0&&(n=n.substr(t))}try{return e.request.responseJSON=JSON.parse(n),jaxon.ajax.response.json}catch(e){return null}},json:function(e){const t=jaxon,n=t.tools,o=t.ajax.callback,a=t.callback,r=e.callback;let s=e.returnValue;if(n.array.is_in(t.ajax.response.successCodes,e.request.status)){o.execute([a,r],"onSuccess",e);let c=0;"object"==typeof e.request.responseJSON&&"object"==typeof e.request.responseJSON.jxnobj&&(e.status.onProcessing(),s=t.ajax.response.processFragment(e.request.responseJSON,c,s,e));const i={fullName:"Response Complete"};i.sequence=c,i.request=e,i.context=e.context,i.cmd="rcmplt",n.queue.push(e.response,i),null==e.response.timeout&&t.ajax.response.process(e.response)}else n.array.is_in(t.ajax.response.redirectCodes,e.request.status)?(o.execute([a,r],"onRedirect",e),window.location=e.request.getResponseHeader("location"),t.ajax.response.complete(e)):n.array.is_in(t.ajax.response.errorsForAlert,e.request.status)&&(o.execute([a,r],"onFailure",e),t.ajax.response.complete(e));return s},upload:function(e){const t=jaxon,n=t.ajax.callback,o=t.callback,a=e.callback;let r=!1;const s=e.upload.iframe.contentWindow.res;if(s&&s.code?"error"===s.code&&(jaxon.ajax.message.error(s.msg),r=!0):(jaxon.ajax.message.error("The server returned an invalid response"),r=!0),r)return n.clearTimer([o,a],"onExpiration"),n.clearTimer([o,a],"onResponseDelay"),n.execute([o,a],"onFailure",e),void jaxon.ajax.response.complete(e);"success"===s.code&&(e.requestData+="&jxnupl="+encodeURIComponent(s.upl),jaxon.ajax.request._send(e))},successCodes:["0","200"],errorsForAlert:["400","401","402","403","404","500","501","502","503"],redirectCodes:["301","302","307"]},jaxon.dom={},function(e,t){"use strict";e=e||"docReady",t=t||window;let n=[],o=!1,a=!1;function r(){if(!o){o=!0;for(let e=0;e1&&1==arguments[1],n=arguments.length>2?arguments[2]:"";"string"==typeof e&&(e=jaxon.$(e));const o={};return e&&e.childNodes&&jaxon.tools.form._getValues(o,e.childNodes,t,n),o},_getValues:function(e,t,n,o){const a=t.length;for(let r=0;r=e.size},push:function(e,t){if(jaxon.tools.queue.full(e))throw{code:10003};return e.elements[e.end]=t,++e.end>=e.size&&(e.end=0),++e.count},pushFront:function(e,t){if(jaxon.tools.queue.full(e))throw{code:10003};return jaxon.tools.queue.empty(e)?jaxon.tools.queue.push(e,t):(--e.start<0&&(e.start=e.size-1),e.elements[e.start]=t,++e.count)},pop:function(e){if(jaxon.tools.queue.empty(e))return null;let t=e.elements[e.start];return delete e.elements[e.start],++e.start>=e.size&&(e.start=0),e.count--,t},peek:function(e){return jaxon.tools.queue.empty(e)?null:e.elements[e.start]}},jaxon.tools.string={doubleQuotes:function(e){return void 0!==e&&e.replace(new RegExp("'","g"),'"')},singleQuotes:function(e){return void 0!==e&&e.replace(new RegExp('"',"g"),"'")},stripOnPrefix:function(e){return 0==(e=e.toLowerCase()).indexOf("on")&&(e=e.replace(/on/,"")),e},addOnPrefix:function(e){return 0!=(e=e.toLowerCase()).indexOf("on")&&(e="on"+e),e}},String.prototype.supplant||(String.prototype.supplant=function(e){return this.replace(/\{([^{}]*)\}/g,(function(t,n){const o=e[n];return"string"==typeof o||"number"==typeof o?o:t}))}),jaxon.tools.upload={createIframe:function(e){const t="jaxon_upload_"+e.upload.id;return jaxon.cmd.node.remove(t),jaxon.cmd.node.insert(e.upload.form,"iframe",t),e.upload.iframe=jaxon.tools.dom.$(t),e.upload.iframe.name=t,e.upload.iframe.style.display="none",e.upload.form.method="POST",e.upload.form.enctype="multipart/form-data",e.upload.form.action=jaxon.config.requestURI,e.upload.form.target=t,!0},_initialize:function(e){if(!e.upload)return!1;e.upload={id:e.upload,input:null,form:null,ajax:e.ajax};const t=jaxon.tools.dom.$(e.upload.id);if(!t)return console.log("Unable to find input field for file upload with id "+e.upload.id),!1;if("file"!==t.type)return console.log("The upload input field with id "+e.upload.id+" is not of type file"),!1;if(0===t.files.length)return console.log("There is no file selected for upload in input field with id "+e.upload.id),!1;if(void 0===t.name)return console.log("The upload input field with id "+e.upload.id+" has no name attribute"),!1;if(e.upload.input=t,e.upload.form=t.form,0!=e.upload.ajax)return!0;if(!t.form){let n=t;for(;null!==n&&"FORM"!==n.nodeName;)n=n.parentNode;if(null===n)return console.log("The upload input field with id "+e.upload.id+" is not in a form"),!1;e.upload.form=n}return jaxon.tools.upload.createIframe(e),!0},initialize:function(e){jaxon.tools.upload._initialize(e),e.upload&&e.upload.ajax&&e.upload.input||e.append("postHeaders",{"content-type":e.contentType})}},jaxon.cmd.delay={popAsyncRequest:function(e){return jaxon.tools.queue.empty(e)||"synchronous"===jaxon.tools.queue.peek(e).mode?null:jaxon.tools.queue.pop(e)},retry:function(e,t){let n=e.retries;if(n){if(--n,1>n)return!1}else n=t;return e.retries=n,e.requeue=!0,!0},setWakeup:function(e,t){null!==e.timeout&&(clearTimeout(e.timeout),e.timeout=null),e.timout=setTimeout((function(){jaxon.ajax.response.process(e)}),t)},confirmCallback:function(e,t,n){if(!0===n)for(;t>0&&e.response.count>1&&null!==jaxon.tools.queue.pop(e.response);)--t;!0===e.requeue?jaxon.cmd.delay.setWakeup(e.response,30):jaxon.ajax.response.process(e.response)},confirm:function(e,t,n){return e.requeue=!0,jaxon.ajax.message.confirm(n,"",(function(){jaxon.cmd.delay.confirmCallback(e,t,!1)}),(function(){jaxon.cmd.delay.confirmCallback(e,t,!0)})),e.requeue=!1,!1}},jaxon.cmd.event={setEvent:function(e){e.fullName="setEvent";const t=jaxon.tools.string.addOnPrefix(e.prop),n=jaxon.tools.string.doubleQuotes(e.data);return("string"==typeof e.id?jaxon.$(e.id):e.id)[t]=new Function("e",n),!0},addHandler:function(e){e.fullName="addHandler";const t=e.data,n=jaxon.cmd.event.getName(e.prop),o="string"==typeof e.id?jaxon.$(e.id):e.id;return jaxon.cmd.event._addHandler(o,n,t)},removeHandler:function(e){e.fullName="removeHandler";const t=e.data,n=jaxon.cmd.event.getName(e.prop),o="string"==typeof e.id?jaxon.$(e.id):e.id;return jaxon.cmd.event._removeHandler(o,n,t)}},window.addEventListener?(jaxon.cmd.event.getName=function(e){return jaxon.tools.string.stripOnPrefix(e)},jaxon.cmd.event._addHandler=function(e,t,n){return e.addEventListener(t,jaxon.tools.dom.findFunction(n),!1),!0},jaxon.cmd.event._removeHandler=function(e,t,n){return e.removeEventListener(t,jaxon.tools.dom.findFunction(n),!1),!0}):(jaxon.cmd.event.getName=function(e){return jaxon.tools.string.addOnPrefix(e)},jaxon.cmd.event._addHandler=function(e,t,n){return e.attachEvent(t,jaxon.tools.dom.findFunction(n)),!0},jaxon.cmd.event._removeHandler=function(e,t,n){return e.detachEvent(t,jaxon.tools.dom.findFunction(n)),!0}),jaxon.cmd.form={getInput:function(e,t,n){return void 0===window.addEventListener?jaxon.cmd.form.getInput=function(e,t,n){return jaxon.config.baseDocument.createElement('')}:jaxon.cmd.form.getInput=function(e,t,n){const o=jaxon.config.baseDocument.createElement("input");return o.setAttribute("type",e),o.setAttribute("name",t),o.setAttribute("id",n),o},jaxon.cmd.form.getInput(e,t,n)},createInput:function(e){e.fullName="createInput";const t=e.id,n=e.type,o=e.data,a=e.prop;"string"==typeof t&&(t=jaxon.$(t));const r=jaxon.cmd.form.getInput(n,o,a);return t&&r&&t.appendChild(r),!0},insertInput:function(e){e.fullName="insertInput";const t=e.id,n=e.type,o=e.data,a=e.prop;"string"==typeof t&&(t=jaxon.$(t));const r=jaxon.cmd.form.getInput(n,o,a);return r&&t&&t.parentNode&&t.parentNode.insertBefore(r,t),!0},insertInputAfter:function(e){e.fullName="insertInputAfter";const t=e.id,n=e.type,o=e.data,a=e.prop;"string"==typeof t&&(t=jaxon.$(t));const r=jaxon.cmd.form.getInput(n,o,a);return r&&t&&t.parentNode&&t.parentNode.insertBefore(r,t.nextSibling),!0}},jaxon.cmd.node={assign:function(element,property,data){switch("string"==typeof element&&(element=jaxon.$(element)),property){case"innerHTML":element.innerHTML=data;break;case"outerHTML":if(void 0===element.outerHTML){const e=jaxon.config.baseDocument.createRange();e.setStartBefore(element);const t=e.createContextualFragment(data);element.parentNode.replaceChild(t,element)}else element.outerHTML=data;break;default:jaxon.tools.dom.willChange(element,property,data)&&eval("element."+property+" = data;")}return!0},append:function(element,property,data){return"string"==typeof element&&(element=jaxon.$(element)),window.insertAdjacentHTML||element.insertAdjacentHTML?"innerHTML"==property?element.insertAdjacentHTML("beforeend",data):"outerHTML"==property?element.insertAdjacentHTML("afterend",data):element[property]+=data:eval("element."+property+" += data;"),!0},prepend:function(element,property,data){return"string"==typeof element&&(element=jaxon.$(element)),eval("element."+property+" = data + element."+property),!0},replace:function(element,sAttribute,aData){const sReplace=aData.r,sSearch="innerHTML"===sAttribute?jaxon.tools.dom.getBrowserHTML(aData.s):aData.s;"string"==typeof element&&(element=jaxon.$(element)),eval("var txt = element."+sAttribute);let bFunction=!1;"function"==typeof txt&&(txt=txt.join(""),bFunction=!0);let start=txt.indexOf(sSearch);if(start>-1){let newTxt=[];for(;start>-1;){const e=start+sSearch.length;newTxt.push(txt.substr(0,start)),newTxt.push(sReplace),txt=txt.substr(e,txt.length-e),start=txt.indexOf(sSearch)}newTxt.push(txt),newTxt=newTxt.join(""),(bFunction||jaxon.tools.dom.willChange(element,sAttribute,newTxt))&&eval("element."+sAttribute+"=newTxt;")}return!0},remove:function(e){return"string"==typeof e&&(e=jaxon.$(e)),e&&e.parentNode&&e.parentNode.removeChild&&e.parentNode.removeChild(e),!0},create:function(e,t,n){"string"==typeof e&&(e=jaxon.$(e));const o=jaxon.config.baseDocument.createElement(t);return o.setAttribute("id",n),e&&e.appendChild(o),!0},insert:function(e,t,n){"string"==typeof e&&(e=jaxon.$(e));const o=jaxon.config.baseDocument.createElement(t);return o.setAttribute("id",n),e.parentNode.insertBefore(o,e),!0},insertAfter:function(e,t,n){"string"==typeof e&&(e=jaxon.$(e));const o=jaxon.config.baseDocument.createElement(t);return o.setAttribute("id",n),e.parentNode.insertBefore(o,e.nextSibling),!0},contextAssign:function(command){command.fullName="context assign";const code=[];return code.push("this."),code.push(command.prop),code.push(" = data;"),code=code.join(""),command.context.jaxonDelegateCall=function(data){eval(code)},command.context.jaxonDelegateCall(command.data),!0},contextAppend:function(command){command.fullName="context append";const code=[];return code.push("this."),code.push(command.prop),code.push(" += data;"),code=code.join(""),command.context.jaxonDelegateCall=function(data){eval(code)},command.context.jaxonDelegateCall(command.data),!0},contextPrepend:function(command){command.fullName="context prepend";const code=[];return code.push("this."),code.push(command.prop),code.push(" = data + this."),code.push(command.prop),code.push(";"),code=code.join(""),command.context.jaxonDelegateCall=function(data){eval(code)},command.context.jaxonDelegateCall(command.data),!0}},jaxon.cmd.script={includeScriptOnce:function(e){e.fullName="includeScriptOnce";const t=e.data,n=jaxon.config.baseDocument.getElementsByTagName("script"),o=n.length;for(let e=0;e0?returnVariable+" = ":"")+origFun+"("+args+"); ";let code="wrapper = function("+args+") { ";returnVariable.length>0&&(code+=" let "+returnVariable+" = null;");let separator="";const bLen=codeBlocks.length;for(let e=0;e0&&(code+=" return "+returnVariable+";"),code+=" } ";let wrapper=null;return context.jaxonDelegateCall=function(){eval(code)},context.jaxonDelegateCall(),wrapper}},jaxon.cmd.style={add:function(e,t){const n=jaxon.config.baseDocument,o=n.getElementsByTagName("head")[0],a=o.getElementsByTagName("link"),r=!1,s=a.length;for(let n=0;n0?skip-=1:0!=remove&&(remove>0&&(remove-=1),element.removeChild(children[e])))},endResponse:function(e){jxnElm=[]}},jaxon.ajax.callback={create:function(){const e=jaxon.config,t=jaxon.ajax.callback,n={timers:{}};return n.timers.onResponseDelay=t.setupTimer(arguments.length>0?arguments[0]:e.defaultResponseDelayTime),n.timers.onExpiration=t.setupTimer(arguments.length>1?arguments[1]:e.defaultExpirationTime),n.onPrepare=null,n.onRequest=null,n.onResponseDelay=null,n.onExpiration=null,n.beforeResponseProcessing=null,n.onFailure=null,n.onRedirect=null,n.onSuccess=null,n.onComplete=null,n},setupTimer:function(e){return{timer:null,delay:e}},clearTimer:function(e,t){if(void 0!==e.timers)void 0!==e.timers[t]&&clearTimeout(e.timers[t].timer);else for(let n=0;n0;)try{return o.ajax.request.prepare(n)?(--n.requestRetry,o.ajax.request.submit(n)):null}catch(e){if(jaxon.ajax.callback.execute([jaxon.callback,n.callback],"onFailure",n),0===n.requestRetry)throw e}}},jaxon.ajax.response={received:function(e){const t=jaxon,n=t.ajax.callback,o=t.callback,a=e.callback;if(e.aborted)return null;e.response=t.tools.queue.create(t.config.responseQueueSize),n.clearTimer([o,a],"onExpiration"),n.clearTimer([o,a],"onResponseDelay"),n.execute([o,a],"beforeResponseProcessing",e);const r=t.ajax.response.processor(e);return null==r?(n.execute([o,a],"onFailure",e),void t.ajax.response.complete(e)):r(e)},complete:function(e){if(jaxon.ajax.callback.execute([jaxon.callback,e.callback],"onComplete",e),e.cursor.onComplete(),e.status.onComplete(),delete e.functionName,delete e.requestURI,delete e.requestData,delete e.requestRetry,delete e.request,delete e.response,delete e.set,delete e.open,delete e.setRequestHeaders,delete e.setCommonRequestHeaders,delete e.setPostRequestHeaders,delete e.setGetRequestHeaders,delete e.applyRequestHeaders,delete e.finishRequest,delete e.status,delete e.cursor,"synchronous"==e.mode){let e=jaxon.tools.queue,t=jaxon.cmd.delay;for(e.pop(t.q.send),e.pop(t.q.recv);null!=(recvRequest=t.popAsyncRequest(t.q.recv));)jaxon.ajax.response.received(recvRequest);for(;null!=(nextRequest=t.popAsyncRequest(t.q.send));)jaxon.ajax.request.submit(nextRequest);null!=(nextRequest=e.peek(t.q.send))&&jaxon.ajax.request.submit(nextRequest)}},process:function(e){null!=e.timeout&&(clearTimeout(e.timeout),e.timeout=null);let t=null;for(;null!=(t=jaxon.tools.queue.pop(e));){try{if(0==jaxon.ajax.handler.execute(t))return 1==t.requeue?jaxon.tools.queue.pushFront(e,t):delete t,!1}catch(e){console.log(e)}delete t}return!0},processFragment:function(e,t,n,o){const r=jaxon.tools;for(nodeName in e)if("jxnobj"==nodeName)for(a in e[nodeName]){if(parseInt(a)!=a)continue;const n=e[nodeName][a];n.fullName="*unknown*",n.sequence=t,n.response=o.response,n.request=o,n.context=o.context,r.queue.push(o.response,n),++t}else if("jxnrv"==nodeName)n=e[nodeName];else{if("debugmsg"!=nodeName)throw{code:10004,data:command.fullName};txt=e[nodeName]}return n},processor:function(e){if(void 0!==e.responseProcessor)return e.responseProcessor;let t=e.request.getResponseHeader("content-type");if(!t)return null;let n="";if(0<=t.indexOf("application/json"))n=e.request.responseText;else if(0<=t.indexOf("text/html")){n=e.request.responseText;let t=n.indexOf('{"jxnobj"');if(t<0)return null;t>0&&(n=n.substr(t))}try{return e.request.responseJSON=JSON.parse(n),jaxon.ajax.response.json}catch(e){return null}},json:function(e){const t=jaxon,n=t.tools,o=t.ajax.callback,a=t.callback,r=e.callback;let s=e.returnValue;if(n.array.is_in(t.ajax.response.successCodes,e.request.status)){o.execute([a,r],"onSuccess",e);let c=0;"object"==typeof e.request.responseJSON&&"object"==typeof e.request.responseJSON.jxnobj&&(e.status.onProcessing(),s=t.ajax.response.processFragment(e.request.responseJSON,c,s,e));const i={fullName:"Response Complete"};i.sequence=c,i.request=e,i.context=e.context,i.cmd="rcmplt",n.queue.push(e.response,i),null==e.response.timeout&&t.ajax.response.process(e.response)}else n.array.is_in(t.ajax.response.redirectCodes,e.request.status)?(o.execute([a,r],"onRedirect",e),window.location=e.request.getResponseHeader("location"),t.ajax.response.complete(e)):n.array.is_in(t.ajax.response.errorsForAlert,e.request.status)&&(o.execute([a,r],"onFailure",e),t.ajax.response.complete(e));return s},upload:function(e){const t=jaxon,n=t.ajax.callback,o=t.callback,a=e.callback;let r=!1;const s=e.upload.iframe.contentWindow.res;if(s&&s.code?"error"===s.code&&(jaxon.ajax.message.error(s.msg),r=!0):(jaxon.ajax.message.error("The server returned an invalid response"),r=!0),r)return n.clearTimer([o,a],"onExpiration"),n.clearTimer([o,a],"onResponseDelay"),n.execute([o,a],"onFailure",e),void jaxon.ajax.response.complete(e);"success"===s.code&&(e.requestData+="&jxnupl="+encodeURIComponent(s.upl),jaxon.ajax.request._send(e))},successCodes:["0","200"],errorsForAlert:["400","401","402","403","404","500","501","502","503"],redirectCodes:["301","302","307"]},jaxon.dom={},function(e,t){"use strict";e=e||"docReady",t=t||window;let n=[],o=!1,a=!1;function r(){if(!o){o=!0;for(let e=0;e file, or by specifying the appropriate configuration options on a per call basis. */ -const jaxon = {}; +var jaxon = {}; /* Class: jaxon.config diff --git a/src/tools/dom.js b/src/tools/dom.js index c58a1c2..6f81272 100644 --- a/src/tools/dom.js +++ b/src/tools/dom.js @@ -1,121 +1,108 @@ jaxon.tools.dom = { - /* - Function: jaxon.tools.dom.$ - - Shorthand for finding a uniquely named element within the document. - - Parameters: - sId - (string): - The unique name of the element (specified by the ID attribute), not to be confused - with the name attribute on form elements. - - Returns: - object - The element found or null. - - Note: - This function uses the which allows to operate on the - main window document as well as documents from contained iframes and child windows. - - See also: - and - */ + /** + * Shorthand for finding a uniquely named element within the document. + * + * Note: + * This function uses the which allows to operate on the + * main window document as well as documents from contained iframes and child windows. + * + * @param {string} sId - The unique name of the element (specified by the ID attribute) + * Not to be confused with the name attribute on form elements. + * + * @returns {object} - The element found or null. + * + * @see and + */ $: function(sId) { if (!sId) return null; - //sId not an string so return it maybe its an object. - if (typeof sId != 'string') + + if (typeof sId !== 'string') return sId; const oDoc = jaxon.config.baseDocument; - const obj = oDoc.getElementById(sId); if (obj) return obj; - if (oDoc.all) return oDoc.all[sId]; return obj; }, - /* - Function: jaxon.tools.dom.getBrowserHTML - - Insert the specified string of HTML into the document, then extract it. - This gives the browser the ability to validate the code and to apply any transformations it deems appropriate. - - Parameters: - sValue - (string): - A block of html code or text to be inserted into the browser's document. + /** + * Create a div as workspace for the getBrowserHTML() function. + * + * @returns {object} - The workspace DOM element. + */ + _getWorkspace: function() { + const elWorkspace = jaxon.$('jaxon_temp_workspace'); + if (elWorkspace) { + return elWorkspace; + } - Returns: - The (potentially modified) html code or text. - */ - getBrowserHTML: function(sValue) { + // Workspace not found. Must be ceated. const oDoc = jaxon.config.baseDocument; if (!oDoc.body) - return ''; + return null; - const elWorkspace = jaxon.$('jaxon_temp_workspace'); - if (!elWorkspace) { - elWorkspace = oDoc.createElement('div'); - elWorkspace.setAttribute('id', 'jaxon_temp_workspace'); - elWorkspace.style.display = 'none'; - elWorkspace.style.visibility = 'hidden'; - oDoc.body.appendChild(elWorkspace); - } + const elNewWorkspace = oDoc.createElement('div'); + elNewWorkspace.setAttribute('id', 'jaxon_temp_workspace'); + elNewWorkspace.style.display = 'none'; + elNewWorkspace.style.visibility = 'hidden'; + oDoc.body.appendChild(elNewWorkspace); + return elNewWorkspace; + }, + + /** + * Insert the specified string of HTML into the document, then extract it. + * This gives the browser the ability to validate the code and to apply any transformations it deems appropriate. + * + * @param {string} sValue - A block of html code or text to be inserted into the browser's document. + * + * @returns {string} - The (potentially modified) html code or text. + */ + getBrowserHTML: function(sValue) { + const elWorkspace = jaxon.tools.dom._getWorkspace(); elWorkspace.innerHTML = sValue; const browserHTML = elWorkspace.innerHTML; elWorkspace.innerHTML = ''; - return browserHTML; }, - /* - Function: jaxon.tools.dom.willChange - - Tests to see if the specified data is the same as the current value of the element's attribute. - - Parameters: - element - (string or object): - The element or it's unique name (specified by the ID attribute) - attribute - (string): - The name of the attribute. - newData - (string): - The value to be compared with the current value of the specified element. - - Returns: - true - The specified value differs from the current attribute value. - false - The specified value is the same as the current value. - */ + /** + * Tests to see if the specified data is the same as the current value of the element's attribute. + * + * @param {string|object} element - The element or it's unique name (specified by the ID attribute) + * @param {string} ttribute - The name of the attribute. + * @param {string} newData - The value to be compared with the current value of the specified element. + * + * @returns {true} - The specified value differs from the current attribute value. + * @returns {false} - The specified value is the same as the current value. + */ willChange: function(element, attribute, newData) { - if ('string' == typeof element) + if ('string' === typeof element) element = jaxon.$(element); - if (element) { - let oldData; - // eval('oldData=element.' + attribute); - oldData = element[attribute]; - return (newData != oldData); + if (!element) { + return false; } - return false; + return (newData != element[attribute]); }, - /* - Function: jaxon.tools.dom.findFunction - - Find a function using its name as a string. - - Parameters: - sFuncName - (string): The name of the function to find. - - Returns: - Functiion - The function with the given name. - */ + /** + * Find a function using its name as a string. + * + * @param {string} sFuncName - The name of the function to find. + * + * @returns {object} - The function + */ findFunction: function (sFuncName) { let context = window; - const namespaces = sFuncName.split("."); - for(const i = 0; i < namespaces.length && context != undefined; i++) { - context = context[namespaces[i]]; + const names = sFuncName.split("."); + const length = names.length; + + for(let i = 0; i < length && (context); i++) { + context = context[names[i]]; } return context; }