3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4 <title>The source code</title>
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <body onload="prettyPrint();">
9 <pre class="prettyprint lang-js">/*!
10 * Ext JS Library 3.2.0
11 * Copyright(c) 2006-2010 Ext JS, Inc.
13 * http://www.extjs.com/license
16 * @class Ext.DomHelper
18 Ext.apply(Ext.DomHelper,
21 afterbegin = 'afterbegin',
22 afterend = 'afterend',
23 beforebegin = 'beforebegin',
24 beforeend = 'beforeend';
27 function doInsert(el, o, returnElement, pos, sibling, append){
31 newNode = createDom(o, null);
33 el.appendChild(newNode);
35 (sibling == 'firstChild' ? el : el.parentNode).insertBefore(newNode, el[sibling] || el);
38 newNode = Ext.DomHelper.insertHtml(pos, el, Ext.DomHelper.createHtml(o));
40 return returnElement ? Ext.get(newNode, true) : newNode;
45 function createDom(o, parentNode){
53 if (Ext.isArray(o)) { // Allow Arrays of siblings to be inserted
54 el = doc.createDocumentFragment(); // in one shot using a DocumentFragment
55 Ext.each(o, function(v) {
58 } else if (Ext.isString(o)) { // Allow a string as a child spec.
59 el = doc.createTextNode(o);
61 el = doc.createElement( o.tag || 'div' );
62 useSet = !!el.setAttribute; // In IE some elements don't have setAttribute
63 Ext.iterate(o, function(attr, val){
64 if(!/tag|children|cn|html|style/.test(attr)){
69 el.setAttribute(attr, val);
76 Ext.DomHelper.applyStyles(el, o.style);
78 if ((cn = o.children || o.cn)) {
81 el.innerHTML = o.html;
85 parentNode.appendChild(el);
91 <div id="method-Ext.DomHelper-createTemplate"></div>/**
92 * Creates a new Ext.Template from the DOM object spec.
93 * @param {Object} o The DOM object spec (and children)
94 * @return {Ext.Template} The new template
96 createTemplate : function(o){
97 var html = Ext.DomHelper.createHtml(o);
98 return new Ext.Template(html);
101 <div id="prop-Ext.DomHelper-useDom"></div>/** True to force the use of DOM instead of html fragments @type Boolean */
104 <div id="method-Ext.DomHelper-insertBefore"></div>/**
105 * Creates new DOM element(s) and inserts them before el.
106 * @param {Mixed} el The context element
107 * @param {Object/String} o The DOM object spec (and children) or raw HTML blob
108 * @param {Boolean} returnElement (optional) true to return a Ext.Element
109 * @return {HTMLElement/Ext.Element} The new node
112 insertBefore : function(el, o, returnElement){
113 return doInsert(el, o, returnElement, beforebegin);
116 <div id="method-Ext.DomHelper-insertAfter"></div>/**
117 * Creates new DOM element(s) and inserts them after el.
118 * @param {Mixed} el The context element
119 * @param {Object} o The DOM object spec (and children)
120 * @param {Boolean} returnElement (optional) true to return a Ext.Element
121 * @return {HTMLElement/Ext.Element} The new node
124 insertAfter : function(el, o, returnElement){
125 return doInsert(el, o, returnElement, afterend, 'nextSibling');
128 <div id="method-Ext.DomHelper-insertFirst"></div>/**
129 * Creates new DOM element(s) and inserts them as the first child of el.
130 * @param {Mixed} el The context element
131 * @param {Object/String} o The DOM object spec (and children) or raw HTML blob
132 * @param {Boolean} returnElement (optional) true to return a Ext.Element
133 * @return {HTMLElement/Ext.Element} The new node
136 insertFirst : function(el, o, returnElement){
137 return doInsert(el, o, returnElement, afterbegin, 'firstChild');
140 <div id="method-Ext.DomHelper-append"></div>/**
141 * Creates new DOM element(s) and appends them to el.
142 * @param {Mixed} el The context element
143 * @param {Object/String} o The DOM object spec (and children) or raw HTML blob
144 * @param {Boolean} returnElement (optional) true to return a Ext.Element
145 * @return {HTMLElement/Ext.Element} The new node
148 append: function(el, o, returnElement){
149 return doInsert(el, o, returnElement, beforeend, '', true);
152 <div id="method-Ext.DomHelper-createDom"></div>/**
153 * Creates new DOM element(s) without inserting them to the document.
154 * @param {Object/String} o The DOM object spec (and children) or raw HTML blob
155 * @return {HTMLElement} The new uninserted node