3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
\r
4 <title>The source code</title>
\r
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
8 <body onload="prettyPrint();">
\r
9 <pre class="prettyprint lang-js">/**
\r
10 * @class Ext.DomHelper
\r
12 Ext.apply(Ext.DomHelper,
\r
15 afterbegin = 'afterbegin',
\r
16 afterend = 'afterend',
\r
17 beforebegin = 'beforebegin',
\r
18 beforeend = 'beforeend';
\r
21 function doInsert(el, o, returnElement, pos, sibling, append){
\r
22 el = Ext.getDom(el);
\r
25 newNode = createDom(o, null);
\r
27 el.appendChild(newNode);
\r
29 (sibling == 'firstChild' ? el : el.parentNode).insertBefore(newNode, el[sibling] || el);
\r
32 newNode = Ext.DomHelper.insertHtml(pos, el, Ext.DomHelper.createHtml(o));
\r
34 return returnElement ? Ext.get(newNode, true) : newNode;
\r
39 function createDom(o, parentNode){
\r
47 if (Ext.isArray(o)) { // Allow Arrays of siblings to be inserted
\r
48 el = doc.createDocumentFragment(); // in one shot using a DocumentFragment
\r
49 Ext.each(o, function(v) {
\r
52 } else if (Ext.isString(o)) { // Allow a string as a child spec.
\r
53 el = doc.createTextNode(o);
\r
55 el = doc.createElement( o.tag || 'div' );
\r
56 useSet = !!el.setAttribute; // In IE some elements don't have setAttribute
\r
57 Ext.iterate(o, function(attr, val){
\r
58 if(!/tag|children|cn|html|style/.test(attr)){
\r
63 el.setAttribute(attr, val);
\r
70 Ext.DomHelper.applyStyles(el, o.style);
\r
72 if ((cn = o.children || o.cn)) {
\r
74 } else if (o.html) {
\r
75 el.innerHTML = o.html;
\r
79 parentNode.appendChild(el);
\r
85 <div id="method-Ext.DomHelper-createTemplate"></div>/**
\r
86 * Creates a new Ext.Template from the DOM object spec.
\r
87 * @param {Object} o The DOM object spec (and children)
\r
88 * @return {Ext.Template} The new template
\r
90 createTemplate : function(o){
\r
91 var html = Ext.DomHelper.createHtml(o);
\r
92 return new Ext.Template(html);
\r
95 <div id="prop-Ext.DomHelper-useDom"></div>/** True to force the use of DOM instead of html fragments @type Boolean */
\r
98 <div id="method-Ext.DomHelper-insertBefore"></div>/**
\r
99 * Creates new DOM element(s) and inserts them before el.
\r
100 * @param {Mixed} el The context element
\r
101 * @param {Object/String} o The DOM object spec (and children) or raw HTML blob
\r
102 * @param {Boolean} returnElement (optional) true to return a Ext.Element
\r
103 * @return {HTMLElement/Ext.Element} The new node
\r
106 insertBefore : function(el, o, returnElement){
\r
107 return doInsert(el, o, returnElement, beforebegin);
\r
110 <div id="method-Ext.DomHelper-insertAfter"></div>/**
\r
111 * Creates new DOM element(s) and inserts them after el.
\r
112 * @param {Mixed} el The context element
\r
113 * @param {Object} o The DOM object spec (and children)
\r
114 * @param {Boolean} returnElement (optional) true to return a Ext.Element
\r
115 * @return {HTMLElement/Ext.Element} The new node
\r
118 insertAfter : function(el, o, returnElement){
\r
119 return doInsert(el, o, returnElement, afterend, 'nextSibling');
\r
122 <div id="method-Ext.DomHelper-insertFirst"></div>/**
\r
123 * Creates new DOM element(s) and inserts them as the first child of el.
\r
124 * @param {Mixed} el The context element
\r
125 * @param {Object/String} o The DOM object spec (and children) or raw HTML blob
\r
126 * @param {Boolean} returnElement (optional) true to return a Ext.Element
\r
127 * @return {HTMLElement/Ext.Element} The new node
\r
130 insertFirst : function(el, o, returnElement){
\r
131 return doInsert(el, o, returnElement, afterbegin, 'firstChild');
\r
134 <div id="method-Ext.DomHelper-append"></div>/**
\r
135 * Creates new DOM element(s) and appends them to el.
\r
136 * @param {Mixed} el The context element
\r
137 * @param {Object/String} o The DOM object spec (and children) or raw HTML blob
\r
138 * @param {Boolean} returnElement (optional) true to return a Ext.Element
\r
139 * @return {HTMLElement/Ext.Element} The new node
\r
142 append: function(el, o, returnElement){
\r
143 return doInsert(el, o, returnElement, beforeend, '', true);
\r
146 <div id="method-Ext.DomHelper-createDom"></div>/**
\r
147 * Creates new DOM element(s) without inserting them to the document.
\r
148 * @param {Object/String} o The DOM object spec (and children) or raw HTML blob
\r
149 * @return {HTMLElement} The new uninserted node
\r
151 createDom: createDom
\r