YANG Model update for A1 Adapter
[ccsdk/features.git] / sdnr / wt / devicemanager / provider / src / main / resources / elasticsearch / plugins / head / src / vendor / joey / joey.js
1 /**
2  * Copyright 2010-2013 Ben Birch
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this software except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 (function() {
17
18         var joey = this.joey = function joey(elementDef, parentNode) {
19                 return createNode( elementDef, parentNode, parentNode ? parentNode.ownerDocument : this.document );
20         };
21
22         var shortcuts = joey.shortcuts = {
23                 "text" : "textContent",
24                 "cls" : "className"
25         };
26
27         var plugins = joey.plugins = [
28                 function( obj, context ) {
29                         if( typeof obj === 'string' ) {
30                                 return context.createTextNode( obj );
31                         }
32                 },
33                 function( obj, context ) {
34                         if( "tag" in obj ) {
35                                 var el = context.createElement( obj.tag );
36                                 for( var attr in obj ) {
37                                         addAttr( el, attr, obj[ attr ], context );
38                                 }
39                                 return el;
40                         }
41                 }
42         ];
43
44         function addAttr( el, attr, value, context ) {
45                 attr = shortcuts[attr] || attr;
46                 if( attr === 'children' ) {
47                         for( var i = 0; i < value.length; i++) {
48                                 createNode( value[i], el, context );
49                         }
50                 } else if( attr === 'style' || attr === 'dataset' ) {
51                         for( var prop in value ) {
52                                 el[ attr ][ prop ] = value[ prop ];
53                         }
54                 } else if( attr.indexOf("on") === 0 ) {
55                         el.addEventListener( attr.substr(2), value, false );
56                 } else if( value !== undefined ) {
57                         el[ attr ] = value;
58                 }
59         }
60
61         function createNode( obj, parent, context ) {
62                 var el;
63                 if( obj != null ) {
64                         plugins.some( function( plug ) {
65                                 return ( el = plug( obj, context ) );
66                         });
67                         parent && parent.appendChild( el );
68                         return el;
69                 }
70         }
71
72 }());