Upgrade to ExtJS 3.2.0 - Released 03/30/2010
[extjs.git] / src / ext-core / src / core / Element.insertion.js
similarity index 96%
rename from src/core/core/Element.insertion.js
rename to src/ext-core/src/core/Element.insertion.js
index 3c94dfe..8185fad 100644 (file)
 /*!
- * Ext JS Library 3.1.1
- * Copyright(c) 2006-2010 Ext JS, LLC
+ * Ext JS Library 3.2.0
+ * Copyright(c) 2006-2010 Ext JS, Inc.
  * licensing@extjs.com
  * http://www.extjs.com/license
  */
-/**\r
- * @class Ext.Element\r
- */\r
-Ext.Element.addMethods(\r
-function() {\r
-       var GETDOM = Ext.getDom,\r
-               GET = Ext.get,\r
-               DH = Ext.DomHelper;\r
-       \r
-       return {\r
-           /**\r
-            * Appends the passed element(s) to this element\r
-            * @param {String/HTMLElement/Array/Element/CompositeElement} el\r
-            * @return {Ext.Element} this\r
-            */\r
-           appendChild: function(el){        \r
-               return GET(el).appendTo(this);        \r
-           },\r
-       \r
-           /**\r
-            * Appends this element to the passed element\r
-            * @param {Mixed} el The new parent element\r
-            * @return {Ext.Element} this\r
-            */\r
-           appendTo: function(el){        \r
-               GETDOM(el).appendChild(this.dom);        \r
-               return this;\r
-           },\r
-       \r
-           /**\r
-            * Inserts this element before the passed element in the DOM\r
-            * @param {Mixed} el The element before which this element will be inserted\r
-            * @return {Ext.Element} this\r
-            */\r
-           insertBefore: function(el){                   \r
-               (el = GETDOM(el)).parentNode.insertBefore(this.dom, el);\r
-               return this;\r
-           },\r
-       \r
-           /**\r
-            * Inserts this element after the passed element in the DOM\r
-            * @param {Mixed} el The element to insert after\r
-            * @return {Ext.Element} this\r
-            */\r
-           insertAfter: function(el){\r
-               (el = GETDOM(el)).parentNode.insertBefore(this.dom, el.nextSibling);\r
-               return this;\r
-           },\r
-       \r
-           /**\r
-            * Inserts (or creates) an element (or DomHelper config) as the first child of this element\r
-            * @param {Mixed/Object} el The id or element to insert or a DomHelper config to create and insert\r
-            * @return {Ext.Element} The new child\r
-            */\r
-           insertFirst: function(el, returnDom){\r
-            el = el || {};\r
-            if(el.nodeType || el.dom || typeof el == 'string'){ // element\r
-                el = GETDOM(el);\r
-                this.dom.insertBefore(el, this.dom.firstChild);\r
-                return !returnDom ? GET(el) : el;\r
-            }else{ // dh config\r
-                return this.createChild(el, this.dom.firstChild, returnDom);\r
-            }\r
-        },\r
-       \r
-           /**\r
-            * Replaces the passed element with this element\r
-            * @param {Mixed} el The element to replace\r
-            * @return {Ext.Element} this\r
-            */\r
-           replace: function(el){\r
-               el = GET(el);\r
-               this.insertBefore(el);\r
-               el.remove();\r
-               return this;\r
-           },\r
-       \r
-           /**\r
-            * Replaces this element with the passed element\r
-            * @param {Mixed/Object} el The new element or a DomHelper config of an element to create\r
-            * @return {Ext.Element} this\r
-            */\r
-           replaceWith: function(el){\r
-                   var me = this;\r
-                \r
-            if(el.nodeType || el.dom || typeof el == 'string'){\r
-                el = GETDOM(el);\r
-                me.dom.parentNode.insertBefore(el, me.dom);\r
-            }else{\r
-                el = DH.insertBefore(me.dom, el);\r
-            }\r
-               \r
-               delete Ext.elCache[me.id];\r
-               Ext.removeNode(me.dom);      \r
-               me.id = Ext.id(me.dom = el);\r
-               Ext.Element.addToCache(me.isFlyweight ? new Ext.Element(me.dom) : me);     \r
-            return me;\r
-           },\r
-           \r
-               /**\r
-                * Creates the passed DomHelper config and appends it to this element or optionally inserts it before the passed child element.\r
-                * @param {Object} config DomHelper element config object.  If no tag is specified (e.g., {tag:'input'}) then a div will be\r
-                * automatically generated with the specified attributes.\r
-                * @param {HTMLElement} insertBefore (optional) a child element of this element\r
-                * @param {Boolean} returnDom (optional) true to return the dom node instead of creating an Element\r
-                * @return {Ext.Element} The new child element\r
-                */\r
-               createChild: function(config, insertBefore, returnDom){\r
-                   config = config || {tag:'div'};\r
-                   return insertBefore ? \r
-                          DH.insertBefore(insertBefore, config, returnDom !== true) :  \r
-                          DH[!this.dom.firstChild ? 'overwrite' : 'append'](this.dom, config,  returnDom !== true);\r
-               },\r
-               \r
-               /**\r
-                * Creates and wraps this element with another element\r
-                * @param {Object} config (optional) DomHelper element config object for the wrapper element or null for an empty div\r
-                * @param {Boolean} returnDom (optional) True to return the raw DOM element instead of Ext.Element\r
-                * @return {HTMLElement/Element} The newly created wrapper element\r
-                */\r
-               wrap: function(config, returnDom){        \r
-                   var newEl = DH.insertBefore(this.dom, config || {tag: "div"}, !returnDom);\r
-                   newEl.dom ? newEl.dom.appendChild(this.dom) : newEl.appendChild(this.dom);\r
-                   return newEl;\r
-               },\r
-               \r
-               /**\r
-                * Inserts an html fragment into this element\r
-                * @param {String} where Where to insert the html in relation to this element - beforeBegin, afterBegin, beforeEnd, afterEnd.\r
-                * @param {String} html The HTML fragment\r
-                * @param {Boolean} returnEl (optional) True to return an Ext.Element (defaults to false)\r
-                * @return {HTMLElement/Ext.Element} The inserted node (or nearest related if more than 1 inserted)\r
-                */\r
-               insertHtml : function(where, html, returnEl){\r
-                   var el = DH.insertHtml(where, this.dom, html);\r
-                   return returnEl ? Ext.get(el) : el;\r
-               }\r
-       }\r
+/**
+ * @class Ext.Element
+ */
+Ext.Element.addMethods(
+function() {
+       var GETDOM = Ext.getDom,
+               GET = Ext.get,
+               DH = Ext.DomHelper;
+       
+       return {
+           /**
+            * Appends the passed element(s) to this element
+            * @param {String/HTMLElement/Array/Element/CompositeElement} el
+            * @return {Ext.Element} this
+            */
+           appendChild: function(el){        
+               return GET(el).appendTo(this);        
+           },
+       
+           /**
+            * Appends this element to the passed element
+            * @param {Mixed} el The new parent element
+            * @return {Ext.Element} this
+            */
+           appendTo: function(el){        
+               GETDOM(el).appendChild(this.dom);        
+               return this;
+           },
+       
+           /**
+            * Inserts this element before the passed element in the DOM
+            * @param {Mixed} el The element before which this element will be inserted
+            * @return {Ext.Element} this
+            */
+           insertBefore: function(el){                   
+               (el = GETDOM(el)).parentNode.insertBefore(this.dom, el);
+               return this;
+           },
+       
+           /**
+            * Inserts this element after the passed element in the DOM
+            * @param {Mixed} el The element to insert after
+            * @return {Ext.Element} this
+            */
+           insertAfter: function(el){
+               (el = GETDOM(el)).parentNode.insertBefore(this.dom, el.nextSibling);
+               return this;
+           },
+       
+           /**
+            * Inserts (or creates) an element (or DomHelper config) as the first child of this element
+            * @param {Mixed/Object} el The id or element to insert or a DomHelper config to create and insert
+            * @return {Ext.Element} The new child
+            */
+           insertFirst: function(el, returnDom){
+            el = el || {};
+            if(el.nodeType || el.dom || typeof el == 'string'){ // element
+                el = GETDOM(el);
+                this.dom.insertBefore(el, this.dom.firstChild);
+                return !returnDom ? GET(el) : el;
+            }else{ // dh config
+                return this.createChild(el, this.dom.firstChild, returnDom);
+            }
+        },
+       
+           /**
+            * Replaces the passed element with this element
+            * @param {Mixed} el The element to replace
+            * @return {Ext.Element} this
+            */
+           replace: function(el){
+               el = GET(el);
+               this.insertBefore(el);
+               el.remove();
+               return this;
+           },
+       
+           /**
+            * Replaces this element with the passed element
+            * @param {Mixed/Object} el The new element or a DomHelper config of an element to create
+            * @return {Ext.Element} this
+            */
+           replaceWith: function(el){
+                   var me = this;
+                
+            if(el.nodeType || el.dom || typeof el == 'string'){
+                el = GETDOM(el);
+                me.dom.parentNode.insertBefore(el, me.dom);
+            }else{
+                el = DH.insertBefore(me.dom, el);
+            }
+               
+               delete Ext.elCache[me.id];
+               Ext.removeNode(me.dom);      
+               me.id = Ext.id(me.dom = el);
+               Ext.Element.addToCache(me.isFlyweight ? new Ext.Element(me.dom) : me);     
+            return me;
+           },
+           
+               /**
+                * Creates the passed DomHelper config and appends it to this element or optionally inserts it before the passed child element.
+                * @param {Object} config DomHelper element config object.  If no tag is specified (e.g., {tag:'input'}) then a div will be
+                * automatically generated with the specified attributes.
+                * @param {HTMLElement} insertBefore (optional) a child element of this element
+                * @param {Boolean} returnDom (optional) true to return the dom node instead of creating an Element
+                * @return {Ext.Element} The new child element
+                */
+               createChild: function(config, insertBefore, returnDom){
+                   config = config || {tag:'div'};
+                   return insertBefore ? 
+                          DH.insertBefore(insertBefore, config, returnDom !== true) :  
+                          DH[!this.dom.firstChild ? 'overwrite' : 'append'](this.dom, config,  returnDom !== true);
+               },
+               
+               /**
+                * Creates and wraps this element with another element
+                * @param {Object} config (optional) DomHelper element config object for the wrapper element or null for an empty div
+                * @param {Boolean} returnDom (optional) True to return the raw DOM element instead of Ext.Element
+                * @return {HTMLElement/Element} The newly created wrapper element
+                */
+               wrap: function(config, returnDom){        
+                   var newEl = DH.insertBefore(this.dom, config || {tag: "div"}, !returnDom);
+                   newEl.dom ? newEl.dom.appendChild(this.dom) : newEl.appendChild(this.dom);
+                   return newEl;
+               },
+               
+               /**
+                * Inserts an html fragment into this element
+                * @param {String} where Where to insert the html in relation to this element - beforeBegin, afterBegin, beforeEnd, afterEnd.
+                * @param {String} html The HTML fragment
+                * @param {Boolean} returnEl (optional) True to return an Ext.Element (defaults to false)
+                * @return {HTMLElement/Ext.Element} The inserted node (or nearest related if more than 1 inserted)
+                */
+               insertHtml : function(where, html, returnEl){
+                   var el = DH.insertHtml(where, this.dom, html);
+                   return returnEl ? Ext.get(el) : el;
+               }
+       }
 }());
\ No newline at end of file