NxTIC/js/lib/min/element-object.js

6 lines
1.5 KiB
JavaScript
Raw Normal View History

function references(a){return{$:a}}
var ElementObject=function(a,c){if(a instanceof Object){c=c instanceof Object?c:{};var b,d;!a.hasOwnProperty("repeat")||isNaN(a.repeat)&&ElementObject.regex.arr_out_set.test(a.repeat);b=(b=a.hasOwnProperty("node"))&&"string"==typeof a.node;d=(d=a.hasOwnProperty("node_type"))&&"string"==typeof a.node_type;a.hasOwnProperty("prev_nodes");a.hasOwnProperty("next_nodes");a.hasOwnProperty("children");a.hasOwnProperty("attributes");a.hasOwnProperty("text");a.hasOwnProperty("listeners");a.hasOwnProperty("scope");
if(d)this.element=document.createElement(node_type);else if(b){if(!this.fetchDefinition(c))return null;scope=this.scope;return new ElementObject}a&&(this.node="undefined"==typeof node?null:node)}};ElementObject.prototype={node:this.node,node_type:null,prev_nodes:[],next_nodes:[],children:[],attributes:{},text:null,listeners:[],repeat:1,scope:{},parent:null,node_def:null,element:null};
ElementObject.regex={reg_in_key:/^\/\^(.+)\$\/$/,reg_out_val:/\{(\$[1-9])\}/,pri_out_val:/\{([a-z-]+)\}/g,pri_in_key:/^\$([a-z-]+)$/,arr_out_set:/^\{\{([a-z-]+)\}\}$/,arr_out_val:/\{([a-z-]+)\.([a-z-]+)\}/g,arr_in_key:/^\$\$([a-z-]+)$/};
ElementObject.prototype.fetchDefinition=function(a){var c,b;r=ElementObject.regex.reg_in_key;if(a.hasOwnProperty(this.node))return this.node_def=a[this.node],!0;for(c in a)if(r.test(c)&&(b=new RegExp(c.slice(1,-1)),b.test(this.node))){for(b=1;b<RegExp.length&&10>b;b++)this.scope["$"+b]=RegExp["$"+b];this.node_def=a[c];return!0}return!1};