PageRenderTime 19ms CodeModel.GetById 15ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/hippo/src/main/webapp/ext/src/core/Element.insertion-more.js

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