Upgrade to ExtJS 4.0.1 - Released 05/18/2011
[extjs.git] / docs / output / Ext.core.DomHelper.js
1 Ext.data.JsonP.Ext_core_DomHelper({
2   "tagname": "class",
3   "name": "Ext.core.DomHelper",
4   "doc": "<p>The DomHelper class provides a layer of abstraction from DOM and transparently supports creating\nelements via DOM or using HTML fragments. It also has the ability to create HTML fragment templates\nfrom your DOM building code.</p>\n\n\n\n\n<p><b><u>DomHelper element specification object</u></b></p>\n\n\n<p>A specification object is used when creating elements. Attributes of this object\nare assumed to be element attributes, except for 4 special attributes:\n<div class=\"mdetail-params\"><ul>\n<li><b><tt>tag</tt></b> : <div class=\"sub-desc\">The tag name of the element</div></li>\n<li><b><tt>children</tt></b> : or <tt>cn</tt><div class=\"sub-desc\">An array of the\nsame kind of element definition objects to be created and appended. These can be nested\nas deep as you want.</div></li>\n<li><b><tt>cls</tt></b> : <div class=\"sub-desc\">The class attribute of the element.\nThis will end up being either the \"class\" attribute on a HTML fragment or className\nfor a DOM node, depending on whether DomHelper is using fragments or DOM.</div></li>\n<li><b><tt>html</tt></b> : <div class=\"sub-desc\">The innerHTML for the element</div></li>\n</ul></div></p>\n\n\n<p><b>NOTE:</b> For other arbitrary attributes, the value will currently <b>not</b> be automatically\nHTML-escaped prior to building the element's HTML string. This means that if your attribute value\ncontains special characters that would not normally be allowed in a double-quoted attribute value,\nyou <b>must</b> manually HTML-encode it beforehand (see <a href=\"#/api/Ext.String-method-htmlEncode\" rel=\"Ext.String-method-htmlEncode\" class=\"docClass\">Ext.String.htmlEncode</a>) or risk\nmalformed HTML being created. This behavior may change in a future release.</p>\n\n\n\n\n<p><b><u>Insertion methods</u></b></p>\n\n\n<p>Commonly used insertion methods:\n<div class=\"mdetail-params\"><ul>\n<li><b><tt><a href=\"#/api/Ext.core.DomHelper-method-append\" rel=\"Ext.core.DomHelper-method-append\" class=\"docClass\">append</a></tt></b> : <div class=\"sub-desc\"></div></li>\n<li><b><tt><a href=\"#/api/Ext.core.DomHelper-method-insertBefore\" rel=\"Ext.core.DomHelper-method-insertBefore\" class=\"docClass\">insertBefore</a></tt></b> : <div class=\"sub-desc\"></div></li>\n<li><b><tt><a href=\"#/api/Ext.core.DomHelper-method-insertAfter\" rel=\"Ext.core.DomHelper-method-insertAfter\" class=\"docClass\">insertAfter</a></tt></b> : <div class=\"sub-desc\"></div></li>\n<li><b><tt><a href=\"#/api/Ext.core.DomHelper-method-overwrite\" rel=\"Ext.core.DomHelper-method-overwrite\" class=\"docClass\">overwrite</a></tt></b> : <div class=\"sub-desc\"></div></li>\n<li><b><tt><a href=\"#/api/Ext.core.DomHelper-method-createTemplate\" rel=\"Ext.core.DomHelper-method-createTemplate\" class=\"docClass\">createTemplate</a></tt></b> : <div class=\"sub-desc\"></div></li>\n<li><b><tt><a href=\"#/api/Ext.core.DomHelper-method-insertHtml\" rel=\"Ext.core.DomHelper-method-insertHtml\" class=\"docClass\">insertHtml</a></tt></b> : <div class=\"sub-desc\"></div></li>\n</ul></div></p>\n\n\n\n\n<p><b><u>Example</u></b></p>\n\n\n<p>This is an example, where an unordered list with 3 children items is appended to an existing\nelement with id <tt>'my-div'</tt>:<br>\n \n<pre><code>var dh = Ext.core.DomHelper; // create shorthand alias\n// specification object\nvar spec = {\n    id: 'my-ul',\n    tag: 'ul',\n    cls: 'my-list',\n    // append children after creating\n    children: [     // may also specify 'cn' instead of 'children'\n        {tag: 'li', id: 'item0', html: 'List Item 0'},\n        {tag: 'li', id: 'item1', html: 'List Item 1'},\n        {tag: 'li', id: 'item2', html: 'List Item 2'}\n    ]\n};\nvar list = dh.append(\n    'my-div', // the context element 'my-div' can either be the id or the actual node\n    spec      // the specification object\n);\n </code></pre></p>\n\n\n<p>Element creation specification parameters in this class may also be passed as an Array of\nspecification objects. This can be used to insert multiple sibling nodes into an existing\ncontainer very efficiently. For example, to add more list items to the example above:\n<pre><code>dh.append('my-ul', [\n    {tag: 'li', id: 'item3', html: 'List Item 3'},\n    {tag: 'li', id: 'item4', html: 'List Item 4'}\n]);\n</code></pre></p>\n\n\n\n\n<p><b><u>Templating</u></b></p>\n\n\n<p>The real power is in the built-in templating. Instead of creating or appending any elements,\n<tt><a href=\"#/api/Ext.core.DomHelper-method-createTemplate\" rel=\"Ext.core.DomHelper-method-createTemplate\" class=\"docClass\">createTemplate</a></tt> returns a Template object which can be used over and over to\ninsert new elements. Revisiting the example above, we could utilize templating this time:\n<pre><code>// create the node\nvar list = dh.append('my-div', {tag: 'ul', cls: 'my-list'});\n// get template\nvar tpl = dh.createTemplate({tag: 'li', id: 'item{0}', html: 'List Item {0}'});\n\nfor(var i = 0; i < 5, i++){\n    tpl.append(list, [i]); // use template to append to the actual node\n}\n</code></pre></p>\n<p>An example using a template:\n<pre><code>var html = '<a id=\"{0}\" href=\"{1}\" class=\"nav\">{2}</a>';\n\nvar tpl = new Ext.core.DomHelper.createTemplate(html);\ntpl.append('blog-roll', ['link1', 'http://www.edspencer.net/', \"Ed&#39;s Site\"]);\ntpl.append('blog-roll', ['link2', 'http://www.dustindiaz.com/', \"Dustin&#39;s Site\"]);\n</code></pre></p>\n\n<p>The same example using named parameters:\n<pre><code>var html = '<a id=\"{id}\" href=\"{url}\" class=\"nav\">{text}</a>';\n\nvar tpl = new Ext.core.DomHelper.createTemplate(html);\ntpl.append('blog-roll', {\n    id: 'link1',\n    url: 'http://www.edspencer.net/',\n    text: \"Ed&#39;s Site\"\n});\ntpl.append('blog-roll', {\n    id: 'link2',\n    url: 'http://www.dustindiaz.com/',\n    text: \"Dustin&#39;s Site\"\n});\n</code></pre></p>\n\n<p><b><u>Compiling Templates</u></b></p>\n<p>Templates are applied using regular expressions. The performance is great, but if\nyou are adding a bunch of DOM elements using the same template, you can increase\nperformance even further by <a href=\"#/api/Ext.Template--compile\" rel=\"Ext.Template--compile\" class=\"docClass\">&quot;compiling&quot;</a> the template.\nThe way \"<a href=\"#/api/Ext.Template--compile\" rel=\"Ext.Template--compile\" class=\"docClass\">compile()</a>\" works is the template is parsed and\nbroken up at the different variable points and a dynamic function is created and eval'ed.\nThe generated function performs string concatenation of these parts and the passed\nvariables instead of using regular expressions.\n<pre><code>var html = '<a id=\"{id}\" href=\"{url}\" class=\"nav\">{text}</a>';\n\nvar tpl = new Ext.core.DomHelper.createTemplate(html);\ntpl.compile();\n\n//... use template like normal\n</code></pre></p>\n\n<p><b><u>Performance Boost</u></b></p>\n<p>DomHelper will transparently create HTML fragments when it can. Using HTML fragments instead\nof DOM can significantly boost performance.</p>\n<p>Element creation specification parameters may also be strings. If <a href=\"#/api/Ext.core.DomHelper-property-useDom\" rel=\"Ext.core.DomHelper-property-useDom\" class=\"docClass\">useDom</a> is <tt>false</tt>,\nthen the string is used as innerHTML. If <a href=\"#/api/Ext.core.DomHelper-property-useDom\" rel=\"Ext.core.DomHelper-property-useDom\" class=\"docClass\">useDom</a> is <tt>true</tt>, a string specification\nresults in the creation of a text node. Usage:</p>\n<pre><code>Ext.core.DomHelper.useDom = true; // force it to use DOM; reduces performance\n</code></pre>\n\n",
5   "extends": null,
6   "mixins": [
7
8   ],
9   "alternateClassNames": [
10
11   ],
12   "xtype": null,
13   "author": null,
14   "docauthor": null,
15   "singleton": true,
16   "private": false,
17   "cfg": [
18
19   ],
20   "method": [
21     {
22       "tagname": "method",
23       "name": "append",
24       "member": "Ext.core.DomHelper",
25       "doc": "<p>Creates new DOM element(s) and appends them to el.</p>\n",
26       "params": [
27         {
28           "type": "Mixed",
29           "name": "el",
30           "doc": "<p>The context element</p>\n",
31           "optional": false
32         },
33         {
34           "type": "Object/String",
35           "name": "o",
36           "doc": "<p>The DOM object spec (and children) or raw HTML blob</p>\n",
37           "optional": false
38         },
39         {
40           "type": "Boolean",
41           "name": "returnElement",
42           "doc": "<p>(optional) true to return a Ext.core.Element</p>\n",
43           "optional": true
44         }
45       ],
46       "return": {
47         "type": "HTMLElement/Ext.core.Element",
48         "doc": "<p>The new node</p>\n"
49       },
50       "private": false,
51       "static": false,
52       "filename": "/Users/nick/Projects/sencha/SDK/platform/core/src/dom/DomHelper.js",
53       "linenr": 492,
54       "html_filename": "DomHelper.html",
55       "href": "DomHelper.html#Ext-core-DomHelper-method-append",
56       "shortDoc": "<p>Creates new DOM element(s) and appends them to el.</p>\n"
57     },
58     {
59       "tagname": "method",
60       "name": "applyStyles",
61       "member": "Ext.core.DomHelper",
62       "doc": "<p>Applies a style specification to an element.</p>\n",
63       "params": [
64         {
65           "type": "String/HTMLElement",
66           "name": "el",
67           "doc": "<p>The element to apply styles to</p>\n",
68           "optional": false
69         },
70         {
71           "type": "String/Object/Function",
72           "name": "styles",
73           "doc": "<p>A style specification string e.g. 'width:100px', or object in the form {width:'100px'}, or\na function which returns such a specification.</p>\n",
74           "optional": false
75         }
76       ],
77       "return": {
78         "type": "void",
79         "doc": "\n"
80       },
81       "private": false,
82       "static": false,
83       "filename": "/Users/nick/Projects/sencha/SDK/platform/core/src/dom/DomHelper.js",
84       "linenr": 354,
85       "html_filename": "DomHelper.html",
86       "href": "DomHelper.html#Ext-core-DomHelper-method-applyStyles",
87       "shortDoc": "<p>Applies a style specification to an element.</p>\n"
88     },
89     {
90       "tagname": "method",
91       "name": "createDom",
92       "member": "Ext.core.DomHelper",
93       "doc": "<p>Creates new DOM element(s) without inserting them to the document.</p>\n",
94       "params": [
95         {
96           "type": "Object/String",
97           "name": "o",
98           "doc": "<p>The DOM object spec (and children) or raw HTML blob</p>\n",
99           "optional": false
100         }
101       ],
102       "return": {
103         "type": "HTMLElement",
104         "doc": "<p>The new uninserted node</p>\n"
105       },
106       "private": false,
107       "static": false,
108       "filename": "/Users/nick/Projects/sencha/SDK/platform/core/src/dom/DomHelper.js",
109       "linenr": 518,
110       "html_filename": "DomHelper.html",
111       "href": "DomHelper.html#Ext-core-DomHelper-method-createDom",
112       "shortDoc": "<p>Creates new DOM element(s) without inserting them to the document.</p>\n"
113     },
114     {
115       "tagname": "method",
116       "name": "createTemplate",
117       "member": "Ext.core.DomHelper",
118       "doc": "<p>Creates a new <a href=\"#/api/Ext.Template\" rel=\"Ext.Template\" class=\"docClass\">Ext.Template</a> from the DOM object spec.</p>\n",
119       "params": [
120         {
121           "type": "Object",
122           "name": "o",
123           "doc": "<p>The DOM object spec (and children)</p>\n",
124           "optional": false
125         }
126       ],
127       "return": {
128         "type": "Ext.Template",
129         "doc": "<p>The new template</p>\n"
130       },
131       "private": false,
132       "static": false,
133       "filename": "/Users/nick/Projects/sencha/SDK/platform/core/src/dom/DomHelper.js",
134       "linenr": 529,
135       "html_filename": "DomHelper.html",
136       "href": "DomHelper.html#Ext-core-DomHelper-method-createTemplate",
137       "shortDoc": "<p>Creates a new <a href=\"#/api/Ext.Template\" rel=\"Ext.Template\" class=\"docClass\">Ext.Template</a> from the DOM object spec.</p>\n"
138     },
139     {
140       "tagname": "method",
141       "name": "insertAfter",
142       "member": "Ext.core.DomHelper",
143       "doc": "<p>Creates new DOM element(s) and inserts them after el.</p>\n",
144       "params": [
145         {
146           "type": "Mixed",
147           "name": "el",
148           "doc": "<p>The context element</p>\n",
149           "optional": false
150         },
151         {
152           "type": "Object",
153           "name": "o",
154           "doc": "<p>The DOM object spec (and children)</p>\n",
155           "optional": false
156         },
157         {
158           "type": "Boolean",
159           "name": "returnElement",
160           "doc": "<p>(optional) true to return a Ext.core.Element</p>\n",
161           "optional": true
162         }
163       ],
164       "return": {
165         "type": "HTMLElement/Ext.core.Element",
166         "doc": "<p>The new node</p>\n"
167       },
168       "private": false,
169       "static": false,
170       "filename": "/Users/nick/Projects/sencha/SDK/platform/core/src/dom/DomHelper.js",
171       "linenr": 470,
172       "html_filename": "DomHelper.html",
173       "href": "DomHelper.html#Ext-core-DomHelper-method-insertAfter",
174       "shortDoc": "<p>Creates new DOM element(s) and inserts them after el.</p>\n"
175     },
176     {
177       "tagname": "method",
178       "name": "insertBefore",
179       "member": "Ext.core.DomHelper",
180       "doc": "<p>Creates new DOM element(s) and inserts them before el.</p>\n",
181       "params": [
182         {
183           "type": "Mixed",
184           "name": "el",
185           "doc": "<p>The context element</p>\n",
186           "optional": false
187         },
188         {
189           "type": "Object/String",
190           "name": "o",
191           "doc": "<p>The DOM object spec (and children) or raw HTML blob</p>\n",
192           "optional": false
193         },
194         {
195           "type": "Boolean",
196           "name": "returnElement",
197           "doc": "<p>(optional) true to return a Ext.core.Element</p>\n",
198           "optional": true
199         }
200       ],
201       "return": {
202         "type": "HTMLElement/Ext.core.Element",
203         "doc": "<p>The new node</p>\n"
204       },
205       "private": false,
206       "static": false,
207       "filename": "/Users/nick/Projects/sencha/SDK/platform/core/src/dom/DomHelper.js",
208       "linenr": 459,
209       "html_filename": "DomHelper.html",
210       "href": "DomHelper.html#Ext-core-DomHelper-method-insertBefore",
211       "shortDoc": "<p>Creates new DOM element(s) and inserts them before el.</p>\n"
212     },
213     {
214       "tagname": "method",
215       "name": "insertFirst",
216       "member": "Ext.core.DomHelper",
217       "doc": "<p>Creates new DOM element(s) and inserts them as the first child of el.</p>\n",
218       "params": [
219         {
220           "type": "Mixed",
221           "name": "el",
222           "doc": "<p>The context element</p>\n",
223           "optional": false
224         },
225         {
226           "type": "Object/String",
227           "name": "o",
228           "doc": "<p>The DOM object spec (and children) or raw HTML blob</p>\n",
229           "optional": false
230         },
231         {
232           "type": "Boolean",
233           "name": "returnElement",
234           "doc": "<p>(optional) true to return a Ext.core.Element</p>\n",
235           "optional": true
236         }
237       ],
238       "return": {
239         "type": "HTMLElement/Ext.core.Element",
240         "doc": "<p>The new node</p>\n"
241       },
242       "private": false,
243       "static": false,
244       "filename": "/Users/nick/Projects/sencha/SDK/platform/core/src/dom/DomHelper.js",
245       "linenr": 481,
246       "html_filename": "DomHelper.html",
247       "href": "DomHelper.html#Ext-core-DomHelper-method-insertFirst",
248       "shortDoc": "<p>Creates new DOM element(s) and inserts them as the first child of el.</p>\n"
249     },
250     {
251       "tagname": "method",
252       "name": "insertHtml",
253       "member": "Ext.core.DomHelper",
254       "doc": "<p>Inserts an HTML fragment into the DOM.</p>\n",
255       "params": [
256         {
257           "type": "String",
258           "name": "where",
259           "doc": "<p>Where to insert the html in relation to el - beforeBegin, afterBegin, beforeEnd, afterEnd.</p>\n",
260           "optional": false
261         },
262         {
263           "type": "HTMLElement/TextNode",
264           "name": "el",
265           "doc": "<p>The context element</p>\n",
266           "optional": false
267         },
268         {
269           "type": "String",
270           "name": "html",
271           "doc": "<p>The HTML fragment</p>\n",
272           "optional": false
273         }
274       ],
275       "return": {
276         "type": "HTMLElement",
277         "doc": "<p>The new node</p>\n"
278       },
279       "private": false,
280       "static": false,
281       "filename": "/Users/nick/Projects/sencha/SDK/platform/core/src/dom/DomHelper.js",
282       "linenr": 375,
283       "html_filename": "DomHelper.html",
284       "href": "DomHelper.html#Ext-core-DomHelper-method-insertHtml",
285       "shortDoc": "<p>Inserts an HTML fragment into the DOM.</p>\n"
286     },
287     {
288       "tagname": "method",
289       "name": "markup",
290       "member": "Ext.core.DomHelper",
291       "doc": "<p>Returns the markup for the passed Element(s) config.</p>\n",
292       "params": [
293         {
294           "type": "Object",
295           "name": "o",
296           "doc": "<p>The DOM object spec (and children)</p>\n",
297           "optional": false
298         }
299       ],
300       "return": {
301         "type": "String",
302         "doc": "\n"
303       },
304       "private": false,
305       "static": false,
306       "filename": "/Users/nick/Projects/sencha/SDK/platform/core/src/dom/DomHelper.js",
307       "linenr": 345,
308       "html_filename": "DomHelper.html",
309       "href": "DomHelper.html#Ext-core-DomHelper-method-markup",
310       "shortDoc": "<p>Returns the markup for the passed Element(s) config.</p>\n"
311     },
312     {
313       "tagname": "method",
314       "name": "overwrite",
315       "member": "Ext.core.DomHelper",
316       "doc": "<p>Creates new DOM element(s) and overwrites the contents of el with them.</p>\n",
317       "params": [
318         {
319           "type": "Mixed",
320           "name": "el",
321           "doc": "<p>The context element</p>\n",
322           "optional": false
323         },
324         {
325           "type": "Object/String",
326           "name": "o",
327           "doc": "<p>The DOM object spec (and children) or raw HTML blob</p>\n",
328           "optional": false
329         },
330         {
331           "type": "Boolean",
332           "name": "returnElement",
333           "doc": "<p>(optional) true to return a Ext.core.Element</p>\n",
334           "optional": true
335         }
336       ],
337       "return": {
338         "type": "HTMLElement/Ext.core.Element",
339         "doc": "<p>The new node</p>\n"
340       },
341       "private": false,
342       "static": false,
343       "filename": "/Users/nick/Projects/sencha/SDK/platform/core/src/dom/DomHelper.js",
344       "linenr": 503,
345       "html_filename": "DomHelper.html",
346       "href": "DomHelper.html#Ext-core-DomHelper-method-overwrite",
347       "shortDoc": "<p>Creates new DOM element(s) and overwrites the contents of el with them.</p>\n"
348     }
349   ],
350   "property": [
351     {
352       "tagname": "property",
353       "name": "useDom",
354       "member": "Ext.core.DomHelper",
355       "type": "Boolean",
356       "doc": "<p>True to force the use of DOM instead of html fragments</p>\n",
357       "private": false,
358       "static": false,
359       "filename": "/Users/nick/Projects/sencha/SDK/platform/core/src/dom/DomHelper.js",
360       "linenr": 526,
361       "html_filename": "DomHelper.html",
362       "href": "DomHelper.html#Ext-core-DomHelper-property-useDom"
363     }
364   ],
365   "event": [
366
367   ],
368   "filename": "/Users/nick/Projects/sencha/SDK/platform/core/src/dom/DomHelper.js",
369   "linenr": 1,
370   "html_filename": "DomHelper.html",
371   "href": "DomHelper.html#Ext-core-DomHelper",
372   "cssVar": [
373
374   ],
375   "cssMixin": [
376
377   ],
378   "component": false,
379   "superclasses": [
380
381   ],
382   "subclasses": [
383
384   ],
385   "mixedInto": [
386
387   ],
388   "allMixins": [
389
390   ]
391 });