application-prototype
Version:
Application builder - prototype
846 lines (775 loc) • 71 kB
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>constructors/js-template.js - Application Prototype - Framework</title>
<meta name="description" content="Application Prototype Framework based on Module Pattern" />
<meta name="keywords" content="javascript, js, application-prototype, prototype" />
<meta name="keyword" content="javascript, js, application-prototype, prototype" />
<meta property="og:title" content="Application Prototype - Framework"/>
<meta property="og:type" content="website"/>
<meta property="og:image" content=""/>
<meta property="og:url" content="https://labs.sgapps.io/open-source/application-prototype"/>
<script src="scripts/prettify/prettify.js"></script>
<script src="scripts/prettify/lang-css.js"></script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
<script src="scripts/nav.js" defer></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger" class="navicon-button x">
<div class="navicon"></div>
</label>
<label for="nav-trigger" class="overlay"></label>
<nav class="wrap">
<input type="text" id="nav-search" placeholder="Search" />
<h2><a href="index.html">Home</a></h2><h2><a href="https://labs.sgapps.io/open-source/application-prototype" target="_blank" class="menu-item" id="website_link" >Project Page ( Git Lab )</a></h2><h2><a href="http://gordienco.net/" target="_blank" class="menu-item" id="website_link" >About Me</a></h2><h2><a href="https://github.com/sergiu-gordienco/application-prototype" target="_blank" class="menu-item" id="github_link" >GitHub</a></h2><h3>Modules</h3><ul><li><a href="module-uriLoad.html">uriLoad</a><ul class='methods'><li data-type='method' style='display: none;'><a href="module-uriLoad.html#.link">link</a></li><li data-type='method' style='display: none;'><a href="module-uriLoad.html#.script">script</a></li></ul></li></ul><h3>Classes</h3><ul><li><a href="ApplicationPrototype.Builder.html">Builder</a><ul class='methods'><li data-type='method' style='display: none;'><a href="ApplicationPrototype.Builder.html#bind">bind</a></li><li data-type='method' style='display: none;'><a href="ApplicationPrototype.Builder.html#consoleOptions">consoleOptions</a></li><li data-type='method' style='display: none;'><a href="ApplicationPrototype.Builder.html#crudEvents">crudEvents</a></li><li data-type='method' style='display: none;'><a href="ApplicationPrototype.Builder.html#debugEnabled">debugEnabled</a></li><li data-type='method' style='display: none;'><a href="ApplicationPrototype.Builder.html#emit">emit</a></li><li data-type='method' style='display: none;'><a href="ApplicationPrototype.Builder.html#isBrowser">isBrowser</a></li><li data-type='method' style='display: none;'><a href="ApplicationPrototype.Builder.html#isNode">isNode</a></li><li data-type='method' style='display: none;'><a href="ApplicationPrototype.Builder.html#modulePath">modulePath</a></li><li data-type='method' style='display: none;'><a href="ApplicationPrototype.Builder.html#moduleRegister">moduleRegister</a></li><li data-type='method' style='display: none;'><a href="ApplicationPrototype.Builder.html#off">off</a></li><li data-type='method' style='display: none;'><a href="ApplicationPrototype.Builder.html#on">on</a></li><li data-type='method' style='display: none;'><a href="ApplicationPrototype.Builder.html#once">once</a></li><li data-type='method' style='display: none;'><a href="ApplicationPrototype.Builder.html#property">property</a></li><li data-type='method' style='display: none;'><a href="ApplicationPrototype.Builder.html#require">require</a></li><li data-type='method' style='display: none;'><a href="ApplicationPrototype.Builder.html#runModulesInFiles">runModulesInFiles</a></li></ul></li><li class="level-hide"><a href="ApplicationPrototype.Builder.Promise.html">Promise</a><ul class='methods'><li data-type='method' style='display: none;'><a href="ApplicationPrototype.Builder.Promise.html#.all">all</a></li><li data-type='method' style='display: none;'><a href="ApplicationPrototype.Builder.Promise.html#.race">race</a></li><li data-type='method' style='display: none;'><a href="ApplicationPrototype.Builder.Promise.html#.reject">reject</a></li><li data-type='method' style='display: none;'><a href="ApplicationPrototype.Builder.Promise.html#.resolve">resolve</a></li></ul></li><li><a href="ApplicationPrototype.Instance.html">Instance</a><ul class='methods'><li data-type='method' style='display: none;'><a href="ApplicationPrototype.Instance.html#bind">bind</a></li><li data-type='method' style='display: none;'><a href="ApplicationPrototype.Instance.html#crudEvents">crudEvents</a></li><li data-type='method' style='display: none;'><a href="ApplicationPrototype.Instance.html#emit">emit</a></li><li data-type='method' style='display: none;'><a href="ApplicationPrototype.Instance.html#off">off</a></li><li data-type='method' style='display: none;'><a href="ApplicationPrototype.Instance.html#on">on</a></li><li data-type='method' style='display: none;'><a href="ApplicationPrototype.Instance.html#once">once</a></li><li data-type='method' style='display: none;'><a href="ApplicationPrototype.Instance.html#property">property</a></li><li data-type='method' style='display: none;'><a href="ApplicationPrototype.Instance.html#property">property</a></li></ul></li><li><a href="async.Async.html">Async</a><ul class='methods'><li data-type='method' style='display: none;'><a href="async.Async.html#done">done</a></li><li data-type='method' style='display: none;'><a href="async.Async.html#errors">errors</a></li><li data-type='method' style='display: none;'><a href="async.Async.html#flush">flush</a></li><li data-type='method' style='display: none;'><a href="async.Async.html#index">index</a></li><li data-type='method' style='display: none;'><a href="async.Async.html#processing">processing</a></li><li data-type='method' style='display: none;'><a href="async.Async.html#receive">receive</a></li><li data-type='method' style='display: none;'><a href="async.Async.html#reserve">reserve</a></li><li data-type='method' style='display: none;'><a href="async.Async.html#responses">responses</a></li><li data-type='method' style='display: none;'><a href="async.Async.html#run">run</a></li><li data-type='method' style='display: none;'><a href="async.Async.html#wait">wait</a></li></ul></li><li><a href="ExtensionsPrototype.slDOMSet.html">slDOMSet</a><ul class='methods'><li data-type='method' style='display: none;'><a href="ExtensionsPrototype.slDOMSet.html#add">add</a></li><li data-type='method' style='display: none;'><a href="ExtensionsPrototype.slDOMSet.html#attr">attr</a></li><li data-type='method' style='display: none;'><a href="ExtensionsPrototype.slDOMSet.html#attr">attr</a></li><li data-type='method' style='display: none;'><a href="ExtensionsPrototype.slDOMSet.html#attr">attr</a></li><li data-type='method' style='display: none;'><a href="ExtensionsPrototype.slDOMSet.html#attr">attr</a></li><li data-type='method' style='display: none;'><a href="ExtensionsPrototype.slDOMSet.html#config">config</a></li><li data-type='method' style='display: none;'><a href="ExtensionsPrototype.slDOMSet.html#config">config</a></li><li data-type='method' style='display: none;'><a href="ExtensionsPrototype.slDOMSet.html#each">each</a></li><li data-type='method' style='display: none;'><a href="ExtensionsPrototype.slDOMSet.html#env">env</a></li><li data-type='method' style='display: none;'><a href="ExtensionsPrototype.slDOMSet.html#eq">eq</a></li><li data-type='method' style='display: none;'><a href="ExtensionsPrototype.slDOMSet.html#filter">filter</a></li><li data-type='method' style='display: none;'><a href="ExtensionsPrototype.slDOMSet.html#find">find</a></li><li data-type='method' style='display: none;'><a href="ExtensionsPrototype.slDOMSet.html#get">get</a></li><li data-type='method' style='display: none;'><a href="ExtensionsPrototype.slDOMSet.html#get">get</a></li><li data-type='method' style='display: none;'><a href="ExtensionsPrototype.slDOMSet.html#map">map</a></li><li data-type='method' style='display: none;'><a href="ExtensionsPrototype.slDOMSet.html#set">set</a></li><li data-type='method' style='display: none;'><a href="ExtensionsPrototype.slDOMSet.html#set">set</a></li><li data-type='method' style='display: none;'><a href="ExtensionsPrototype.slDOMSet.html#unique">unique</a></li></ul></li><li><a href="JSTemplateComponent.html">JSTemplateComponent</a></li><li><a href="RequestModule.html">RequestModule</a><ul class='members'><li data-type='member' style='display: none;'><a href="RequestModule.html#.READY_STATE_DONE">READY_STATE_DONE</a></li><li data-type='member' style='display: none;'><a href="RequestModule.html#.READY_STATE_HEADERS_RECEIVED">READY_STATE_HEADERS_RECEIVED</a></li><li data-type='member' style='display: none;'><a href="RequestModule.html#.READY_STATE_LOADING">READY_STATE_LOADING</a></li><li data-type='member' style='display: none;'><a href="RequestModule.html#.READY_STATE_OPENED">READY_STATE_OPENED</a></li><li data-type='member' style='display: none;'><a href="RequestModule.html#.READY_STATE_UNSENT">READY_STATE_UNSENT</a></li></ul><ul class='methods'><li data-type='method' style='display: none;'><a href="RequestModule.html#.ParamsParser">ParamsParser</a></li><li data-type='method' style='display: none;'><a href="RequestModule.html#async">async</a></li><li data-type='method' style='display: none;'><a href="RequestModule.html#async">async</a></li><li data-type='method' style='display: none;'><a href="RequestModule.html#basicAuth">basicAuth</a></li><li data-type='method' style='display: none;'><a href="RequestModule.html#basicAuth">basicAuth</a></li><li data-type='method' style='display: none;'><a href="RequestModule.html#config">config</a></li><li data-type='method' style='display: none;'><a href="RequestModule.html#configurator">configurator</a></li><li data-type='method' style='display: none;'><a href="RequestModule.html#headers">headers</a></li><li data-type='method' style='display: none;'><a href="RequestModule.html#headers">headers</a></li><li data-type='method' style='display: none;'><a href="RequestModule.html#method">method</a></li><li data-type='method' style='display: none;'><a href="RequestModule.html#method">method</a></li><li data-type='method' style='display: none;'><a href="RequestModule.html#open">open</a></li><li data-type='method' style='display: none;'><a href="RequestModule.html#readyState">readyState</a></li><li data-type='method' style='display: none;'><a href="RequestModule.html#request">request</a></li><li data-type='method' style='display: none;'><a href="RequestModule.html#response">response</a></li><li data-type='method' style='display: none;'><a href="RequestModule.html#send">send</a></li><li data-type='method' style='display: none;'><a href="RequestModule.html#status">status</a></li><li data-type='method' style='display: none;'><a href="RequestModule.html#statusText">statusText</a></li><li data-type='method' style='display: none;'><a href="RequestModule.html#timeout">timeout</a></li><li data-type='method' style='display: none;'><a href="RequestModule.html#timeout">timeout</a></li><li data-type='method' style='display: none;'><a href="RequestModule.html#url">url</a></li><li data-type='method' style='display: none;'><a href="RequestModule.html#url">url</a></li><li data-type='method' style='display: none;'><a href="RequestModule.html#withCredentials">withCredentials</a></li><li data-type='method' style='display: none;'><a href="RequestModule.html#withCredentials">withCredentials</a></li></ul></li></ul><h3>Events</h3><ul><li class="level-hide"><a href="ApplicationPrototype.Instance.html#.event:__afterGet">__afterGet</a></li><li class="level-hide"><a href="ApplicationPrototype.Instance.html#.event:__afterGet::propName">__afterGet::propName</a></li><li class="level-hide"><a href="ApplicationPrototype.Instance.html#.event:__afterSet">__afterSet</a></li><li class="level-hide"><a href="ApplicationPrototype.Instance.html#.event:__afterSet::propName">__afterSet::propName</a></li><li class="level-hide"><a href="ApplicationPrototype.Instance.html#.event:__onGet">__onGet</a></li><li class="level-hide"><a href="ApplicationPrototype.Instance.html#.event:__onGet::propName">__onGet::propName</a></li><li class="level-hide"><a href="ApplicationPrototype.Instance.html#.event:__onSet">__onSet</a></li><li class="level-hide"><a href="ApplicationPrototype.Instance.html#.event:__onSet::propName">__onSet::propName</a></li></ul><h3>Interfaces</h3><ul><li><a href="ApplicationPrototype.html">ApplicationPrototype</a></li><li><a href="Array.html">Array</a><ul class='methods'><li data-type='method' style='display: none;'><a href="Array.html#__pointerFilter">__pointerFilter</a></li><li data-type='method' style='display: none;'><a href="Array.html#base64encode">base64encode</a></li><li data-type='method' style='display: none;'><a href="Array.html#bytesToHex">bytesToHex</a></li><li data-type='method' style='display: none;'><a href="Array.html#inArray">inArray</a></li><li data-type='method' style='display: none;'><a href="Array.html#indexOfSect">indexOfSect</a></li><li data-type='method' style='display: none;'><a href="Array.html#max">max</a></li><li data-type='method' style='display: none;'><a href="Array.html#min">min</a></li><li data-type='method' style='display: none;'><a href="Array.html#move">move</a></li><li data-type='method' style='display: none;'><a href="Array.html#resetArray">resetArray</a></li><li data-type='method' style='display: none;'><a href="Array.html#shuffle">shuffle</a></li><li data-type='method' style='display: none;'><a href="Array.html#split">split</a></li><li data-type='method' style='display: none;'><a href="Array.html#splitSect">splitSect</a></li><li data-type='method' style='display: none;'><a href="Array.html#toBinaryString">toBinaryString</a></li><li data-type='method' style='display: none;'><a href="Array.html#toBlob">toBlob</a></li><li data-type='method' style='display: none;'><a href="Array.html#toBytesBinary">toBytesBinary</a></li><li data-type='method' style='display: none;'><a href="Array.html#toBytesEscaped">toBytesEscaped</a></li><li data-type='method' style='display: none;'><a href="Array.html#toParamObj">toParamObj</a></li><li data-type='method' style='display: none;'><a href="Array.html#toStringUtf8">toStringUtf8</a></li><li data-type='method' style='display: none;'><a href="Array.html#unique">unique</a></li></ul></li><li><a href="ArrayBuffer.html">ArrayBuffer</a><ul class='methods'><li data-type='method' style='display: none;'><a href="ArrayBuffer.html#base64encode">base64encode</a></li><li data-type='method' style='display: none;'><a href="ArrayBuffer.html#toArray">toArray</a></li><li data-type='method' style='display: none;'><a href="ArrayBuffer.html#toBytes">toBytes</a></li><li data-type='method' style='display: none;'><a href="ArrayBuffer.html#toStringUtf8">toStringUtf8</a></li></ul></li><li><a href="async.html">async</a><ul class='methods'><li data-type='method' style='display: none;'><a href="async.html#.flow">flow</a></li><li data-type='method' style='display: none;'><a href="async.html#.flow_map">flow_map</a></li><li data-type='method' style='display: none;'><a href="async.html#.map">map</a></li><li data-type='method' style='display: none;'><a href="async.html#.waterfall">waterfall</a></li><li data-type='method' style='display: none;'><a href="async.html#.waterfall_map">waterfall_map</a></li></ul></li><li><a href="Blob.html">Blob</a><ul class='methods'><li data-type='method' style='display: none;'><a href="Blob.html#toArrayBuffer">toArrayBuffer</a></li><li data-type='method' style='display: none;'><a href="Blob.html#toURL">toURL</a></li></ul></li><li><a href="BrowserSessionModule.html">BrowserSessionModule</a><ul class='methods'><li data-type='method' style='display: none;'><a href="BrowserSessionModule.html#.clear">clear</a></li><li data-type='method' style='display: none;'><a href="BrowserSessionModule.html#.findItems">findItems</a></li><li data-type='method' style='display: none;'><a href="BrowserSessionModule.html#.getItem">getItem</a></li><li data-type='method' style='display: none;'><a href="BrowserSessionModule.html#.getItems">getItems</a></li><li data-type='method' style='display: none;'><a href="BrowserSessionModule.html#.removeItem">removeItem</a></li><li data-type='method' style='display: none;'><a href="BrowserSessionModule.html#.removeItems">removeItems</a></li><li data-type='method' style='display: none;'><a href="BrowserSessionModule.html#.setItem">setItem</a></li><li data-type='method' style='display: none;'><a href="BrowserSessionModule.html#.setItems">setItems</a></li></ul></li><li><a href="Buffer.html">Buffer</a><ul class='methods'><li data-type='method' style='display: none;'><a href="Buffer.html#base64encode">base64encode</a></li><li data-type='method' style='display: none;'><a href="Buffer.html#toArray">toArray</a></li><li data-type='method' style='display: none;'><a href="Buffer.html#toBytes">toBytes</a></li><li data-type='method' style='display: none;'><a href="Buffer.html#toStringUtf8">toStringUtf8</a></li></ul></li><li><a href="ExtensionsPrototype.html">ExtensionsPrototype</a><ul class='members'><li data-type='member' style='display: none;'><a href="ExtensionsPrototype.html#._">_</a></li><li data-type='member' style='display: none;'><a href="ExtensionsPrototype.html#.__">__</a></li><li data-type='member' style='display: none;'><a href="ExtensionsPrototype.html#.fn">fn</a></li><li data-type='member' style='display: none;'><a href="ExtensionsPrototype.html#.object">object</a></li><li data-type='member' style='display: none;'><a href="ExtensionsPrototype.html#.string">string</a></li><li data-type='member' style='display: none;'><a href="ExtensionsPrototype.html#.WindowExtend">WindowExtend</a></li></ul></li><li><a href="Function.html">Function</a><ul class='methods'><li data-type='method' style='display: none;'><a href="Function.html#runInWorker">runInWorker</a></li><li data-type='method' style='display: none;'><a href="Function.html#toWorker">toWorker</a></li><li data-type='method' style='display: none;'><a href="Function.html#toWorkerURL">toWorkerURL</a></li></ul></li><li><a href="HTMLElement.html">HTMLElement</a></li><li><a href="JSTemplate.html">JSTemplate</a><ul class='methods'><li data-type='method' style='display: none;'><a href="JSTemplate.html#.attrParser">attrParser</a></li><li data-type='method' style='display: none;'><a href="JSTemplate.html#.expressionBuilder">expressionBuilder</a></li><li data-type='method' style='display: none;'><a href="JSTemplate.html#.nodeParser">nodeParser</a></li><li data-type='method' style='display: none;'><a href="JSTemplate.html#.parseTextNodes">parseTextNodes</a></li><li data-type='method' style='display: none;'><a href="JSTemplate.html#.textParser">textParser</a></li></ul></li><li><a href="JSTemplateComponent.contextInstance.html">contextInstance</a><ul class='members'><li data-type='member' style='display: none;'><a href="JSTemplateComponent.contextInstance.html#.node">node</a></li><li data-type='member' style='display: none;'><a href="JSTemplateComponent.contextInstance.html#.references">references</a></li></ul><ul class='methods'><li data-type='method' style='display: none;'><a href="JSTemplateComponent.contextInstance.html#.redraw">redraw</a></li><li data-type='method' style='display: none;'><a href="JSTemplateComponent.contextInstance.html#.redrawForce">redrawForce</a></li></ul></li><li><a href="JSTemplateComponent.contextWithInstance.html">contextWithInstance</a><ul class='members'><li data-type='member' style='display: none;'><a href="JSTemplateComponent.contextWithInstance.html#.__instance">__instance</a></li><li data-type='member' style='display: none;'><a href="JSTemplateComponent.contextWithInstance.html#.__lifeCycle">__lifeCycle</a></li><li data-type='member' style='display: none;'><a href="JSTemplateComponent.contextWithInstance.html#.state">state</a></li></ul></li><li><a href="JSTemplateComponent.contextWithoutInstance.html">contextWithoutInstance</a><ul class='members'><li data-type='member' style='display: none;'><a href="JSTemplateComponent.contextWithoutInstance.html#.__lifeCycle">__lifeCycle</a></li><li data-type='member' style='display: none;'><a href="JSTemplateComponent.contextWithoutInstance.html#.state">state</a></li></ul></li><li><a href="String.html">String</a><ul class='methods'><li data-type='method' style='display: none;'><a href="String.html#add_Class">add_Class</a></li><li data-type='method' style='display: none;'><a href="String.html#add_Class">add_Class</a></li><li data-type='method' style='display: none;'><a href="String.html#base64decode">base64decode</a></li><li data-type='method' style='display: none;'><a href="String.html#base64decode">base64decode</a></li><li data-type='method' style='display: none;'><a href="String.html#base64decodeBytes">base64decodeBytes</a></li><li data-type='method' style='display: none;'><a href="String.html#base64decodeBytes">base64decodeBytes</a></li><li data-type='method' style='display: none;'><a href="String.html#base64decodeBytesArray">base64decodeBytesArray</a></li><li data-type='method' style='display: none;'><a href="String.html#base64decodeBytesArray">base64decodeBytesArray</a></li><li data-type='method' style='display: none;'><a href="String.html#base64decodeClean">base64decodeClean</a></li><li data-type='method' style='display: none;'><a href="String.html#base64decodeClean">base64decodeClean</a></li><li data-type='method' style='display: none;'><a href="String.html#base64encode">base64encode</a></li><li data-type='method' style='display: none;'><a href="String.html#base64encode">base64encode</a></li><li data-type='method' style='display: none;'><a href="String.html#base64encodeBytes">base64encodeBytes</a></li><li data-type='method' style='display: none;'><a href="String.html#base64encodeBytes">base64encodeBytes</a></li><li data-type='method' style='display: none;'><a href="String.html#base64encodeBytesArray">base64encodeBytesArray</a></li><li data-type='method' style='display: none;'><a href="String.html#base64encodeBytesArray">base64encodeBytesArray</a></li><li data-type='method' style='display: none;'><a href="String.html#base64encodeClean">base64encodeClean</a></li><li data-type='method' style='display: none;'><a href="String.html#base64encodeClean">base64encodeClean</a></li><li data-type='method' style='display: none;'><a href="String.html#buildQuery">buildQuery</a></li><li data-type='method' style='display: none;'><a href="String.html#buildQuery">buildQuery</a></li><li data-type='method' style='display: none;'><a href="String.html#buildSearchArray">buildSearchArray</a></li><li data-type='method' style='display: none;'><a href="String.html#buildSearchArray">buildSearchArray</a></li><li data-type='method' style='display: none;'><a href="String.html#cleanTags">cleanTags</a></li><li data-type='method' style='display: none;'><a href="String.html#cleanTags">cleanTags</a></li><li data-type='method' style='display: none;'><a href="String.html#decodeURI">decodeURI</a></li><li data-type='method' style='display: none;'><a href="String.html#decodeURI">decodeURI</a></li><li data-type='method' style='display: none;'><a href="String.html#decryptAes">decryptAes</a></li><li data-type='method' style='display: none;'><a href="String.html#decryptAes">decryptAes</a></li><li data-type='method' style='display: none;'><a href="String.html#decryptTea">decryptTea</a></li><li data-type='method' style='display: none;'><a href="String.html#decryptTea">decryptTea</a></li><li data-type='method' style='display: none;'><a href="String.html#del_Class">del_Class</a></li><li data-type='method' style='display: none;'><a href="String.html#del_Class">del_Class</a></li><li data-type='method' style='display: none;'><a href="String.html#encodeURI">encodeURI</a></li><li data-type='method' style='display: none;'><a href="String.html#encodeURI">encodeURI</a></li><li data-type='method' style='display: none;'><a href="String.html#encryptAes">encryptAes</a></li><li data-type='method' style='display: none;'><a href="String.html#encryptAes">encryptAes</a></li><li data-type='method' style='display: none;'><a href="String.html#encryptTea">encryptTea</a></li><li data-type='method' style='display: none;'><a href="String.html#encryptTea">encryptTea</a></li><li data-type='method' style='display: none;'><a href="String.html#escape">escape</a></li><li data-type='method' style='display: none;'><a href="String.html#escape">escape</a></li><li data-type='method' style='display: none;'><a href="String.html#escapeHex">escapeHex</a></li><li data-type='method' style='display: none;'><a href="String.html#escapeHex">escapeHex</a></li><li data-type='method' style='display: none;'><a href="String.html#fnd_Class">fnd_Class</a></li><li data-type='method' style='display: none;'><a href="String.html#fnd_Class">fnd_Class</a></li><li data-type='method' style='display: none;'><a href="String.html#fromHex">fromHex</a></li><li data-type='method' style='display: none;'><a href="String.html#fromHex">fromHex</a></li><li data-type='method' style='display: none;'><a href="String.html#fromHtml">fromHtml</a></li><li data-type='method' style='display: none;'><a href="String.html#fromHtml">fromHtml</a></li><li data-type='method' style='display: none;'><a href="String.html#lcfirst">lcfirst</a></li><li data-type='method' style='display: none;'><a href="String.html#lcfirst">lcfirst</a></li><li data-type='method' style='display: none;'><a href="String.html#markdown">markdown</a></li><li data-type='method' style='display: none;'><a href="String.html#match_str">match_str</a></li><li data-type='method' style='display: none;'><a href="String.html#match_str">match_str</a></li><li data-type='method' style='display: none;'><a href="String.html#md5">md5</a></li><li data-type='method' style='display: none;'><a href="String.html#md5">md5</a></li><li data-type='method' style='display: none;'><a href="String.html#parseUrl">parseUrl</a></li><li data-type='method' style='display: none;'><a href="String.html#parseUrl">parseUrl</a></li><li data-type='method' style='display: none;'><a href="String.html#parseUrlVars">parseUrlVars</a></li><li data-type='method' style='display: none;'><a href="String.html#sha1">sha1</a></li><li data-type='method' style='display: none;'><a href="String.html#sha1">sha1</a></li><li data-type='method' style='display: none;'><a href="String.html#sha256">sha256</a></li><li data-type='method' style='display: none;'><a href="String.html#sha256">sha256</a></li><li data-type='method' style='display: none;'><a href="String.html#subs">subs</a></li><li data-type='method' style='display: none;'><a href="String.html#subs">subs</a></li><li data-type='method' style='display: none;'><a href="String.html#subs">subs</a></li><li data-type='method' style='display: none;'><a href="String.html#swp_case">swp_case</a></li><li data-type='method' style='display: none;'><a href="String.html#swp_case">swp_case</a></li><li data-type='method' style='display: none;'><a href="String.html#toArrayBufferFromUtf8">toArrayBufferFromUtf8</a></li><li data-type='method' style='display: none;'><a href="String.html#toArrayBufferFromUtf8">toArrayBufferFromUtf8</a></li><li data-type='method' style='display: none;'><a href="String.html#toHex">toHex</a></li><li data-type='method' style='display: none;'><a href="String.html#toHex">toHex</a></li><li data-type='method' style='display: none;'><a href="String.html#toHtml">toHtml</a></li><li data-type='method' style='display: none;'><a href="String.html#toHtml">toHtml</a></li><li data-type='method' style='display: none;'><a href="String.html#toHtmlSimple">toHtmlSimple</a></li><li data-type='method' style='display: none;'><a href="String.html#toHtmlSimple">toHtmlSimple</a></li><li data-type='method' style='display: none;'><a href="String.html#toRegexp">toRegexp</a></li><li data-type='method' style='display: none;'><a href="String.html#toRegexp">toRegexp</a></li><li data-type='method' style='display: none;'><a href="String.html#ucfirst">ucfirst</a></li><li data-type='method' style='display: none;'><a href="String.html#ucfirst">ucfirst</a></li><li data-type='method' style='display: none;'><a href="String.html#unescape">unescape</a></li><li data-type='method' style='display: none;'><a href="String.html#unescape">unescape</a></li><li data-type='method' style='display: none;'><a href="String.html#unicode">unicode</a></li><li data-type='method' style='display: none;'><a href="String.html#unicode">unicode</a></li><li data-type='method' style='display: none;'><a href="String.html#utf8">utf8</a></li><li data-type='method' style='display: none;'><a href="String.html#utf8">utf8</a></li><li data-type='method' style='display: none;'><a href="String.html#utf8decode">utf8decode</a></li><li data-type='method' style='display: none;'><a href="String.html#utf8decode">utf8decode</a></li><li data-type='method' style='display: none;'><a href="String.html#utf8encode">utf8encode</a></li><li data-type='method' style='display: none;'><a href="String.html#utf8encode">utf8encode</a></li><li data-type='method' style='display: none;'><a href="String.html#utf8need">utf8need</a></li><li data-type='method' style='display: none;'><a href="String.html#utf8need">utf8need</a></li></ul></li><li></li></ul><h3>Global</h3><ul><li><a href="global.html#ApplicationBuilderConstructor">ApplicationBuilderConstructor</a></li><li><a href="global.html#ApplicationBuilderExports">ApplicationBuilderExports</a></li><li><a href="global.html#ApplicationPrototypeConstructor">ApplicationPrototypeConstructor</a></li><li><a href="global.html#NodeInterface">NodeInterface</a></li><li><a href="global.html#RequestModuleConstructor">RequestModuleConstructor</a></li></ul>
</nav>
<div id="main">
<h1 class="page-title">constructors/js-template.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>/**
* @memberof JSTemplate
* @typedef {Object} JSTemplateModule
* @property {JSTemplate.JSTemplateParseContent} parseContent
* @property {object} config
* @property {number} [config.RENDER_FPS=15]
* @property {number} [config.REMOVE_EMPTY_NODES=true]
*/
/**
* Module used for template rendering
* @example
* Application.require('js-template').then(function (jsTemplate) {
* jsTemplate.parseContent(
* document.body,
* function (err, config) { console.log(config) },
* { context: {}, args: { item: 'sample reference' }}
* );
* }, console.error);
* @interface JSTemplate
* @returns {JSTemplate.JSTemplateModule}
*/
var libs;
/**
* @typedef {Object} jsTemplate_textResult
* @memberof JSTemplate
* @property {string} [type='text']
* @property {JSTemplate.jsTemplate_textResultData} data
*/
/**
* @typedef {Object} jsTemplate_textResultData
* @memberof JSTemplate
* @property {Array<Text>} nodes
* @property {Array<Text>} initialNodes
* @property {string} code
*/
/**
* @typedef {Object} parseTextNodesConfig
* @memberof JSTemplate
* @property {object} [args={}] arguments
* @property {object} [context={}] execution context
* @property {string} [start='{{'] start token
* @property {string} [end='}}'] end token
* @property {Array<JSTemplate.jsTemplate_textResult>} [textNodes] array of TextNodes
* @property {Array<Text>} [buffer] (technical property) buffer
* @property {boolean} [opened=false] (technical property)
* @property {Array<string>} [__argsNames] (technical property)
* @property {Array<any>} [__argsValues] (technical property)
*/
/**
* Expression Builder
* @protected
* @function
* @memberof JSTemplate
* @param {string} code
* @param {JSTemplate.parseTextNodesConfig} config
*/
var expressionBuilder = function (code, config) {
var expressionCall;
/* jshint -W054 */
try {
expressionCall = (
Function.apply(
config.context || {},
config.__argsNames.concat(
[
"return (" +
code +
" );"
]
)
)
);
} catch (er) {
expressionCall = function () {
return [
"{{ ", er, ":\n", code,
" }}"
];
};
}
/* jshint +W054 */
return expressionCall;
};
/**
* @protected
* @function
* @memberof JSTemplate
* @param {Array<Text>} bf
* @param {parseTextNodesConfig} config
* @returns {JSTemplate.jsTemplate_textResult}
*/
var textParser = function (bf, config) {
var er;
var code = [];
bf.forEach(function (node) {
if (node.parentNode) {
code.push(node.data);
}
});
/* jshint +W054 */
/* jshint -W014 */
var _methods = {
type: 'text',
data: {
nodes: bf,
initialNodes: bf,
code: code.join("")
}
};
return _methods;
};
/**
* @protected
* @function
* @param {JSTemplate.jsTemplate_textResult} item
* @param {JSTemplate.parseTextNodesConfig} config
* @param {function(Error, any): void} cb
*/
textParser.value = function (item, config, cb) {
var expressionCall = expressionBuilder(item.data.code, config);
var value = expressionCall.apply(config.context, config.__argsValues);
if (
value &&
typeof(value) === "object" &&
typeof(value.then) === "function" &&
typeof(value.catch) === "function"
) {
value.then(function (result) {
cb(null, result);
}, function (err) {
cb(err, null);
});
} else {
cb(null, value);
}
};
/**
* @protected
* @function
* @param {JSTemplate.jsTemplate_textResult} item
* @param {Array<Node|Text>|Text|Node} val
* @param {function(Error): void} cb
*/
textParser.update = function (item, val, cb) {
var nNodes = [], er;
try {
if (typeof (val) !== "undefined") {
if (!Array.isArray(val)) {
val = [val];
}
val.forEach(function (v) {
if (v instanceof Node) {
nNodes.push(v);
} else {
//@ts-ignore
if (v && typeof (v.toString) === "function") {
//@ts-ignore
nNodes.push(document.createTextNode(v.toString()));
} else {
nNodes.push(document.createTextNode("" + v));
}
}
});
}
} catch (er) {
console.error(er);
}
if (!nNodes.length) {
nNodes.push(document.createTextNode(""));
}
// removing old nodes
// TODO divList[0].isEqualNode(divList[2])
var equalNodesArr = true;
if (item.data.nodes.length !== nNodes.length) {
equalNodesArr = false;
} else {
item.data.nodes.forEach(function (n, i) {
if (!n.isEqualNode(nNodes[i])) {
equalNodesArr = false;
}
});
}
if (equalNodesArr) {
cb(null);
return;
}
var nodes = item.data.nodes;
item.data.nodes = nNodes;
var markNode = document.createTextNode("");
nodes[0].parentNode.insertBefore(markNode, nodes[0]);
nNodes.forEach(function (node) {
markNode.parentNode.insertBefore(node, markNode);
});
markNode.parentNode.removeChild(markNode);
nodes.filter(function (node) {
var found = false;
var i;
for (i = 0; i < nNodes.length; i++) {
if (node === nNodes[i]) {
found = true;
break;
}
}
return !found;
}).forEach(function (node) {
if (node.parentNode) {
node.parentNode.removeChild(node);
}
});
if (cb) {
cb(null);
}
};
/**
* @callback parseTextNodesCallback
* @memberof JSTemplate
* @param {Error} err
* @param {JSTemplate.parseTextNodesConfig} config
*/
/**
* @protected
* @function
* @memberof JSTemplate
* @param {HTMLElement|Node|Text} textNode
* @param {JSTemplate.parseTextNodesCallback} cb
* @param {JSTemplate.parseTextNodesConfig} config
*/
var parseTextNodes = function (textNode, cb, config) {
if (!config && typeof(cb) !== "function") {
config = cb;
cb = function () {};
}
if (!config) {
config = {
opened: false,
buffer: [],
args: {},
context: {},
start: "{{",
end: "}}",
textNodes: []
};
} else {
config.opened = false;
config.buffer = [];
config.args = (config.args || {});
config.context = (config.context || {});
config.start = (config.start || '{{');
config.end = (config.end || '}}');
config.textNodes = [];
}
/**
* nodes parser
* @private
* @function
* @param {(ChildNode|Node|Text)} textNode
*/
var ate = function (textNode) {
//@ts-ignore
var text = (textNode ? (textNode.data || '') : '') + '';
var firstNode, nextNode, index, cNode;
if (textNode && textNode.nodeType === Node.TEXT_NODE) {
/**
* @private
* @type {string}
*/
//@ts-ignore
text = textNode.data;
}
if (config.opened) {
//@ts-ignore
index = (textNode === null ? "" : text).indexOf(config.end);
//@ts-ignore
if (index === -1 || textNode === null) {
if (
!textNode ||
!textNode.previousSibling ||
textNode.previousSibling.nodeType !== Node.TEXT_NODE
) {
config.buffer = [];
config.opened = false;
} else {
//@ts-ignore
if (textNode !== null) {
//@ts-ignore
config.buffer.push(textNode);
}
}
} else {
config.opened = false;
if (index) {
//@ts-ignore
firstNode = document.createTextNode(text.subs(index));
config.buffer.push(firstNode);
}
if (index + config.end.length < text.length) {
//@ts-ignore
nextNode = document.createTextNode(text.subs(index + config.end.length, 0));
}
if (firstNode) {
textNode.parentNode.insertBefore(firstNode, textNode);
}
cNode = textParser(config.buffer.map(function (v) {
return v;
}), {
start: config.start,
end: config.end
});
config.textNodes.push(cNode);
if (nextNode) {
textNode.parentNode.insertBefore(nextNode, textNode);
}
config.buffer = [];
textNode.parentNode.removeChild(textNode);
if (nextNode) {
ate(nextNode);
}
}
} else if (textNode) {
index = text.indexOf(config.start);
if (index !== -1) {
config.opened = true;
config.buffer = [];
if (index) {
//@ts-ignore
firstNode = document.createTextNode(text.subs(index));
}
if (index + config.end.length < text.length) {
//@ts-ignore
nextNode = document.createTextNode(text.subs(index + config.end.length, 0));
// config.buffer.push(nextNode);
}
if (firstNode) {
textNode.parentElement.insertBefore(firstNode, textNode);
}
if (nextNode) {
textNode.parentElement.insertBefore(nextNode, textNode);
}
textNode.parentNode.removeChild(textNode);
if (nextNode) {
ate(nextNode);
} else {
ate(textNode.nextSibling || null);
}
} else {
ate(textNode.nextSibling || null);
}
}
};
if (textNode.nodeType === Node.ELEMENT_NODE) {
if (textNode.childNodes[0]) {
ate(textNode.childNodes[0]);
}
}
if (textNode.nodeType === Node.TEXT_NODE) {
ate(textNode);
}
if (typeof (cb) === "function") {
cb(null, config);
}
return config;
};
/**
* @typedef {Object} jsTemplate_Attribute
* @memberof JSTemplate
* @property {string} name
* @property {string} value
*/
/**
* @typedef {Object} jsTemplate_attrResultAttributeData
* @memberof JSTemplate
* @property {string} name attribute name
* @property {string} code executable code
* @property {HTMLElement} node node element
* @property {any} [buffer] ( technical property )
* @property {boolean} [inline=false] should be value be parsed
* @property {boolean} [postProcess=false] should be value be parsed
*/
/**
* @typedef {Object} jsTemplate_attrResult
* @memberof JSTemplate
* @property {('event'|'attribute'|'binding'|'macro')} type
* @property {JSTemplate.jsTemplate_Attribute} attr
* @property {JSTemplate.jsTemplate_attrResultAttributeData} data
*/
/**
* @typedef {Object} jsTemplateAttrData
* @memberof JSTemplate
* @property {Array<JSTemplate.jsTemplate_attrResult>} nodes
* @property {Array<JSTemplate.jsTemplate_textResult>} texts
* @property {Array<JSTemplate.jsTemplateAttrData>} children
* @property {Object<string,JSTemplate.jsTemplate_attrResult>} _macro
* @property {boolean} [HAS_POST_PROCESS=false]
*/
/**
* Parsing NodeElement Attribute
* @protected
* @memberof JSTemplate
* @param {JSTemplate.jsTemplate_Attribute} attr
* @returns {JSTemplate.jsTemplate_attrResult}
*/
var attrParser = function (attr, node) {
/**
* @private
* @type {JSTemplate.jsTemplate_attrResult}
*/
var attrResult = {
type: null,
attr: attr,
data: null
};
if (attr.name.match(/^ev-.+/)) {
attrResult.type = 'event';
attrResult.data = {
name: attr.name.substring(3),
code: 'function (event) { ' + attr.value + ' }',
node: node
};
} else if (attr.name.match(/^\((.+)\)$/)) {
attrResult.type = 'event';
attrResult.data = {
name: attr.name.match(/^\((.+)\)$/)[1],
code: 'function (event) { ' + attr.value + ' }',
node: node
};
} else if (attr.name.match(/^\[\((.+)\)\]$/)) {
attrResult.type = 'binding';
attrResult.data = {
name: attr.name.match(/^\[\((.+)\)\]$/)[1],
code: 'function (event) { if (event.__args) with (event.__args) { ' + attr.value + ' = event.__value; }; return ( ' + attr.value + ' ); }',
node: node
};
} else if (attr.name.match(/^\[(.+)\]$/)) {
attrResult.type = 'attribute';
attrResult.data = {
name: attr.name.match(/^\[(.+)\]$/)[1],
code: attr.value,
node: node
};
} else if (attr.name.match(/^\*(.*)$/)) {
attrResult.type = 'macro';
attrResult.data = {
name: attr.name.match(/^\*(.*)$/)[1].toLowerCase(),
code: attr.value,
node: node
};
if (['for', 'template'].indexOf(attrResult.data.name) !== -1) {
attrResult.data.postProcess = true;
}
} else if (attr.name.match(/^js-.+$/)) {
attrResult.type = 'attribute';
attrResult.data = {
name: attr.name.substring(3),
code: attr.value,
inline: true,
node: node
};
} else if (attr.value.match(/\{\{.+\}\}/)) {
attrResult.type = 'attribute';
attrResult.data = {
name: attr.name,
inline: true,
code: attr.value,
node: node
};
} else {
attrResult = null;
}
if (attrResult) {
attrResult.data.buffer = null;
}
return attrResult;
};
/**
* @protected
* @function
* @param {JSTemplate.jsTemplate_attrResult} item
* @param {(Node|Text|Array<Node|Text>|function)} value
* @param {function (Error, boolean): void} cb
* @param {JSTemplate.parseTextNodesConfig} config
*/
attrParser.update = function (item, value, config, cb) {
var status = true;
switch (item.type) {
case "attribute":
if (value === null) {
if (item.data.node.hasAttribute(item.data.name)) {
item.data.node.removeAttribute(item.data.name);
}
} else {
if (
value !== item.data.buffer
) {
item.data.buffer = value;
item.data.node.setAttribute(
item.data.name,
//@ts-ignore
value
);
}
}
break;
case "macro":
switch (item.data.name) {
case "if":
if (item.data.buffer === null) {
item.data.buffer = {
current: item.data.node,
empty: document.createTextNode(''),
valid: item.data.node
};
}
if (value) {
if (item.data.buffer.current !== item.data.buffer.valid) {
item.data.buffer.current.parentElement.insertBefore(
item.data.buffer.valid,
item.data.buffer.current
);
item.data.buffer.current.parentElement.removeChild(
item.data.buffer.current
);
item.data.buffer.current = item.data.buffer.valid;
}
} else {
status = false;
if (item.data.buffer.current !== item.data.buffer.empty) {
item.data.buffer.current.parentElement.insertBefore(
item.data.buffer.empty,
item.data.buffer.current
);
item.data.buffer.current.parentElement.removeChild(
item.data.buffer.current
);
item.data.buffer.current = item.data.buffer.empty;
}
}
break;
case "class":
if (value === null) {
if (item.data.buffer !== value) {
item.data.buffer = value;
if (
item.data.node.hasAttribute(item.data.name)
) {
item.data.node.removeAttribute(item.data.name);
}
}
} else if (typeof (value) === "string") {
if (item.data.buffer !== value) {
item.data.buffer = value;
item.data.node.setAttribute(item.data.name, value);
}
} else if (typeof (value) === "object") {
var name, result = [];
for (name in value) {
if (value[name]) {
result.push(name);
}
}
var resultValue = result.sort().join(' ');
if (item.data.buffer !== resultValue) {
item.data.buffer = resultValue;
if (resultValue) {
item.data.node.setAttribute(item.data.name, resultValue);
} else if (
item.data.node.hasAttribute(item.data.name)
) {
item.data.node.removeAttribute(item.data.name);
}
}
} else {
console.warn("🐛 Incorrect value for JSTemplate:class:item ", item, "; value: ", value);
}
break;
case "for":
if (item.data.buffer === null) {
var _key = (
//@ts-ignore
item.data.node.attrdata.__JS_TEMPLATE._macro['key'] || {
data: {
code: 'key'
}
}
).data.code || 'key';
var _ref = (
//@ts-ignore
item.data.node.attrdata.__JS_TEMPLATE._macro['ref'] || {
data: {
code: 'item'
}
}
).data.code || 'item';
item.data.buffer = {
template: item.data.node,
current: [],
reference: document.createTextNode(''),
cache: [],
createNode: function (args) {
var _item = {
node: item.data.node.cloneNode(true),
args: Object.assign({}, config.args, args)
};
//@ts-ignore
_item.node.renderJs(
config.context,
_item.args,
function (err) {
if (err) console.error(err);
}
);
item.data.buffer.reference.parentNode.insertBefore(
_item.node,
item.data.buffer.reference
);
return _item;
},
allocNode: function (args) {
var _item;
if (item.data.buffer.cache.length) {
_item = item.data.buffer.cache.shift();
Object.assign(_item.args, args);
// console.log(_item, {..._item.args}, args, config.context);
_item.node.renderJs(
config.context,
_item.args,
function (err) {
if (err) console.error(err);
}
);
item.data.buffer.reference.parentNode.insertBefore(
_item.node,
item.data.buffer.reference
);
} else {
_item = item.data.buffer.createNode(args);
}
item.data.buffer.current.push(_item);
return _item;
},
cacheCurrent: function (length) {
var _item;
while (item.data.buffer.current.length > length) {
_item = item.data.buffer.current.pop();
if (_item) {
item.data.buffer.cache.push(
_item
);
_item.node.parentElement.removeChild(_item.node);
}
}
},
update: function (value) {
if (Array.isArray(value)) {
value.forEach(function (_item, index) {
var args = {};
args[_key] = index;
args[_ref] = _item;
if (!item.data.buffer.current[index]) {
item.data.buffer.allocNode(args);
} else {
Object.assign(
item.data.buffer.current[index].args,
args
);
item.data.buffer.current[index].node.renderJs(
config.context,
item.data.buffer.current[index].args,
function (err) {
if (err) console.error(err);
}
);
}
});
item.data.buffer.cacheCurrent(value.length);
} else if (value && typeof (value) === "object") {
var _keys = Object.keys(value);
_keys.sort().forEach(function (indexKey, index) {
var args = {};
args[_key] = indexKey;
args[_ref] = value[indexKey];
if (!item.data.buffer.current[index]) {
item.data.buffer.allocNode(Object.assign({}, args));
} else {
Object.assign(
item.data.buffer.current[index].args,
args
);
// item.data.buffer.current[index].node.renderJs();
item.data.buffer.current[index].node.renderJs(
config.context,
item.data.buffer.current[index].args,
function (err) {
if (err) console.error(err);
}
);
}
});
item.data.buffer.cacheCurrent(_keys.length);
}
}
};
item.data.buffer.current = [];
item.data.node.parentElement.insertBefore(
item.data.buffer.reference,
item.data.node
);
item.data.node.parentElement.removeChild(
item.data.node
);
}
item.data.buffer.update(value);
break;
}
break;
case "event":
if (!item.data.buffer) {
item.data.buffer = value;
if (typeof (value) === "function") {
//@ts-ignore
item.data.node.addEventListener(
item.data.name,
function (event) {
attrParser.value(item, config, function (err, value) {
if (err) {
console.error(err);
return;
}
if (value.apply(
config.context,
[event]
) !== false) {
config.__redraw();
}
});
}
);
// } else if (
// //@ts-ignore
// value && typeof (value) === "object