Ext.DomHelper.html
15.1 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
<div class="body-wrap">
<div class="top-tools">
<a class="inner-link" href="#Ext.DomHelper-props"><img src="../resources/images/default/s_wev8.gif" class="item-icon icon-prop">Properties</a>
<a class="inner-link" href="#Ext.DomHelper-methods"><img src="../resources/images/default/s_wev8.gif" class="item-icon icon-method">Methods</a>
<a class="inner-link" href="#Ext.DomHelper-events"><img src="../resources/images/default/s_wev8.gif" class="item-icon icon-event">Events</a>
<a class="bookmark" href="../docs/?class=Ext.DomHelper"><img src="../resources/images/default/s_wev8.gif" class="item-icon icon-fav">Direct Link</a>
</div>
<h1>Class Ext.DomHelper</h1>
<table cellspacing="0">
<tr><td class="label">Package:</td><td class="hd-info">Ext</td></tr>
<tr><td class="label">Defined In:</td><td class="hd-info"><a href="../source/core/DomHelper_wev8.js" target="_blank">DomHelper_wev8.js</a></td></tr>
<tr><td class="label">Class:</td><td class="hd-info">DomHelper</td></tr>
<tr><td class="label">Extends:</td><td class="hd-info">Object</td></tr>
</table>
<div class="description">
Utility class for working with DOM and/or Templates. It transparently supports using HTML fragments or DOM.<br>
This is an example, where an unordered list with 5 children items is appended to an existing element with id 'my-div':<br>
<pre><code>var list = dh.append(<em>'my-div'</em>, {
id: <em>'my-ul'</em>, tag: <em>'ul'</em>, cls: <em>'my-list'</em>, children: [
{tag: <em>'li'</em>, id: <em>'item0'</em>, html: <em>'List Item 0'</em>},
{tag: <em>'li'</em>, id: <em>'item1'</em>, html: <em>'List Item 1'</em>},
{tag: <em>'li'</em>, id: <em>'item2'</em>, html: <em>'List Item 2'</em>},
{tag: <em>'li'</em>, id: <em>'item3'</em>, html: <em>'List Item 3'</em>},
{tag: <em>'li'</em>, id: <em>'item4'</em>, html: <em>'List Item 4'</em>}
]
});</code></pre>
<p>Element creation specification parameters in this class may also be passed as an Array of
specification objects. This can be used to insert multiple sibling nodes into an existing
container very efficiently. For example, to add more list items to the example above:<pre><code>dh.append(<em>'my-ul'</em>, [
{tag: <em>'li'</em>, id: <em>'item5'</em>, html: <em>'List Item 5'</em>},
{tag: <em>'li'</em>, id: <em>'item6'</em>, html: <em>'List Item 6'</em>} ]);</code></pre></p>
<p>Element creation specification parameters may also be strings. If <a ext:cls="useDom" href="output/useDom.html">useDom</a> is false, then the string is used
as innerHTML. If <a ext:cls="useDom" href="output/useDom.html">useDom</a> is true, a string specification results in the creation of a text node.</p>
For more information and examples, see <a href="http://www.jackslocum.com/blog/2006/10/06/domhelper-create-elements-using-dom-html-fragments-or-templates/">the original blog post</a>.<br><br><i>This class is a singleton and cannot be created directly.</i> </div>
<div class="hr"></div>
<a id="Ext.DomHelper-props"></a>
<h2>Public Properties</h2>
<table cellspacing="0" class="member-table">
<tr>
<th class="sig-header" colspan="2">Property</th>
<th class="msource-header">Defined By</th>
</tr>
<tr class="property-row">
<td class="micon"><a class="exi" href="#expand"> </a></td>
<td class="sig">
<a id="Ext.DomHelper-useDom"></a>
<b>useDom</b> : Boolean <div class="mdesc">
True to force the use of DOM instead of html fragments </div>
</td>
<td class="msource">DomHelper</td>
</tr>
</table>
<a id="Ext.DomHelper-methods"></a>
<h2>Public Methods</h2>
<table cellspacing="0" class="member-table">
<tr>
<th class="sig-header" colspan="2">Method</th>
<th class="msource-header">Defined By</th>
</tr>
<tr class="method-row expandable">
<td class="micon"><a class="exi" href="#expand"> </a></td>
<td class="sig">
<a id="Ext.DomHelper-append"></a>
<b>append</b>( <code>Mixed el</code>, <code>Object/String o</code>, <span class="optional" title="Optional">[<code>Boolean returnElement</code>]</span> ) : HTMLElement/Ext.Element <div class="mdesc">
<div class="short">Creates new DOM element(s) and appends them to el.</div>
<div class="long">
Creates new DOM element(s) and appends them to el. <div class="mdetail-params">
<strong>Parameters:</strong>
<ul><li><code>el</code> : Mixed<div class="sub-desc">The context element</div></li><li><code>o</code> : Object/String<div class="sub-desc">The DOM object spec (and children) or raw HTML blob</div></li><li><code>returnElement</code> : Boolean<div class="sub-desc">(optional) true to return a Ext.Element</div></li> </ul>
<strong>Returns:</strong>
<ul>
<li><code>HTMLElement/Ext.Element</code><div class="sub-desc">The new node</div></li>
</ul>
</div>
</div>
</div>
</td>
<td class="msource">DomHelper</td>
</tr>
<tr class="method-row alt expandable">
<td class="micon"><a class="exi" href="#expand"> </a></td>
<td class="sig">
<a id="Ext.DomHelper-applyStyles"></a>
<b>applyStyles</b>( <code>String/HTMLElement el</code>, <code>String/Object/Function styles</code> ) : void <div class="mdesc">
<div class="short">Applies a style specification to an element.</div>
<div class="long">
Applies a style specification to an element. <div class="mdetail-params">
<strong>Parameters:</strong>
<ul><li><code>el</code> : String/HTMLElement<div class="sub-desc">The element to apply styles to</div></li><li><code>styles</code> : String/Object/Function<div class="sub-desc">A style specification string eg "width:100px", or object in the form {width:"100px"}, or
a function which returns such a specification.</div></li> </ul>
<strong>Returns:</strong>
<ul>
<li><code>void</code></li>
</ul>
</div>
</div>
</div>
</td>
<td class="msource">DomHelper</td>
</tr>
<tr class="method-row expandable">
<td class="micon"><a class="exi" href="#expand"> </a></td>
<td class="sig">
<a id="Ext.DomHelper-createTemplate"></a>
<b>createTemplate</b>( <code>Object o</code> ) : Ext.Template <div class="mdesc">
<div class="short">Creates a new Ext.Template from the DOM object spec.</div>
<div class="long">
Creates a new Ext.Template from the DOM object spec. <div class="mdetail-params">
<strong>Parameters:</strong>
<ul><li><code>o</code> : Object<div class="sub-desc">The DOM object spec (and children)</div></li> </ul>
<strong>Returns:</strong>
<ul>
<li><code>Ext.Template</code><div class="sub-desc">The new template</div></li>
</ul>
</div>
</div>
</div>
</td>
<td class="msource">DomHelper</td>
</tr>
<tr class="method-row alt expandable">
<td class="micon"><a class="exi" href="#expand"> </a></td>
<td class="sig">
<a id="Ext.DomHelper-insertAfter"></a>
<b>insertAfter</b>( <code>Mixed el</code>, <code>Object o</code>, <span class="optional" title="Optional">[<code>Boolean returnElement</code>]</span> ) : HTMLElement/Ext.Element <div class="mdesc">
<div class="short">Creates new DOM element(s) and inserts them after el.</div>
<div class="long">
Creates new DOM element(s) and inserts them after el. <div class="mdetail-params">
<strong>Parameters:</strong>
<ul><li><code>el</code> : Mixed<div class="sub-desc">The context element</div></li><li><code>o</code> : Object<div class="sub-desc">The DOM object spec (and children)</div></li><li><code>returnElement</code> : Boolean<div class="sub-desc">(optional) true to return a Ext.Element</div></li> </ul>
<strong>Returns:</strong>
<ul>
<li><code>HTMLElement/Ext.Element</code><div class="sub-desc">The new node</div></li>
</ul>
</div>
</div>
</div>
</td>
<td class="msource">DomHelper</td>
</tr>
<tr class="method-row expandable">
<td class="micon"><a class="exi" href="#expand"> </a></td>
<td class="sig">
<a id="Ext.DomHelper-insertBefore"></a>
<b>insertBefore</b>( <code>Mixed el</code>, <code>Object/String o</code>, <span class="optional" title="Optional">[<code>Boolean returnElement</code>]</span> ) : HTMLElement/Ext.Element <div class="mdesc">
<div class="short">Creates new DOM element(s) and inserts them before el.</div>
<div class="long">
Creates new DOM element(s) and inserts them before el. <div class="mdetail-params">
<strong>Parameters:</strong>
<ul><li><code>el</code> : Mixed<div class="sub-desc">The context element</div></li><li><code>o</code> : Object/String<div class="sub-desc">The DOM object spec (and children) or raw HTML blob</div></li><li><code>returnElement</code> : Boolean<div class="sub-desc">(optional) true to return a Ext.Element</div></li> </ul>
<strong>Returns:</strong>
<ul>
<li><code>HTMLElement/Ext.Element</code><div class="sub-desc">The new node</div></li>
</ul>
</div>
</div>
</div>
</td>
<td class="msource">DomHelper</td>
</tr>
<tr class="method-row alt expandable">
<td class="micon"><a class="exi" href="#expand"> </a></td>
<td class="sig">
<a id="Ext.DomHelper-insertFirst"></a>
<b>insertFirst</b>( <code>Mixed el</code>, <code>Object/String o</code>, <span class="optional" title="Optional">[<code>Boolean returnElement</code>]</span> ) : HTMLElement/Ext.Element <div class="mdesc">
<div class="short">Creates new DOM element(s) and inserts them as the first child of el.</div>
<div class="long">
Creates new DOM element(s) and inserts them as the first child of el. <div class="mdetail-params">
<strong>Parameters:</strong>
<ul><li><code>el</code> : Mixed<div class="sub-desc">The context element</div></li><li><code>o</code> : Object/String<div class="sub-desc">The DOM object spec (and children) or raw HTML blob</div></li><li><code>returnElement</code> : Boolean<div class="sub-desc">(optional) true to return a Ext.Element</div></li> </ul>
<strong>Returns:</strong>
<ul>
<li><code>HTMLElement/Ext.Element</code><div class="sub-desc">The new node</div></li>
</ul>
</div>
</div>
</div>
</td>
<td class="msource">DomHelper</td>
</tr>
<tr class="method-row expandable">
<td class="micon"><a class="exi" href="#expand"> </a></td>
<td class="sig">
<a id="Ext.DomHelper-insertHtml"></a>
<b>insertHtml</b>( <code>String where</code>, <code>HTMLElement el</code>, <code>String html</code> ) : HTMLElement <div class="mdesc">
<div class="short">Inserts an HTML fragment into the DOM.</div>
<div class="long">
Inserts an HTML fragment into the DOM. <div class="mdetail-params">
<strong>Parameters:</strong>
<ul><li><code>where</code> : String<div class="sub-desc">Where to insert the html in relation to el - beforeBegin, afterBegin, beforeEnd, afterEnd.</div></li><li><code>el</code> : HTMLElement<div class="sub-desc">The context element</div></li><li><code>html</code> : String<div class="sub-desc">The HTML fragmenet</div></li> </ul>
<strong>Returns:</strong>
<ul>
<li><code>HTMLElement</code><div class="sub-desc">The new node</div></li>
</ul>
</div>
</div>
</div>
</td>
<td class="msource">DomHelper</td>
</tr>
<tr class="method-row alt expandable">
<td class="micon"><a class="exi" href="#expand"> </a></td>
<td class="sig">
<a id="Ext.DomHelper-markup"></a>
<b>markup</b>( <code>Object o</code> ) : String <div class="mdesc">
<div class="short">Returns the markup for the passed Element(s) config.</div>
<div class="long">
Returns the markup for the passed Element(s) config. <div class="mdetail-params">
<strong>Parameters:</strong>
<ul><li><code>o</code> : Object<div class="sub-desc">The DOM object spec (and children)</div></li> </ul>
<strong>Returns:</strong>
<ul>
<li><code>String</code></li>
</ul>
</div>
</div>
</div>
</td>
<td class="msource">DomHelper</td>
</tr>
<tr class="method-row expandable">
<td class="micon"><a class="exi" href="#expand"> </a></td>
<td class="sig">
<a id="Ext.DomHelper-overwrite"></a>
<b>overwrite</b>( <code>Mixed el</code>, <code>Object/String o</code>, <span class="optional" title="Optional">[<code>Boolean returnElement</code>]</span> ) : HTMLElement/Ext.Element <div class="mdesc">
<div class="short">Creates new DOM element(s) and overwrites the contents of el with them.</div>
<div class="long">
Creates new DOM element(s) and overwrites the contents of el with them. <div class="mdetail-params">
<strong>Parameters:</strong>
<ul><li><code>el</code> : Mixed<div class="sub-desc">The context element</div></li><li><code>o</code> : Object/String<div class="sub-desc">The DOM object spec (and children) or raw HTML blob</div></li><li><code>returnElement</code> : Boolean<div class="sub-desc">(optional) true to return a Ext.Element</div></li> </ul>
<strong>Returns:</strong>
<ul>
<li><code>HTMLElement/Ext.Element</code><div class="sub-desc">The new node</div></li>
</ul>
</div>
</div>
</div>
</td>
<td class="msource">DomHelper</td>
</tr>
</table>
<a id="Ext.DomHelper-events"></a>
<h2>Public Events</h2>
<div class="no-members">This class has no public events.</div>
</div>