~cdparra/gelee/trunk

« back to all changes in this revision

Viewing changes to webui/ecosystem/extjs/source/core/core/Element.insertion.js

  • Committer: parra
  • Date: 2010-03-15 02:39:02 UTC
  • Revision ID: svn-v4:ac5bba68-f036-4e09-846e-8f32731cc928:trunk/gelee:1433
merged gelee at svn

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Ext JS Library 3.0 RC2
 
3
 * Copyright(c) 2006-2009, Ext JS, LLC.
 
4
 * licensing@extjs.com
 
5
 * 
 
6
 * http://extjs.com/license
 
7
 */
 
8
 
 
9
/**
 
10
 * @class Ext.Element
 
11
 */
 
12
Ext.Element.addMethods(
 
13
function() {
 
14
        var GETDOM = Ext.getDom,
 
15
                GET = Ext.get,
 
16
                DH = Ext.DomHelper,
 
17
        isEl = function(el){
 
18
            return  (el.nodeType || el.dom || typeof el == 'string');  
 
19
        };
 
20
        
 
21
        return {
 
22
            /**
 
23
             * Appends the passed element(s) to this element
 
24
             * @param {String/HTMLElement/Array/Element/CompositeElement} el
 
25
             * @return {Ext.Element} this
 
26
             */
 
27
            appendChild: function(el){        
 
28
                return GET(el).appendTo(this);        
 
29
            },
 
30
        
 
31
            /**
 
32
             * Appends this element to the passed element
 
33
             * @param {Mixed} el The new parent element
 
34
             * @return {Ext.Element} this
 
35
             */
 
36
            appendTo: function(el){        
 
37
                GETDOM(el).appendChild(this.dom);        
 
38
                return this;
 
39
            },
 
40
        
 
41
            /**
 
42
             * Inserts this element before the passed element in the DOM
 
43
             * @param {Mixed} el The element before which this element will be inserted
 
44
             * @return {Ext.Element} this
 
45
             */
 
46
            insertBefore: function(el){                   
 
47
                (el = GETDOM(el)).parentNode.insertBefore(this.dom, el);
 
48
                return this;
 
49
            },
 
50
        
 
51
            /**
 
52
             * Inserts this element after the passed element in the DOM
 
53
             * @param {Mixed} el The element to insert after
 
54
             * @return {Ext.Element} this
 
55
             */
 
56
            insertAfter: function(el){
 
57
                (el = GETDOM(el)).parentNode.insertBefore(this.dom, el.nextSibling);
 
58
                return this;
 
59
            },
 
60
        
 
61
            /**
 
62
             * Inserts (or creates) an element (or DomHelper config) as the first child of this element
 
63
             * @param {Mixed/Object} el The id or element to insert or a DomHelper config to create and insert
 
64
             * @return {Ext.Element} The new child
 
65
             */
 
66
            insertFirst: function(el, returnDom){
 
67
            el = el || {};
 
68
            if(isEl(el)){ // element
 
69
                el = GETDOM(el);
 
70
                this.dom.insertBefore(el, this.dom.firstChild);
 
71
                return !returnDom ? GET(el) : el;
 
72
            }else{ // dh config
 
73
                return this.createChild(el, this.dom.firstChild, returnDom);
 
74
            }
 
75
    },
 
76
        
 
77
            /**
 
78
             * Replaces the passed element with this element
 
79
             * @param {Mixed} el The element to replace
 
80
             * @return {Ext.Element} this
 
81
             */
 
82
            replace: function(el){
 
83
                el = GET(el);
 
84
                this.insertBefore(el);
 
85
                el.remove();
 
86
                return this;
 
87
            },
 
88
        
 
89
            /**
 
90
             * Replaces this element with the passed element
 
91
             * @param {Mixed/Object} el The new element or a DomHelper config of an element to create
 
92
             * @return {Ext.Element} this
 
93
             */
 
94
            replaceWith: function(el){
 
95
                    var me = this,
 
96
                        Element = Ext.Element;
 
97
            if(isEl(el)){
 
98
                el = GETDOM(el);
 
99
                me.dom.parentNode.insertBefore(el, me.dom);
 
100
            }else{
 
101
                el = DH.insertBefore(me.dom, el);
 
102
            }
 
103
                
 
104
                delete Element.cache[me.id];
 
105
                Ext.removeNode(me.dom);      
 
106
                me.id = Ext.id(me.dom = el);
 
107
                return Element.cache[me.id] = me;        
 
108
            },
 
109
            
 
110
                /**
 
111
                 * Creates the passed DomHelper config and appends it to this element or optionally inserts it before the passed child element.
 
112
                 * @param {Object} config DomHelper element config object.  If no tag is specified (e.g., {tag:'input'}) then a div will be
 
113
                 * automatically generated with the specified attributes.
 
114
                 * @param {HTMLElement} insertBefore (optional) a child element of this element
 
115
                 * @param {Boolean} returnDom (optional) true to return the dom node instead of creating an Element
 
116
                 * @return {Ext.Element} The new child element
 
117
                 */
 
118
                createChild: function(config, insertBefore, returnDom){
 
119
                    config = config || {tag:'div'};
 
120
                    return insertBefore ? 
 
121
                           DH.insertBefore(insertBefore, config, returnDom !== true) :  
 
122
                           DH[!this.dom.firstChild ? 'overwrite' : 'append'](this.dom, config,  returnDom !== true);
 
123
                },
 
124
                
 
125
                /**
 
126
                 * Creates and wraps this element with another element
 
127
                 * @param {Object} config (optional) DomHelper element config object for the wrapper element or null for an empty div
 
128
                 * @param {Boolean} returnDom (optional) True to return the raw DOM element instead of Ext.Element
 
129
                 * @return {HTMLElement/Element} The newly created wrapper element
 
130
                 */
 
131
                wrap: function(config, returnDom){        
 
132
                    var newEl = DH.insertBefore(this.dom, config || {tag: "div"}, !returnDom);
 
133
                    newEl.dom ? newEl.dom.appendChild(this.dom) : newEl.appendChild(this.dom);
 
134
                    return newEl;
 
135
                },
 
136
                
 
137
                /**
 
138
                 * Inserts an html fragment into this element
 
139
                 * @param {String} where Where to insert the html in relation to this element - beforeBegin, afterBegin, beforeEnd, afterEnd.
 
140
                 * @param {String} html The HTML fragment
 
141
                 * @param {Boolean} returnEl (optional) True to return an Ext.Element (defaults to false)
 
142
                 * @return {HTMLElement/Ext.Element} The inserted node (or nearest related if more than 1 inserted)
 
143
                 */
 
144
                insertHtml : function(where, html, returnEl){
 
145
                    var el = DH.insertHtml(where, this.dom, html);
 
146
                    return returnEl ? Ext.get(el) : el;
 
147
                }
 
148
        }
 
149
}());
 
 
b'\\ No newline at end of file'