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