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