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