+++ /dev/null
-/*!
- * Ext JS Library 3.0.3
- * Copyright(c) 2006-2009 Ext JS, LLC
- * licensing@extjs.com
- * http://www.extjs.com/license
- */
-/**\r
- * @class Ext.DomHelper\r
- * <p>The DomHelper class provides a layer of abstraction from DOM and transparently supports creating\r
- * elements via DOM or using HTML fragments. It also has the ability to create HTML fragment templates\r
- * from your DOM building code.</p>\r
- *\r
- * <p><b><u>DomHelper element specification object</u></b></p>\r
- * <p>A specification object is used when creating elements. Attributes of this object\r
- * are assumed to be element attributes, except for 4 special attributes:\r
- * <div class="mdetail-params"><ul>\r
- * <li><b><tt>tag</tt></b> : <div class="sub-desc">The tag name of the element</div></li>\r
- * <li><b><tt>children</tt></b> : or <tt>cn</tt><div class="sub-desc">An array of the\r
- * same kind of element definition objects to be created and appended. These can be nested\r
- * as deep as you want.</div></li>\r
- * <li><b><tt>cls</tt></b> : <div class="sub-desc">The class attribute of the element.\r
- * This will end up being either the "class" attribute on a HTML fragment or className\r
- * for a DOM node, depending on whether DomHelper is using fragments or DOM.</div></li>\r
- * <li><b><tt>html</tt></b> : <div class="sub-desc">The innerHTML for the element</div></li>\r
- * </ul></div></p>\r
- *\r
- * <p><b><u>Insertion methods</u></b></p>\r
- * <p>Commonly used insertion methods:\r
- * <div class="mdetail-params"><ul>\r
- * <li><b><tt>{@link #append}</tt></b> : <div class="sub-desc"></div></li>\r
- * <li><b><tt>{@link #insertBefore}</tt></b> : <div class="sub-desc"></div></li>\r
- * <li><b><tt>{@link #insertAfter}</tt></b> : <div class="sub-desc"></div></li>\r
- * <li><b><tt>{@link #overwrite}</tt></b> : <div class="sub-desc"></div></li>\r
- * <li><b><tt>{@link #createTemplate}</tt></b> : <div class="sub-desc"></div></li>\r
- * <li><b><tt>{@link #insertHtml}</tt></b> : <div class="sub-desc"></div></li>\r
- * </ul></div></p>\r
- *\r
- * <p><b><u>Example</u></b></p>\r
- * <p>This is an example, where an unordered list with 3 children items is appended to an existing\r
- * element with id <tt>'my-div'</tt>:<br>\r
- <pre><code>\r
-var dh = Ext.DomHelper; // create shorthand alias\r
-// specification object\r
-var spec = {\r
- id: 'my-ul',\r
- tag: 'ul',\r
- cls: 'my-list',\r
- // append children after creating\r
- children: [ // may also specify 'cn' instead of 'children'\r
- {tag: 'li', id: 'item0', html: 'List Item 0'},\r
- {tag: 'li', id: 'item1', html: 'List Item 1'},\r
- {tag: 'li', id: 'item2', html: 'List Item 2'}\r
- ]\r
-};\r
-var list = dh.append(\r
- 'my-div', // the context element 'my-div' can either be the id or the actual node\r
- spec // the specification object\r
-);\r
- </code></pre></p>\r
- * <p>Element creation specification parameters in this class may also be passed as an Array of\r
- * specification objects. This can be used to insert multiple sibling nodes into an existing\r
- * container very efficiently. For example, to add more list items to the example above:<pre><code>\r
-dh.append('my-ul', [\r
- {tag: 'li', id: 'item3', html: 'List Item 3'},\r
- {tag: 'li', id: 'item4', html: 'List Item 4'}\r
-]);\r
- * </code></pre></p>\r
- *\r
- * <p><b><u>Templating</u></b></p>\r
- * <p>The real power is in the built-in templating. Instead of creating or appending any elements,\r
- * <tt>{@link #createTemplate}</tt> returns a Template object which can be used over and over to\r
- * insert new elements. Revisiting the example above, we could utilize templating this time:\r
- * <pre><code>\r
-// create the node\r
-var list = dh.append('my-div', {tag: 'ul', cls: 'my-list'});\r
-// get template\r
-var tpl = dh.createTemplate({tag: 'li', id: 'item{0}', html: 'List Item {0}'});\r
-\r
-for(var i = 0; i < 5, i++){\r
- tpl.append(list, [i]); // use template to append to the actual node\r
-}\r
- * </code></pre></p>\r
- * <p>An example using a template:<pre><code>\r
-var html = '<a id="{0}" href="{1}" class="nav">{2}</a>';\r
-\r
-var tpl = new Ext.DomHelper.createTemplate(html);\r
-tpl.append('blog-roll', ['link1', 'http://www.jackslocum.com/', "Jack's Site"]);\r
-tpl.append('blog-roll', ['link2', 'http://www.dustindiaz.com/', "Dustin's Site"]);\r
- * </code></pre></p>\r
- *\r
- * <p>The same example using named parameters:<pre><code>\r
-var html = '<a id="{id}" href="{url}" class="nav">{text}</a>';\r
-\r
-var tpl = new Ext.DomHelper.createTemplate(html);\r
-tpl.append('blog-roll', {\r
- id: 'link1',\r
- url: 'http://www.jackslocum.com/',\r
- text: "Jack's Site"\r
-});\r
-tpl.append('blog-roll', {\r
- id: 'link2',\r
- url: 'http://www.dustindiaz.com/',\r
- text: "Dustin's Site"\r
-});\r
- * </code></pre></p>\r
- *\r
- * <p><b><u>Compiling Templates</u></b></p>\r
- * <p>Templates are applied using regular expressions. The performance is great, but if\r
- * you are adding a bunch of DOM elements using the same template, you can increase\r
- * performance even further by {@link Ext.Template#compile "compiling"} the template.\r
- * The way "{@link Ext.Template#compile compile()}" works is the template is parsed and\r
- * broken up at the different variable points and a dynamic function is created and eval'ed.\r
- * The generated function performs string concatenation of these parts and the passed\r
- * variables instead of using regular expressions.\r
- * <pre><code>\r
-var html = '<a id="{id}" href="{url}" class="nav">{text}</a>';\r
-\r
-var tpl = new Ext.DomHelper.createTemplate(html);\r
-tpl.compile();\r
-\r
-//... use template like normal\r
- * </code></pre></p>\r
- *\r
- * <p><b><u>Performance Boost</u></b></p>\r
- * <p>DomHelper will transparently create HTML fragments when it can. Using HTML fragments instead\r
- * of DOM can significantly boost performance.</p>\r
- * <p>Element creation specification parameters may also be strings. If {@link #useDom} is <tt>false</tt>,\r
- * then the string is used as innerHTML. If {@link #useDom} is <tt>true</tt>, a string specification\r
- * results in the creation of a text node. Usage:</p>\r
- * <pre><code>\r
-Ext.DomHelper.useDom = true; // force it to use DOM; reduces performance\r
- * </code></pre>\r
- * @singleton\r
- */\r
-Ext.DomHelper = function(){\r
- var tempTableEl = null,\r
- emptyTags = /^(?:br|frame|hr|img|input|link|meta|range|spacer|wbr|area|param|col)$/i,\r
- tableRe = /^table|tbody|tr|td$/i,\r
- pub,\r
- // kill repeat to save bytes\r
- afterbegin = 'afterbegin',\r
- afterend = 'afterend',\r
- beforebegin = 'beforebegin',\r
- beforeend = 'beforeend',\r
- ts = '<table>',\r
- te = '</table>',\r
- tbs = ts+'<tbody>',\r
- tbe = '</tbody>'+te,\r
- trs = tbs + '<tr>',\r
- tre = '</tr>'+tbe;\r
-\r
- // private\r
- function doInsert(el, o, returnElement, pos, sibling, append){\r
- var newNode = pub.insertHtml(pos, Ext.getDom(el), createHtml(o));\r
- return returnElement ? Ext.get(newNode, true) : newNode;\r
- }\r
-\r
- // build as innerHTML where available\r
- function createHtml(o){\r
- var b = '',\r
- attr,\r
- val,\r
- key,\r
- keyVal,\r
- cn;\r
-\r
- if(Ext.isString(o)){\r
- b = o;\r
- } else if (Ext.isArray(o)) {\r
- Ext.each(o, function(v) {\r
- b += createHtml(v);\r
- });\r
- } else {\r
- b += '<' + (o.tag = o.tag || 'div');\r
- Ext.iterate(o, function(attr, val){\r
- if(!/tag|children|cn|html$/i.test(attr)){\r
- if (Ext.isObject(val)) {\r
- b += ' ' + attr + '="';\r
- Ext.iterate(val, function(key, keyVal){\r
- b += key + ':' + keyVal + ';';\r
- });\r
- b += '"';\r
- }else{\r
- b += ' ' + ({cls : 'class', htmlFor : 'for'}[attr] || attr) + '="' + val + '"';\r
- }\r
- }\r
- });\r
- // Now either just close the tag or try to add children and close the tag.\r
- if (emptyTags.test(o.tag)) {\r
- b += '/>';\r
- } else {\r
- b += '>';\r
- if ((cn = o.children || o.cn)) {\r
- b += createHtml(cn);\r
- } else if(o.html){\r
- b += o.html;\r
- }\r
- b += '</' + o.tag + '>';\r
- }\r
- }\r
- return b;\r
- }\r
-\r
- function ieTable(depth, s, h, e){\r
- tempTableEl.innerHTML = [s, h, e].join('');\r
- var i = -1,\r
- el = tempTableEl,\r
- ns;\r
- while(++i < depth){\r
- el = el.firstChild;\r
- }\r
-// If the result is multiple siblings, then encapsulate them into one fragment.\r
- if(ns = el.nextSibling){\r
- var df = document.createDocumentFragment();\r
- while(el){\r
- ns = el.nextSibling;\r
- df.appendChild(el);\r
- el = ns;\r
- }\r
- el = df;\r
- }\r
- return el;\r
- }\r
-\r
- /**\r
- * @ignore\r
- * Nasty code for IE's broken table implementation\r
- */\r
- function insertIntoTable(tag, where, el, html) {\r
- var node,\r
- before;\r
-\r
- tempTableEl = tempTableEl || document.createElement('div');\r
-\r
- if(tag == 'td' && (where == afterbegin || where == beforeend) ||\r
- !/td|tr|tbody/i.test(tag) && (where == beforebegin || where == afterend)) {\r
- return;\r
- }\r
- before = where == beforebegin ? el :\r
- where == afterend ? el.nextSibling :\r
- where == afterbegin ? el.firstChild : null;\r
-\r
- if (where == beforebegin || where == afterend) {\r
- el = el.parentNode;\r
- }\r
-\r
- if (tag == 'td' || (tag == 'tr' && (where == beforeend || where == afterbegin))) {\r
- node = ieTable(4, trs, html, tre);\r
- } else if ((tag == 'tbody' && (where == beforeend || where == afterbegin)) ||\r
- (tag == 'tr' && (where == beforebegin || where == afterend))) {\r
- node = ieTable(3, tbs, html, tbe);\r
- } else {\r
- node = ieTable(2, ts, html, te);\r
- }\r
- el.insertBefore(node, before);\r
- return node;\r
- }\r
-\r
-\r
- pub = {\r
- /**\r
- * Returns the markup for the passed Element(s) config.\r
- * @param {Object} o The DOM object spec (and children)\r
- * @return {String}\r
- */\r
- markup : function(o){\r
- return createHtml(o);\r
- },\r
- \r
- /**\r
- * Applies a style specification to an element.\r
- * @param {String/HTMLElement} el The element to apply styles to\r
- * @param {String/Object/Function} styles A style specification string e.g. 'width:100px', or object in the form {width:'100px'}, or\r
- * a function which returns such a specification.\r
- */\r
- applyStyles : function(el, styles){\r
- if(styles){\r
- var i = 0,\r
- len,\r
- style;\r
-\r
- el = Ext.fly(el);\r
- if(Ext.isFunction(styles)){\r
- styles = styles.call();\r
- }\r
- if(Ext.isString(styles)){\r
- styles = styles.trim().split(/\s*(?::|;)\s*/);\r
- for(len = styles.length; i < len;){\r
- el.setStyle(styles[i++], styles[i++]);\r
- }\r
- }else if (Ext.isObject(styles)){\r
- el.setStyle(styles);\r
- }\r
- }\r
- },\r
-\r
- /**\r
- * Inserts an HTML fragment into the DOM.\r
- * @param {String} where Where to insert the html in relation to el - beforeBegin, afterBegin, beforeEnd, afterEnd.\r
- * @param {HTMLElement} el The context element\r
- * @param {String} html The HTML fragment\r
- * @return {HTMLElement} The new node\r
- */\r
- insertHtml : function(where, el, html){\r
- var hash = {},\r
- hashVal,\r
- setStart,\r
- range,\r
- frag,\r
- rangeEl,\r
- rs;\r
-\r
- where = where.toLowerCase();\r
- // add these here because they are used in both branches of the condition.\r
- hash[beforebegin] = ['BeforeBegin', 'previousSibling'];\r
- hash[afterend] = ['AfterEnd', 'nextSibling'];\r
-\r
- if (el.insertAdjacentHTML) {\r
- if(tableRe.test(el.tagName) && (rs = insertIntoTable(el.tagName.toLowerCase(), where, el, html))){\r
- return rs;\r
- }\r
- // add these two to the hash.\r
- hash[afterbegin] = ['AfterBegin', 'firstChild'];\r
- hash[beforeend] = ['BeforeEnd', 'lastChild'];\r
- if ((hashVal = hash[where])) {\r
- el.insertAdjacentHTML(hashVal[0], html);\r
- return el[hashVal[1]];\r
- }\r
- } else {\r
- range = el.ownerDocument.createRange();\r
- setStart = 'setStart' + (/end/i.test(where) ? 'After' : 'Before');\r
- if (hash[where]) {\r
- range[setStart](el);\r
- frag = range.createContextualFragment(html);\r
- el.parentNode.insertBefore(frag, where == beforebegin ? el : el.nextSibling);\r
- return el[(where == beforebegin ? 'previous' : 'next') + 'Sibling'];\r
- } else {\r
- rangeEl = (where == afterbegin ? 'first' : 'last') + 'Child';\r
- if (el.firstChild) {\r
- range[setStart](el[rangeEl]);\r
- frag = range.createContextualFragment(html);\r
- if(where == afterbegin){\r
- el.insertBefore(frag, el.firstChild);\r
- }else{\r
- el.appendChild(frag);\r
- }\r
- } else {\r
- el.innerHTML = html;\r
- }\r
- return el[rangeEl];\r
- }\r
- }\r
- throw 'Illegal insertion point -> "' + where + '"';\r
- },\r
-\r
- /**\r
- * Creates new DOM element(s) and inserts them before el.\r
- * @param {Mixed} el The context element\r
- * @param {Object/String} o The DOM object spec (and children) or raw HTML blob\r
- * @param {Boolean} returnElement (optional) true to return a Ext.Element\r
- * @return {HTMLElement/Ext.Element} The new node\r
- */\r
- insertBefore : function(el, o, returnElement){\r
- return doInsert(el, o, returnElement, beforebegin);\r
- },\r
-\r
- /**\r
- * Creates new DOM element(s) and inserts them after el.\r
- * @param {Mixed} el The context element\r
- * @param {Object} o The DOM object spec (and children)\r
- * @param {Boolean} returnElement (optional) true to return a Ext.Element\r
- * @return {HTMLElement/Ext.Element} The new node\r
- */\r
- insertAfter : function(el, o, returnElement){\r
- return doInsert(el, o, returnElement, afterend, 'nextSibling');\r
- },\r
-\r
- /**\r
- * Creates new DOM element(s) and inserts them as the first child of el.\r
- * @param {Mixed} el The context element\r
- * @param {Object/String} o The DOM object spec (and children) or raw HTML blob\r
- * @param {Boolean} returnElement (optional) true to return a Ext.Element\r
- * @return {HTMLElement/Ext.Element} The new node\r
- */\r
- insertFirst : function(el, o, returnElement){\r
- return doInsert(el, o, returnElement, afterbegin, 'firstChild');\r
- },\r
-\r
- /**\r
- * Creates new DOM element(s) and appends them to el.\r
- * @param {Mixed} el The context element\r
- * @param {Object/String} o The DOM object spec (and children) or raw HTML blob\r
- * @param {Boolean} returnElement (optional) true to return a Ext.Element\r
- * @return {HTMLElement/Ext.Element} The new node\r
- */\r
- append : function(el, o, returnElement){\r
- return doInsert(el, o, returnElement, beforeend, '', true);\r
- },\r
-\r
- /**\r
- * Creates new DOM element(s) and overwrites the contents of el with them.\r
- * @param {Mixed} el The context element\r
- * @param {Object/String} o The DOM object spec (and children) or raw HTML blob\r
- * @param {Boolean} returnElement (optional) true to return a Ext.Element\r
- * @return {HTMLElement/Ext.Element} The new node\r
- */\r
- overwrite : function(el, o, returnElement){\r
- el = Ext.getDom(el);\r
- el.innerHTML = createHtml(o);\r
- return returnElement ? Ext.get(el.firstChild) : el.firstChild;\r
- },\r
-\r
- createHtml : createHtml\r
- };\r
- return pub;\r
-}();
\ No newline at end of file