Upgrade to ExtJS 3.1.0 - Released 12/16/2009
[extjs.git] / docs / source / Element.insertion-more.html
1 <html>\r
2 <head>\r
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
7 </head>\r
8 <body  onload="prettyPrint();">\r
9     <pre class="prettyprint lang-js">/**\r
10  * @class Ext.Element\r
11  */\r
12 Ext.apply(Ext.Element.prototype, function() {\r
13         var GETDOM = Ext.getDom,\r
14                 GET = Ext.get,\r
15                 DH = Ext.DomHelper;\r
16         \r
17         return {        \r
18                 <div id="method-Ext.Element-insertSibling"></div>/**\r
19              * Inserts (or creates) the passed element (or DomHelper config) as a sibling of this element\r
20              * @param {Mixed/Object/Array} el The id, element to insert or a DomHelper config to create and insert *or* an array of any of those.\r
21              * @param {String} where (optional) 'before' or 'after' defaults to before\r
22              * @param {Boolean} returnDom (optional) True to return the raw DOM element instead of Ext.Element\r
23              * @return {Ext.Element} The inserted Element. If an array is passed, the last inserted element is returned.\r
24              */\r
25             insertSibling: function(el, where, returnDom){\r
26                 var me = this,\r
27                         rt,\r
28                 isAfter = (where || 'before').toLowerCase() == 'after',\r
29                 insertEl;\r
30                         \r
31                 if(Ext.isArray(el)){\r
32                 insertEl = me;\r
33                     Ext.each(el, function(e) {\r
34                             rt = Ext.fly(insertEl, '_internal').insertSibling(e, where, returnDom);\r
35                     if(isAfter){\r
36                         insertEl = rt;\r
37                     }\r
38                     });\r
39                     return rt;\r
40                 }\r
41                         \r
42                 el = el || {};\r
43                 \r
44             if(el.nodeType || el.dom){\r
45                 rt = me.dom.parentNode.insertBefore(GETDOM(el), isAfter ? me.dom.nextSibling : me.dom);\r
46                 if (!returnDom) {\r
47                     rt = GET(rt);\r
48                 }\r
49             }else{\r
50                 if (isAfter && !me.dom.nextSibling) {\r
51                     rt = DH.append(me.dom.parentNode, el, !returnDom);\r
52                 } else {                    \r
53                     rt = DH[isAfter ? 'insertAfter' : 'insertBefore'](me.dom, el, !returnDom);\r
54                 }\r
55             }\r
56                 return rt;\r
57             }\r
58     };\r
59 }());</pre>    \r
60 </body>\r
61 </html>