2016-09-19 06:37:35 +00:00
var ref = function ( a , b ) { for ( var d = null ; null == d || a . hasOwnProperty ( d ) ; ) d = "$" + ( 1048576 + Math . floor ( 15728639 * Math . random ( ) ) ) . toString ( 16 ) + "$" ; a [ d ] = b ; return d } , FormBuilder = function ( a ) { this . form _object = a } ; FormBuilder . prototype = { form _object : this . form _object , defs _object : { } , parent _element : null , built _form : null , root _element : null , ref _table : { } } ;
FormBuilder . 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-]+)$/ , ref _pri : /^\$[a-f0-9]{6}\$$/ } ; FormBuilder . spread _attr = [ "children" , "next_nodes" , "prev_nodes" , "attributes" , "node_link" ] ; FormBuilder . allowed _attr = "node node_type next_nodes prev_nodes attributes children text repeat" . split ( " " ) ;
FormBuilder . prototype . add _definition = function ( a ) { for ( var b in a ) this . defs _object [ b ] = a [ b ] } ; FormBuilder . prototype . build = function ( a ) { a = null == a ? { } : a ; for ( var b in a ) a [ b ] = ref ( this . ref _table , a [ b ] ) ; this . built _form = JSON . parse ( JSON . stringify ( this . form _object ) ) ; this . built _form = FormBuilder . formatFormObject ( this . built _form , this . defs _object ) ; this . built _form = FormBuilder . replaceStatements ( this . built _form , a , this . defs _object , this . ref _table ) } ;
FormBuilder . prototype . attach = function ( a ) { if ( ! ( a instanceof Element ) && null == this . parent _element ) return ! 1 ; this . parent _element = a instanceof Element ? a : this . parent _element } ; FormBuilder . formatFormObject = function ( a , b ) { if ( a . hasOwnProperty ( "children" ) ) for ( var d in a . children ) a . children [ d ] . parent = a , FormBuilder . formatFormObject ( a . children [ d ] , b ) ; return a } ;
2016-09-19 07:51:34 +00:00
FormBuilder . fetchNodeDefinition = function ( a , b ) { var d , f ; r = FormBuilder . regex . reg _in _key ; if ( "undefined" != typeof b && b . hasOwnProperty ( a ) ) return { def : b [ a ] } ; for ( d in b ) if ( r . test ( d ) && ( f = new RegExp ( d . slice ( 1 , - 1 ) ) , f . test ( a ) ) ) { matches = { } ; for ( f = 1 ; f < RegExp . length && 10 > f ; f ++ ) matches [ "$" + f ] = RegExp [ "$" + f ] ; return { def : b [ d ] , scope : matches } } return { } } ;
FormBuilder . replaceStatements = function ( a , b , d , f ) { a = a instanceof Object ? a : { } ; b = b instanceof Object ? JSON . parse ( JSON . stringify ( b ) ) : { } ; var c , h , e , g , k , l , n ; if ( a . hasOwnProperty ( "scope" ) && a . scope instanceof Object ) for ( c in a . scope ) b [ c ] = a . scope [ c ] ; if ( a . hasOwnProperty ( "node" ) && "string" == typeof a . node && ( e = FormBuilder . fetchNodeDefinition ( a . node , d ) , e . hasOwnProperty ( "def" ) && ( a . node _link = JSON . parse ( JSON . stringify ( e . def ) ) , e . hasOwnProperty ( "scope" ) ) ) ) for ( c in e . scope ) b [ c ] = e . scope [ c ] ; for ( c in a ) if ( "string" == typeof a [ c ] ) if ( a [ c ] =
[ a [ c ] ] , e = FormBuilder . replaceStatementsArray ( a [ c ] [ 0 ] , b ) , ! 1 !== e ) a [ c ] [ 0 ] = e ; else { h = FormBuilder . regex . reg _out _val ; g = - 1 ; for ( l = [ ] ; null !== ( e = h . exec ( a [ c ] [ 0 ] ) ) && ! ( g >= h . lastIndex ) ; ) g = h . lastIndex , l . push ( e [ 1 ] ) ; for ( e in l ) b . hasOwnProperty ( l [ e ] ) || ( b [ l [ e ] ] = "" ) , h = new RegExp ( "{\\$" + l [ e ] [ 1 ] + "}" , "g" ) , a [ c ] [ 0 ] = a [ c ] [ 0 ] . replace ( h , b [ l [ e ] ] ) ; if ( ! ( 0 < l . length ) ) for ( k in a [ c ] = FormBuilder . replaceStatementsPrimary ( a [ c ] , b ) , h = FormBuilder . regex . arr _out _val , a [ c ] ) if ( null != a [ c ] [ k ] ) { for ( n = [ ] ; null !== ( e = h . exec ( a [ c ] [ k ] ) ) ; ) n . push ( e ) ; g = 0 ; l =
[ ] ; for ( e in n ) ( 0 < g || 0 < n [ e ] . index ) && l . push ( a [ c ] [ k ] . substr ( g , n [ e ] . index ) ) , b . hasOwnProperty ( n [ e ] [ 1 ] ) || ( b [ n [ e ] [ 1 ] ] = "" ) , l . push ( b [ n [ e ] [ 1 ] ] ) , g = n [ e ] . index + n [ e ] [ 0 ] . length ; g < a [ c ] [ k ] . length && l . push ( a [ c ] [ k ] . substr ( g , a [ c ] [ k ] . length ) ) ; 0 < n . length && ( a [ c ] = a [ c ] . slice ( 0 , k ) . concat ( l ) . concat ( a [ c ] . slice ( k + 1 ) ) ) } } for ( c in a ) FormBuilder . regex . pri _in _key . test ( c ) ? b [ c . substring ( 1 ) ] = ref ( f , a [ c ] ) : FormBuilder . regex . arr _in _key . test ( c ) && ( b [ c . substring ( 2 ) ] = ref ( f , a [ c ] ) ) ; b = JSON . parse ( JSON . stringify ( b ) ) ; for ( c in a ) if ( - 1 < FormBuilder . spread _attr . indexOf ( c ) ) if ( a [ c ] instanceof
Array ) for ( var p in a [ c ] ) FormBuilder . replaceStatements ( a [ c ] [ p ] , b , d , f ) ; else a [ c ] instanceof Object && FormBuilder . replaceStatements ( a [ c ] , b , d , f ) ; return a } ; FormBuilder . replaceStatementsArray = function ( a , b ) { var d = null , d = FormBuilder . regex . arr _out _set . exec ( a ) ; if ( null === d ) return ! 1 ; b . hasOwnProperty ( d [ 1 ] ) || ( b [ d [ 1 ] ] = [ ] ) ; return b [ d [ 1 ] ] } ;
FormBuilder . replaceStatementsPrimary = function ( a , b ) { var d = FormBuilder . regex . pri _out _val , f = null , c = [ ] , h , e , g , k ; for ( g = 0 ; g < a . length ; g ++ ) { m = null ; c = [ ] ; h = 0 ; for ( e = [ ] ; null !== ( f = d . exec ( a [ g ] ) ) ; ) c . push ( f ) ; for ( f = 0 ; f < c . length ; f ++ ) k = c [ f ] [ 1 ] , ( 0 < h || 0 < c [ f ] . index ) && e . push ( a [ g ] . substr ( h , c [ f ] . index - h ) ) , b . hasOwnProperty ( k ) || ( b [ k ] = "" ) , e . push ( b [ k ] ) , h = c [ f ] . index + c [ f ] [ 0 ] . length ; h < a [ g ] . length && e . push ( a [ g ] . substr ( h , a [ g ] . length ) ) ; a = a . slice ( 0 , g ) . concat ( e ) . concat ( a . slice ( g + 1 ) ) } return a } ;
FormBuilder . buildString = function ( a , b ) { var d , f = "" ; if ( "string" == typeof b && FormBuilder . regex . ref _pri . test ( b ) ) return a [ b ] ; for ( d in b ) f = FormBuilder . regex . ref _pri . test ( b [ d ] ) && a . hasOwnProperty ( b [ d ] ) ? a [ b [ d ] ] instanceof Array ? f + ( "" + FormBuilder . buildString ( a , a [ b [ d ] ] ) ) : f + ( "" + a [ b [ d ] ] ) : f + ( "" + b [ d ] . toString ( ) ) ; return f } ;