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