Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: DOM database

  1. #1
    New Coder
    Join Date
    Jan 2014
    Posts
    12
    Thanks
    1
    Thanked 1 Time in 1 Post

    DOM database

    I am developing a client-side DOM object database with API to properties and methods. A JSON string is loaded into browser memory for interactive content control. The DOM objects may be third party addons like tree, grid, chart etc. Demo is available JS2DX HTML Rendering Demo sample site JSON string here: http://js2dx.com/demo/site.js arrays of JSON elements that represent separate pages: http://js2dx.com/demo/pages.js and the code here: http://js2dx.com/demo/objects.js

  2. #2
    New Coder
    Join Date
    Jan 2014
    Posts
    12
    Thanks
    1
    Thanked 1 Time in 1 Post
    This is code pasted into message in case forum users prefer to see it here

    Code:
    'use strict'
    
    
    function DX(_container){
        
        this.container = _container || document.getElementsByTagName('body')[0]
    
        this.dat = {}
        this.dat.b= []
        this.dat.f= []
        this.dat.k= []
        this.dat.n= []
        this.dat.s= []
        this.dat.dom= []
    
        this.enm = {}
        this.enm.i = -1
        this.enm.k = -1
        this.enm.f = -1
        this.enm.s = -1
        this.enm.n = -1
        this.enm.b = -1
        this.enm.dom = -1
    
        this.stk = {}
        this.stk.reset = function(that) {
    
            that.stk.id      = []
            that.stk.tags    = []
            that.stk.pid     = -1
            that.stk.struct  = null
            that.stk.elm     = [that.container]}
        this.stk.reset(this)
    
        this.idx = {}
        this.idx.ik = {}
        this.idx.ic = {"-1":[0]}
        this.idx.in = {}
        this.idx.id = {}
        this.idx.it = []
        this.idx.ip = []
        this.idx.ki = {}
        this.idx.pg = []
        this.idx.ig = []
    
        this.idx.wsk = {
            id: {},
            className: {}}}
    
    
    DX.prototype = {}
    
    DX.prototype.tags = ['div','button','ol','li']
    DX.prototype.branch = ['branch']
    
    DX.prototype.fn = {}
    
    DX.prototype.fn.i   = function(){ this.enm.i += 1; return this.enm.i; }
    DX.prototype.fn.k   = function(){ this.enm.k += 1; return this.enm.k; }
    DX.prototype.fn.s   = function(){ this.enm.s += 1; return this.enm.s; }
    DX.prototype.fn.n   = function(){ this.enm.n += 1; return this.enm.n; }
    DX.prototype.fn.b   = function(){ this.enm.b += 1; return this.enm.b; }
    DX.prototype.fn.f   = function(){ this.enm.f += 1; return this.enm.f; }
    DX.prototype.fn.dom = function(){ this.enm.dom += 1; return this.enm.dom; }
    
    DX.prototype.fn.it  = function(_t)     { this.idx.it.push(_t) }
    DX.prototype.fn.ip  = function(_p)     { this.idx.ip.push(_p) }
    DX.prototype.fn.ig  = function(_g)     { this.idx.ig.push(_g) }
    DX.prototype.fn.in  = function(_i, _n) { this.idx.in[_i] = _n }
    DX.prototype.fn.ik  = function(_i, _k) { this.idx.ik[_i] = _k }  
    DX.prototype.fn.id  = function(_i, _d) { this.idx.id[_i] = _d }
    DX.prototype.fn.ic  = function(_i, _c) { this.idx.ic[_i] = this.idx.ic[_i] || [];  this.idx.ic[_i].push(_c); }
    DX.prototype.fn.ki  = function(_k, _i) { this.idx.ki[_k] = this.idx.ki[_k] || [];  this.idx.ki[_k].push(_i); }
    DX.prototype.fn.wsk = function(_key, _s, _k)
                                           { this.idx.wsk[_key][_s] = this.idx.wsk[_key][_s] || [];  this.idx.wsk[_key][_s].push(_k); }
    
    DX.prototype.fn.unq = function(_dat, _fn, _val) {
        var idx = _dat.indexOf(_val)
        if (!~idx) {
            idx = _fn.call(this)
            _dat[idx] = _val }
        return idx }
    DX.prototype.fn.nuq = function(_dat, _fn, _val) {
        var idx = _fn.call(this)
        _dat[idx] = _val
        return idx}
    
    DX.prototype.k   = function(_val){ return this.fn.unq.call(this, this.dat.k,   this.fn.k, _val) }
    DX.prototype.s   = function(_val){ return this.fn.unq.call(this, this.dat.s,   this.fn.s, _val) }
    DX.prototype.dom = function(_val){ return this.fn.nuq.call(this, this.dat.dom, this.fn.dom, _val) }
        
    
    
    DX.prototype.object   = function(_data){
    
        var id,
            i = 0,
            ln,
            n = this.fn.i.call(this),
            res,
            k,
            tag
    
        this.stk.id.push(n)
        this.fn.ip.call(this, this.stk.pid)
        id = this.stk.id[this.stk.id.length - 1]
        this.stk.pid = id
    
        if (_data.constructor === Array) {
    
            this.fn.it.call(this, 'a')
            ln = _data.length
    
            for (; i < ln; i += 1) {
    
                res = this.a(_data[i])
                this.fn.ic.call(this, id, res)  }}
    
        else {
    
            this.fn.it.call(this, 'o')
    
            for (i in _data) {
    
                res = this.a(_data[i])
                k = this.k(i)
                tag = this.tags.indexOf(i)
    
                if (tag !== -1) this.fn.ig.call(this, res)
                if (this.idx.wsk[i]) this.fn.wsk.call(this, i, this.dat.s[this.idx.in[res]], id)
                this.fn.ic.call(this, id, res)
    
                this.fn.ik.call(this, res, k)
                this.fn.ki.call(this, k, res)}}
    
        this.stk.id.splice(this.stk.id.length - 1, 1)
    
        this.stk.pid = this.stk.id[this.stk.id.length - 1]
    
        return id}
    
    
    DX.prototype.string   = function(_data){
    
        var i = this.fn.i.call(this),
            s = this.s(_data)
    
        this.fn.it.call(this, 's')
        this.fn.in.call(this, i, s)
    
        this.fn.ip.call(this, this.stk.pid)
    
        return i}
    
    DX.prototype.function = function(_data){}
    DX.prototype.number   = function(_data){}
    DX.prototype.boolean  = function(_data){}
    
    
    DX.prototype.a = function(_data) {
    
        return this[typeof _data].call(this, _data) }
    
    
    
    DX.prototype.b = function(_i) {
    
        var typ = this.idx.it[_i],
            out = {
                a: [],
                o: {},
                s: this.dat.s[ this.idx.in[_i] ]}[typ],
            i = 0,
            arr = this.idx.ic[_i],
            ln =  0
    
        if (arr) ln = arr.length
    
        for (; i < ln; i += 1) ({
    
            a: function(){out[i] = this.b( arr[i] )},
            o: function(){out[ this.dat.k[  this.idx.ik[  arr[i]   ] ] ] = this.b( arr[i] )}})[typ].call(this)
    
        return out}
    
    
    
    DX.prototype.c = function(_i) {
    
        var container,
            i = 0,
            arr = this.idx.ic[_i] || [],
            ln =  arr.length,
            typ = this.idx.it[_i],
            tag,
            id,dom,
            fn = {
                a: function(){ this.c(id) },
                o: function(){
    
                container = this.stk.elm[this.stk.elm.length - 1]
                tag = this.dat.k[  this.idx.ik[ id ] ]
    
                if (this.tags.indexOf(tag) !== -1) {
    
                    if (this.map[0] == null || ~this.map.indexOf(id)) {
    
                    dom = this.dom(document.createElement(tag))
                    this.stk.elm.push(this.dat.dom[dom])
                    this.fn.id.call(this, id, dom)
                    container.appendChild(this.dat.dom[dom])
                    this.c(id)
                    this.stk.elm.splice(this.stk.elm.length - 1, 1)}}
    
                else {
    
                   ({o:  function(){
    
                        this.stk.elm.push(container[tag])
                        this.c(id)
                        this.stk.elm.splice(this.stk.elm.length - 1, 1) },
    
                   s:  function(){ container[ tag ] = this.dat.s[ this.idx.in[ id ] ] },
                   a:  function(){ this.c(id) }})[this.idx.it[ id ]].call(this) } } }
    
        for (; i < ln; i += 1) {
    
            id = arr[i]
            fn[typ].call(this) }}
    
    
    DX.prototype.d = function(_str) { return this.dat.dom[this.idx.id[this.idx.wsk.id[_str]]] }
    DX.prototype.reset = function() {this.stk.reset(this)}
    
    
    DX.prototype.map = []
    
    DX.prototype.e1 = function(_data) { 
    
       var that = this
       return _data.map(function(_val) { if (that.idx.ki[that.dat.k.indexOf('nodes')].indexOf(_val) !== -1) return _val }).filter(function(_val ){if (_val) return _val })[0]}
    
    
    DX.prototype.e2 = function(_id) {
    
        this.stk.tags = []
        this.e3(_id)
        return this.stk.tags} 
    
    
    DX.prototype.e3 = function(_id) {
    
        var i = 0,
            ln = this.idx.ic[_id],
            that = this
    
        for (; i < ln; i += 1) {
            this.idx.ic[_id] . map (
                function(_val) { 
                    if (that.idx.ig.indexOf(_val) !== -1)
                    this.e2(_val)
                    this.stk.tags.push(_val)
                    return _val })}}
    
    
    DX.prototype.e = function(_data) { 
                     
        var id,
            i = 0,
            ln,
            that = this,
            idx
            
        function logger(_tx) {
                    return
            console.log(_tx + '   i: '  + i + '  - id: ' + id + '  - ic: ' + dx.idx.ic[id] + '  - dat: ' + JSON.stringify(_data[i]) + ' - ' + JSON.stringify(dx.map)) }
    
    
        function e4(_log) { 
    
            that.stk.id.push(idx)
            logger(_log)
            that.e( _data[i] )
            that.stk.id.splice(that.stk.id.length - 1, 1) }
    
       
    
        if (!this.stk.id.length) this.stk.id.push( 0 )
        id = this.stk.id[this.stk.id.length -1]
    
        if (_data.constructor === Array) {
    
            ln = _data.length
    
            for (; i < ln; i += 1) {
    
                if (_data[i].constructor === Array) {
    
                    logger('AA')
                    this.e(_data[i]) }
    
                else if (_data[i].constructor === Object) {
    
                    idx = this.idx.ic[id] [  Object.keys(_data[i])[0] ] 
                    if (this.idx.it[idx] !== 'a')  { this.map.push(idx)}
                    e4('AO') }
    
                else if (_data[i].constructor === Number) {
    
                    logger('AN')
                    idx = this.idx.ic[ this.idx.ic[ id ] [ _data[i] ] ] [0]
                    this.e5(idx)
                    }
    
                else logger('ERROR A') } }
        
        else if (_data.constructor === Object) {
    
            for (i in _data) {
    
                if (_data[i].constructor === Array) {
    
                    idx = this.idx.ic[id][0]
    
                    if (this.idx.it[ id ] === 'o') {
                        if (this.idx.ig[ idx ] !== -1) this.map.push( idx )
                        idx = this.e1(this.idx.ic[ idx ])}
                    else
                        if ( that.idx.ki[that.dat.k.indexOf('nodes')].indexOf( this.idx.ip[id] ) !== -1 ) idx = id 
    
                    e4( 'OA')  }
    
                else if (_data[i].constructor === Object) {
    
                    idx = this.e1(this.idx.ic[ id ])
                    if (!idx) idx =  this.idx.ic[id] [  Object.keys(_data[i])[0] ]
                    e4('OO') }
    
                else if (_data[i].constructor === Number) {
                    idx = this.e1( this.idx.ic[ this.idx.ic[ this.idx.ic[ id ] [ i ] ] [0] ] )
                    this.map.push( this.idx.ic[ this.idx.ic[ id ] [ i ] ][0] )
                    e4('ON') }
    
                else logger('ERROR O') }}
    
         else {
             this.e5( this.idx.ic[ this.idx.ic[ id ] [ _data ]] [0] )
             logger('N') }
    
        return id}
    
    
    DX.prototype.e5 = function(_idx) { 
    
        var i = 0,
            ln = this.idx.ic[_idx].length
    
        this.map.push(_idx)
    
        for (; i < ln; i += 1) {
    
            if (this.idx.ig.indexOf(this.idx.ic[_idx][i]) !== -1) {
    
                this.e5(this.idx.ic[_idx][i])}}}
    
    
    var mp = [{1:  [ {0: {1: 1}} ]   }  , {2:  { 1: [ {1: [1 ,0]} ] }  },  3]
    
    DX.prototype.feed = function() { 
    
        var i = 0,
            ln = this.enm.i,
            
            out = {
                items: [],
                dom:   []}
    
    
    
        for (; i < ln ; i += 1) {
    
            out.items.push({
               i: i,
               k: this.dat.k[this.idx.ik[i]],
               c: JSON.stringify(this.idx.ic[i]),
               n: this.idx.in[i],
               t: this.idx.it[i],
               p: this.idx.ip[i],
               v: this.idx.id[i] ? this.dat.dom [ this.idx.id[i] ].nodeName : this.dat [ this.idx.it[i] ] ?  this.dat [ this.idx.it[i] ][ this.idx.in[i] ] : '' })}
    
        return out}

  3. Users who have thanked Gonki for this post:

    Ellisnto8876 (07-04-2016)


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •