Upgrade to ExtJS 3.1.1 - Released 02/08/2010
[extjs.git] / src / core / Element.insertion-more.js
1 /*!
2  * Ext JS Library 3.1.1
3  * Copyright(c) 2006-2010 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. If an array is passed, the last inserted element is returned.\r
22              */\r
23             insertSibling: function(el, where, returnDom){\r
24                 var me = this,\r
25                         rt,\r
26                 isAfter = (where || 'before').toLowerCase() == 'after',\r
27                 insertEl;\r
28                         \r
29                 if(Ext.isArray(el)){\r
30                 insertEl = me;\r
31                     Ext.each(el, function(e) {\r
32                             rt = Ext.fly(insertEl, '_internal').insertSibling(e, where, returnDom);\r
33                     if(isAfter){\r
34                         insertEl = rt;\r
35                     }\r
36                     });\r
37                     return rt;\r
38                 }\r
39                         \r
40                 el = el || {};\r
41                 \r
42             if(el.nodeType || el.dom){\r
43                 rt = me.dom.parentNode.insertBefore(GETDOM(el), isAfter ? me.dom.nextSibling : me.dom);\r
44                 if (!returnDom) {\r
45                     rt = GET(rt);\r
46                 }\r
47             }else{\r
48                 if (isAfter && !me.dom.nextSibling) {\r
49                     rt = DH.append(me.dom.parentNode, el, !returnDom);\r
50                 } else {                    \r
51                     rt = DH[isAfter ? 'insertAfter' : 'insertBefore'](me.dom, el, !returnDom);\r
52                 }\r
53             }\r
54                 return rt;\r
55             }\r
56     };\r
57 }());