public
Description: JavaScript Application Framework - JS library only
Homepage: http://www.sproutcore.com
Clone URL: git://github.com/sproutit/sproutcore.git
sproutcore / deprecated / node_descriptor.js
100644 73 lines (62 sloc) 2.05 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// ========================================================================
// SproutCore -- JavaScript Application Framework
// Copyright ©2006-2008, Sprout Systems, Inc. and contributors.
// Portions copyright ©2008 Apple, Inc. All rights reserved.
// ========================================================================
 
require('core') ;
 
/**
This object can generate HTML DOM elements from a hash-based description of
the nodes. See the NodeDescriptor wiki page for complete docs.
 
See https://wiki.sproutit.com/engineering/show/NodeDescriptor
 
@deprecated
*/
SC.NodeDescriptor = {
  create: function(descriptor, opts) {
    if (!opts) opts = {} ;
    // collect info from descriptor
    var tag = opts.tag || descriptor.tag || 'div' ;
    var className = opts.cssClass || descriptor.cssClass ;
    var elementId = opts.id || descriptor.id ;
    var style = opts.style || descriptor.style ;
    var innerHTML = opts.innerHTML || descriptor.innerHTML ;
    if (!innerHTML) {
      var childNodes = opts.childNodes || descriptor.childNodes ;
    }
 
    // create element
    var ret = $(document.createElement(tag)) ;
    if (className) ret.className = className ;
    if (elementId) ret.id = elementId ;
    if (style) {
      for (var name in style) element.style[name.camelize()] = style[name];
    }
    
    // apply extra attributes
    for(var attr in descriptor) {
      if (this.ignoredProperties.indexOf(attr) == -1) {
        ret.setAttribute(attr,descriptor[attr]) ;
      }
    }
    
    // build child nodes, if they exist.
    if (innerHTML) {
      ret.innerHTML = innerHTML ;
    } else if (childNodes) {
      var that = this ;
      childNodes.each(function(desc) {
        ret.appendChild(that.create(desc)) ;
      }) ;
that=null;
childNodes=null;
    }
    
try{
     return ret ;
}finally{
//ie7 memory leaks
tag=null;
className=null;
elementId=null;
style=null;
innerHTML=null;
ret=null;
}
  },
  
  ignoredProperties: ['tag','cssClass','id','style','childNodes','innerHTML']
};