You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

158 lines
6.2 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>The source code</title>
  6. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  8. <style type="text/css">
  9. .highlight { display: block; background-color: #ddd; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  17. <body onload="prettyPrint(); highlight();">
  18. <pre class="prettyprint lang-js"><span id='Ext-Element'>/**
  19. </span> * @class Ext.Element
  20. */
  21. Ext.Element.addMethods(
  22. function() {
  23. var GETDOM = Ext.getDom,
  24. GET = Ext.get,
  25. DH = Ext.DomHelper;
  26. return {
  27. <span id='Ext-Element-method-appendChild'> /**
  28. </span> * Appends the passed element(s) to this element
  29. * @param {String/HTMLElement/Array/Element/CompositeElement} el
  30. * @return {Ext.Element} this
  31. */
  32. appendChild: function(el){
  33. return GET(el).appendTo(this);
  34. },
  35. <span id='Ext-Element-method-appendTo'> /**
  36. </span> * Appends this element to the passed element
  37. * @param {Mixed} el The new parent element
  38. * @return {Ext.Element} this
  39. */
  40. appendTo: function(el){
  41. GETDOM(el).appendChild(this.dom);
  42. return this;
  43. },
  44. <span id='Ext-Element-method-insertBefore'> /**
  45. </span> * Inserts this element before the passed element in the DOM
  46. * @param {Mixed} el The element before which this element will be inserted
  47. * @return {Ext.Element} this
  48. */
  49. insertBefore: function(el){
  50. (el = GETDOM(el)).parentNode.insertBefore(this.dom, el);
  51. return this;
  52. },
  53. <span id='Ext-Element-method-insertAfter'> /**
  54. </span> * Inserts this element after the passed element in the DOM
  55. * @param {Mixed} el The element to insert after
  56. * @return {Ext.Element} this
  57. */
  58. insertAfter: function(el){
  59. (el = GETDOM(el)).parentNode.insertBefore(this.dom, el.nextSibling);
  60. return this;
  61. },
  62. <span id='Ext-Element-method-insertFirst'> /**
  63. </span> * Inserts (or creates) an element (or DomHelper config) as the first child of this element
  64. * @param {Mixed/Object} el The id or element to insert or a DomHelper config to create and insert
  65. * @return {Ext.Element} The new child
  66. */
  67. insertFirst: function(el, returnDom){
  68. el = el || {};
  69. if(el.nodeType || el.dom || typeof el == 'string'){ // element
  70. el = GETDOM(el);
  71. this.dom.insertBefore(el, this.dom.firstChild);
  72. return !returnDom ? GET(el) : el;
  73. }else{ // dh config
  74. return this.createChild(el, this.dom.firstChild, returnDom);
  75. }
  76. },
  77. <span id='Ext-Element-method-replace'> /**
  78. </span> * 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. <span id='Ext-Element-method-replaceWith'> /**
  89. </span> * Replaces this element with the passed element
  90. * @param {Mixed/Object} el The new element or a DomHelper config of an element to create
  91. * @return {Ext.Element} this
  92. */
  93. replaceWith: function(el){
  94. var me = this;
  95. if(el.nodeType || el.dom || typeof el == 'string'){
  96. el = GETDOM(el);
  97. me.dom.parentNode.insertBefore(el, me.dom);
  98. }else{
  99. el = DH.insertBefore(me.dom, el);
  100. }
  101. delete Ext.elCache[me.id];
  102. Ext.removeNode(me.dom);
  103. me.id = Ext.id(me.dom = el);
  104. Ext.Element.addToCache(me.isFlyweight ? new Ext.Element(me.dom) : me);
  105. return me;
  106. },
  107. <span id='Ext-Element-method-createChild'> /**
  108. </span> * Creates the passed DomHelper config and appends it to this element or optionally inserts it before the passed child element.
  109. * @param {Object} config DomHelper element config object. If no tag is specified (e.g., {tag:'input'}) then a div will be
  110. * automatically generated with the specified attributes.
  111. * @param {HTMLElement} insertBefore (optional) a child element of this element
  112. * @param {Boolean} returnDom (optional) true to return the dom node instead of creating an Element
  113. * @return {Ext.Element} The new child element
  114. */
  115. createChild: function(config, insertBefore, returnDom){
  116. config = config || {tag:'div'};
  117. return insertBefore ?
  118. DH.insertBefore(insertBefore, config, returnDom !== true) :
  119. DH[!this.dom.firstChild ? 'overwrite' : 'append'](this.dom, config, returnDom !== true);
  120. },
  121. <span id='Ext-Element-method-wrap'> /**
  122. </span> * Creates and wraps this element with another element
  123. * @param {Object} config (optional) DomHelper element config object for the wrapper element or null for an empty div
  124. * @param {Boolean} returnDom (optional) True to return the raw DOM element instead of Ext.Element
  125. * @return {HTMLElement/Element} The newly created wrapper element
  126. */
  127. wrap: function(config, returnDom){
  128. var newEl = DH.insertBefore(this.dom, config || {tag: &quot;div&quot;}, !returnDom);
  129. newEl.dom ? newEl.dom.appendChild(this.dom) : newEl.appendChild(this.dom);
  130. return newEl;
  131. },
  132. <span id='Ext-Element-method-insertHtml'> /**
  133. </span> * Inserts an html fragment into this element
  134. * @param {String} where Where to insert the html in relation to this element - beforeBegin, afterBegin, beforeEnd, afterEnd.
  135. * @param {String} html The HTML fragment
  136. * @param {Boolean} returnEl (optional) True to return an Ext.Element (defaults to false)
  137. * @return {HTMLElement/Ext.Element} The inserted node (or nearest related if more than 1 inserted)
  138. */
  139. insertHtml : function(where, html, returnEl){
  140. var el = DH.insertHtml(where, this.dom, html);
  141. return returnEl ? Ext.get(el) : el;
  142. }
  143. };
  144. }());</pre>
  145. </body>
  146. </html>