X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/f5240829880f87e0cf581c6a296e436fdef0ef80..3789b528d8dd8aad4558e38e22d775bcab1cbd36:/docs/source/DomHelper.html?ds=sidebyside diff --git a/docs/source/DomHelper.html b/docs/source/DomHelper.html index 9131e523..212b9913 100644 --- a/docs/source/DomHelper.html +++ b/docs/source/DomHelper.html @@ -1,53 +1,61 @@ +
- +/*! - * Ext JS Library 3.3.0 - * Copyright(c) 2006-2010 Ext JS, Inc. - * licensing@extjs.com - * http://www.extjs.com/license - */ -/** - * @class Ext.DomHelper - *The DomHelper class provides a layer of abstraction from DOM and transparently supports creating +
+/** + * @class Ext.core.DomHelper + * <p>The DomHelper class provides a layer of abstraction from DOM and transparently supports creating * elements via DOM or using HTML fragments. It also has the ability to create HTML fragment templates - * from your DOM building code. + * from your DOM building code.</p> * - *DomHelper element specification object
- *A specification object is used when creating elements. Attributes of this object + * <p><b><u>DomHelper element specification object</u></b></p> + * <p>A specification object is used when creating elements. Attributes of this object * are assumed to be element attributes, except for 4 special attributes: - *
+ * as deep as you want.</div></li> + * <li><b><tt>cls</tt></b> : <div class="sub-desc">The class attribute of the element. + * This will end up being either the "class" attribute on a HTML fragment or className + * for a DOM node, depending on whether DomHelper is using fragments or DOM.</div></li> + * <li><b><tt>html</tt></b> : <div class="sub-desc">The innerHTML for the element</div></li> + * </ul></div></p> + * <p><b>NOTE:</b> For other arbitrary attributes, the value will currently <b>not</b> be automatically + * HTML-escaped prior to building the element's HTML string. This means that if your attribute value + * contains special characters that would not normally be allowed in a double-quoted attribute value, + * you <b>must</b> manually HTML-encode it beforehand (see {@link Ext.String#htmlEncode}) or risk + * malformed HTML being created. This behavior may change in a future release.</p> * - *- *
- tag :
- *The tag name of the element- children : or cn
- *An array of the + * <div class="mdetail-params"><ul> + * <li><b><tt>tag</tt></b> : <div class="sub-desc">The tag name of the element</div></li> + * <li><b><tt>children</tt></b> : or <tt>cn</tt><div class="sub-desc">An array of the * same kind of element definition objects to be created and appended. These can be nested - * as deep as you want.- cls :
- *The class attribute of the element. - * This will end up being either the "class" attribute on a HTML fragment or className - * for a DOM node, depending on whether DomHelper is using fragments or DOM.- html :
- *The innerHTML for the elementInsertion methods
- *Commonly used insertion methods: - *
+ * <p><b><u>Insertion methods</u></b></p> + * <p>Commonly used insertion methods: + * <div class="mdetail-params"><ul> + * <li><b><tt>{@link #append}</tt></b> : <div class="sub-desc"></div></li> + * <li><b><tt>{@link #insertBefore}</tt></b> : <div class="sub-desc"></div></li> + * <li><b><tt>{@link #insertAfter}</tt></b> : <div class="sub-desc"></div></li> + * <li><b><tt>{@link #overwrite}</tt></b> : <div class="sub-desc"></div></li> + * <li><b><tt>{@link #createTemplate}</tt></b> : <div class="sub-desc"></div></li> + * <li><b><tt>{@link #insertHtml}</tt></b> : <div class="sub-desc"></div></li> + * </ul></div></p> * - *- *
- {@link #append} :
- *- {@link #insertBefore} :
- *- {@link #insertAfter} :
- *- {@link #overwrite} :
- *- {@link #createTemplate} :
- *- {@link #insertHtml} :
- *Example
- *This is an example, where an unordered list with 3 children items is appended to an existing - * element with id 'my-div':
-- *-var dh = Ext.DomHelper; // create shorthand alias + * <p><b><u>Example</u></b></p> + * <p>This is an example, where an unordered list with 3 children items is appended to an existing + * element with id <tt>'my-div'</tt>:<br> + <pre><code> +var dh = Ext.core.DomHelper; // create shorthand alias // specification object var spec = { id: 'my-ul', @@ -64,89 +72,89 @@ var list = dh.append( 'my-div', // the context element 'my-div' can either be the id or the actual node spec // the specification object ); -
Element creation specification parameters in this class may also be passed as an Array of + </code></pre></p> + * <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:
+ * </code></pre></p> * - *+ * container very efficiently. For example, to add more list items to the example above:<pre><code> dh.append('my-ul', [ {tag: 'li', id: 'item3', html: 'List Item 3'}, {tag: 'li', id: 'item4', html: 'List Item 4'} ]); - *
Templating
- *The real power is in the built-in templating. Instead of creating or appending any elements, - * {@link #createTemplate} returns a Template object which can be used over and over to + * <p><b><u>Templating</u></b></p> + * <p>The real power is in the built-in templating. Instead of creating or appending any elements, + * <tt>{@link #createTemplate}</tt> returns a Template object which can be used over and over to * insert new elements. Revisiting the example above, we could utilize templating this time: - *
- *+ * <pre><code> // create the node var list = dh.append('my-div', {tag: 'ul', cls: 'my-list'}); // get template var tpl = dh.createTemplate({tag: 'li', id: 'item{0}', html: 'List Item {0}'}); -for(var i = 0; i < 5, i++){ +for(var i = 0; i < 5, i++){ tpl.append(list, [i]); // use template to append to the actual node } - *
An example using a template:
+var tpl = new Ext.core.DomHelper.createTemplate(html); +tpl.append('blog-roll', ['link1', 'http://www.edspencer.net/', "Ed's Site"]); +tpl.append('blog-roll', ['link2', 'http://www.dustindiaz.com/', "Dustin's Site"]); + * </code></pre></p> * - *-var html = '{2}'; + * </code></pre></p> + * <p>An example using a template:<pre><code> +var html = '<a id="{0}" href="{1}" class="nav">{2}</a>'; -var tpl = new Ext.DomHelper.createTemplate(html); -tpl.append('blog-roll', ['link1', 'http://www.jackslocum.com/', "Jack's Site"]); -tpl.append('blog-roll', ['link2', 'http://www.dustindiaz.com/', "Dustin's Site"]); - *
The same example using named parameters:
+ * </code></pre></p> * - *-var html = '{text}'; + * <p>The same example using named parameters:<pre><code> +var html = '<a id="{id}" href="{url}" class="nav">{text}</a>'; -var tpl = new Ext.DomHelper.createTemplate(html); +var tpl = new Ext.core.DomHelper.createTemplate(html); tpl.append('blog-roll', { id: 'link1', - url: 'http://www.jackslocum.com/', - text: "Jack's Site" + url: 'http://www.edspencer.net/', + text: "Ed's Site" }); tpl.append('blog-roll', { id: 'link2', url: 'http://www.dustindiaz.com/', - text: "Dustin's Site" + text: "Dustin's Site" }); - *
Compiling Templates
- *Templates are applied using regular expressions. The performance is great, but if + * <p><b><u>Compiling Templates</u></b></p> + * <p>Templates are applied using regular expressions. The performance is great, but if * you are adding a bunch of DOM elements using the same template, you can increase - * performance even further by {@link Ext.Template#compile "compiling"} the template. - * The way "{@link Ext.Template#compile compile()}" works is the template is parsed and + * performance even further by {@link Ext.Template#compile "compiling"} the template. + * The way "{@link Ext.Template#compile compile()}" works is the template is parsed and * broken up at the different variable points and a dynamic function is created and eval'ed. * The generated function performs string concatenation of these parts and the passed * variables instead of using regular expressions. - *
+ * </code></pre></p> * - *-var html = '{text}'; + * <pre><code> +var html = '<a id="{id}" href="{url}" class="nav">{text}</a>'; -var tpl = new Ext.DomHelper.createTemplate(html); +var tpl = new Ext.core.DomHelper.createTemplate(html); tpl.compile(); //... use template like normal - *
Performance Boost
- *DomHelper will transparently create HTML fragments when it can. Using HTML fragments instead - * of DOM can significantly boost performance.
- *Element creation specification parameters may also be strings. If {@link #useDom} is false, - * then the string is used as innerHTML. If {@link #useDom} is true, a string specification - * results in the creation of a text node. Usage:
- *+ * <p><b><u>Performance Boost</u></b></p> + * <p>DomHelper will transparently create HTML fragments when it can. Using HTML fragments instead + * of DOM can significantly boost performance.</p> + * <p>Element creation specification parameters may also be strings. If {@link #useDom} is <tt>false</tt>, + * then the string is used as innerHTML. If {@link #useDom} is <tt>true</tt>, a string specification + * results in the creation of a text node. Usage:</p> + * <pre><code> +Ext.core.DomHelper.useDom = true; // force it to use DOM; reduces performance + * </code></pre> * @singleton */ -Ext.DomHelper = function(){ +Ext.ns('Ext.core'); +Ext.core.DomHelper = function(){ var tempTableEl = null, emptyTags = /^(?:br|frame|hr|img|input|link|meta|range|spacer|wbr|area|param|col)$/i, tableRe = /^table|tbody|tr|td$/i, confRe = /tag|children|cn|html$/i, tableElRe = /td|tr|tbody/i, - cssRe = /([a-z0-9-]+)\s*:\s*([^;\s]+(?:\s*[^;\s]+)*);?/gi, endRe = /end/i, pub, // kill repeat to save bytes @@ -154,18 +162,75 @@ Ext.DomHelper = function(){ afterend = 'afterend', beforebegin = 'beforebegin', beforeend = 'beforeend', - ts = '-Ext.DomHelper.useDom = true; // force it to use DOM; reduces performance - *