3 <title>The source code</title>
\r
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
7 <body onload="prettyPrint();">
\r
8 <pre class="prettyprint lang-js">/**
\r
9 * @class Ext.DomHelper
\r
11 Ext.apply(Ext.DomHelper,
\r
14 afterbegin = 'afterbegin',
\r
15 afterend = 'afterend',
\r
16 beforebegin = 'beforebegin',
\r
17 beforeend = 'beforeend';
\r
20 function doInsert(el, o, returnElement, pos, sibling, append){
\r
21 el = Ext.getDom(el);
\r
24 newNode = createDom(o, null);
\r
26 el.appendChild(newNode);
\r
28 (sibling == 'firstChild' ? el : el.parentNode).insertBefore(newNode, el[sibling] || el);
\r
31 newNode = Ext.DomHelper.insertHtml(pos, el, Ext.DomHelper.createHtml(o));
\r
33 return returnElement ? Ext.get(newNode, true) : newNode;
\r
38 function createDom(o, parentNode){
\r
46 if (Ext.isArray(o)) { // Allow Arrays of siblings to be inserted
\r
47 el = doc.createDocumentFragment(); // in one shot using a DocumentFragment
\r
48 Ext.each(o, function(v) {
\r
51 } else if (Ext.isString(o)) { // Allow a string as a child spec.
\r
52 el = doc.createTextNode(o);
\r
54 el = doc.createElement( o.tag || 'div' );
\r
55 useSet = !!el.setAttribute; // In IE some elements don't have setAttribute
\r
56 Ext.iterate(o, function(attr, val){
\r
57 if(!/tag|children|cn|html|style/.test(attr)){
\r
62 el.setAttribute(attr, val);
\r
69 pub.applyStyles(el, o.style);
\r
71 if ((cn = o.children || o.cn)) {
\r
73 } else if (o.html) {
\r
74 el.innerHTML = o.html;
\r
78 parentNode.appendChild(el);
\r
84 <div id="method-Ext.DomHelper-createTemplate"></div>/**
\r
85 * Creates a new Ext.Template from the DOM object spec.
\r
86 * @param {Object} o The DOM object spec (and children)
\r
87 * @return {Ext.Template} The new template
\r
89 createTemplate : function(o){
\r
90 var html = Ext.DomHelper.createHtml(o);
\r
91 return new Ext.Template(html);
\r
94 <div id="prop-Ext.DomHelper-useDom"></div>/** True to force the use of DOM instead of html fragments @type Boolean */
\r
97 <div id="method-Ext.DomHelper-applyStyles"></div>/**
\r
98 * Applies a style specification to an element.
\r
99 * @param {String/HTMLElement} el The element to apply styles to
\r
100 * @param {String/Object/Function} styles A style specification string e.g. 'width:100px', or object in the form {width:'100px'}, or
\r
101 * a function which returns such a specification.
\r
103 applyStyles : function(el, styles){
\r
110 if(Ext.isFunction(styles)){
\r
111 styles = styles.call();
\r
113 if(Ext.isString(styles)){
\r
114 styles = styles.trim().split(/\s*(?::|;)\s*/);
\r
115 for(len = styles.length; i < len;){
\r
116 el.setStyle(styles[i++], styles[i++]);
\r
118 }else if (Ext.isObject(styles)){
\r
119 el.setStyle(styles);
\r
124 <div id="method-Ext.DomHelper-insertBefore"></div>/**
\r
125 * Creates new DOM element(s) and inserts them before el.
\r
126 * @param {Mixed} el The context element
\r
127 * @param {Object/String} o The DOM object spec (and children) or raw HTML blob
\r
128 * @param {Boolean} returnElement (optional) true to return a Ext.Element
\r
129 * @return {HTMLElement/Ext.Element} The new node
\r
132 insertBefore : function(el, o, returnElement){
\r
133 return doInsert(el, o, returnElement, beforebegin);
\r
136 <div id="method-Ext.DomHelper-insertAfter"></div>/**
\r
137 * Creates new DOM element(s) and inserts them after el.
\r
138 * @param {Mixed} el The context element
\r
139 * @param {Object} o The DOM object spec (and children)
\r
140 * @param {Boolean} returnElement (optional) true to return a Ext.Element
\r
141 * @return {HTMLElement/Ext.Element} The new node
\r
144 insertAfter : function(el, o, returnElement){
\r
145 return doInsert(el, o, returnElement, afterend, 'nextSibling');
\r
148 <div id="method-Ext.DomHelper-insertFirst"></div>/**
\r
149 * Creates new DOM element(s) and inserts them as the first child of el.
\r
150 * @param {Mixed} el The context element
\r
151 * @param {Object/String} o The DOM object spec (and children) or raw HTML blob
\r
152 * @param {Boolean} returnElement (optional) true to return a Ext.Element
\r
153 * @return {HTMLElement/Ext.Element} The new node
\r
156 insertFirst : function(el, o, returnElement){
\r
157 return doInsert(el, o, returnElement, afterbegin, 'firstChild');
\r
160 <div id="method-Ext.DomHelper-append"></div>/**
\r
161 * Creates new DOM element(s) and appends them to el.
\r
162 * @param {Mixed} el The context element
\r
163 * @param {Object/String} o The DOM object spec (and children) or raw HTML blob
\r
164 * @param {Boolean} returnElement (optional) true to return a Ext.Element
\r
165 * @return {HTMLElement/Ext.Element} The new node
\r
168 append: function(el, o, returnElement){
\r
169 return doInsert(el, o, returnElement, beforeend, '', true);
\r
172 <div id="method-Ext.DomHelper-createDom"></div>/**
\r
173 * Creates new DOM element(s) without inserting them to the document.
\r
174 * @param {Object/String} o The DOM object spec (and children) or raw HTML blob
\r
175 * @return {HTMLElement} The new uninserted node
\r
177 createDom: createDom
\r