3 * Copyright(c) 2006-2010 Sencha Inc.
5 * http://www.sencha.com/license
10 Ext.apply(Ext.DomHelper,
13 afterbegin = 'afterbegin',
14 afterend = 'afterend',
15 beforebegin = 'beforebegin',
16 beforeend = 'beforeend',
17 confRe = /tag|children|cn|html$/i;
20 function doInsert(el, o, returnElement, pos, sibling, append){
24 newNode = createDom(o, null);
26 el.appendChild(newNode);
28 (sibling == 'firstChild' ? el : el.parentNode).insertBefore(newNode, el[sibling] || el);
31 newNode = Ext.DomHelper.insertHtml(pos, el, Ext.DomHelper.createHtml(o));
33 return returnElement ? Ext.get(newNode, true) : newNode;
38 function createDom(o, parentNode){
46 if (Ext.isArray(o)) { // Allow Arrays of siblings to be inserted
47 el = doc.createDocumentFragment(); // in one shot using a DocumentFragment
48 for (var i = 0, l = o.length; i < l; i++) {
51 } else if (typeof o == 'string') { // Allow a string as a child spec.
52 el = doc.createTextNode(o);
54 el = doc.createElement( o.tag || 'div' );
55 useSet = !!el.setAttribute; // In IE some elements don't have setAttribute
57 if(!confRe.test(attr)){
63 el.setAttribute(attr, val);
70 Ext.DomHelper.applyStyles(el, o.style);
72 if ((cn = o.children || o.cn)) {
75 el.innerHTML = o.html;
79 parentNode.appendChild(el);
86 * Creates a new Ext.Template from the DOM object spec.
87 * @param {Object} o The DOM object spec (and children)
88 * @return {Ext.Template} The new template
90 createTemplate : function(o){
91 var html = Ext.DomHelper.createHtml(o);
92 return new Ext.Template(html);
95 /** True to force the use of DOM instead of html fragments @type Boolean */
99 * Creates new DOM element(s) and inserts them before el.
100 * @param {Mixed} el The context element
101 * @param {Object/String} o The DOM object spec (and children) or raw HTML blob
102 * @param {Boolean} returnElement (optional) true to return a Ext.Element
103 * @return {HTMLElement/Ext.Element} The new node
106 insertBefore : function(el, o, returnElement){
107 return doInsert(el, o, returnElement, beforebegin);
111 * Creates new DOM element(s) and inserts them after el.
112 * @param {Mixed} el The context element
113 * @param {Object} o The DOM object spec (and children)
114 * @param {Boolean} returnElement (optional) true to return a Ext.Element
115 * @return {HTMLElement/Ext.Element} The new node
118 insertAfter : function(el, o, returnElement){
119 return doInsert(el, o, returnElement, afterend, 'nextSibling');
123 * Creates new DOM element(s) and inserts them as the first child of el.
124 * @param {Mixed} el The context element
125 * @param {Object/String} o The DOM object spec (and children) or raw HTML blob
126 * @param {Boolean} returnElement (optional) true to return a Ext.Element
127 * @return {HTMLElement/Ext.Element} The new node
130 insertFirst : function(el, o, returnElement){
131 return doInsert(el, o, returnElement, afterbegin, 'firstChild');
135 * Creates new DOM element(s) and appends them to el.
136 * @param {Mixed} el The context element
137 * @param {Object/String} o The DOM object spec (and children) or raw HTML blob
138 * @param {Boolean} returnElement (optional) true to return a Ext.Element
139 * @return {HTMLElement/Ext.Element} The new node
142 append: function(el, o, returnElement){
143 return doInsert(el, o, returnElement, beforeend, '', true);
147 * Creates new DOM element(s) without inserting them to the document.
148 * @param {Object/String} o The DOM object spec (and children) or raw HTML blob
149 * @return {HTMLElement} The new uninserted node