PageRenderTime 124ms CodeModel.GetById 42ms RepoModel.GetById 2ms app.codeStats 0ms

/ext-4.1.0_b3/docs/source/Element.scroll.html

https://bitbucket.org/srogerf/javascript
HTML | 234 lines | 218 code | 16 blank | 0 comment | 0 complexity | 3c18f0b9780502244882a2f3135212c0 MD5 | raw file
  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-dom-Element'>/**
  19. </span> * @class Ext.dom.Element
  20. */
  21. Ext.dom.Element.override({
  22. <span id='Ext-dom-Element-method-isScrollable'> /**
  23. </span> * Returns true if this element is scrollable.
  24. * @return {Boolean}
  25. */
  26. isScrollable: function() {
  27. var dom = this.dom;
  28. return dom.scrollHeight &gt; dom.clientHeight || dom.scrollWidth &gt; dom.clientWidth;
  29. },
  30. <span id='Ext-dom-Element-method-getScroll'> /**
  31. </span> * Returns the current scroll position of the element.
  32. * @return {Object} An object containing the scroll position in the format
  33. * `{left: (scrollLeft), top: (scrollTop)}`
  34. */
  35. getScroll: function() {
  36. var d = this.dom,
  37. doc = document,
  38. body = doc.body,
  39. docElement = doc.documentElement,
  40. l,
  41. t,
  42. ret;
  43. if (d == doc || d == body) {
  44. if (Ext.isIE &amp;&amp; Ext.isStrict) {
  45. l = docElement.scrollLeft;
  46. t = docElement.scrollTop;
  47. } else {
  48. l = window.pageXOffset;
  49. t = window.pageYOffset;
  50. }
  51. ret = {
  52. left: l || (body ? body.scrollLeft : 0),
  53. top : t || (body ? body.scrollTop : 0)
  54. };
  55. } else {
  56. ret = {
  57. left: d.scrollLeft,
  58. top : d.scrollTop
  59. };
  60. }
  61. return ret;
  62. },
  63. <span id='Ext-dom-Element-method-scrollBy'> /**
  64. </span> * Scrolls this element by the passed delta values, optionally animating.
  65. *
  66. * All of the following are equivalent:
  67. *
  68. * el.scrollBy(10, 10, true);
  69. * el.scrollBy([10, 10], true);
  70. * el.scrollBy({ x: 10, y: 10 }, true);
  71. *
  72. * @param {Number/Number[]/Object} deltaX Either the x delta, an Array specifying x and y deltas or
  73. * an object with &quot;x&quot; and &quot;y&quot; properties.
  74. * @param {Number/Boolean/Object} deltaY Either the y delta, or an animate flag or config object.
  75. * @param {Boolean/Object} animate Animate flag/config object if the delta values were passed separately.
  76. * @return {Ext.Element} this
  77. */
  78. scrollBy: function(deltaX, deltaY, animate) {
  79. var me = this,
  80. dom = me.dom;
  81. // Extract args if deltas were passed as an Array.
  82. if (deltaX.length) {
  83. animate = deltaY;
  84. deltaY = deltaX[1];
  85. deltaX = deltaX[0];
  86. } else if (typeof deltaX != 'number') { // or an object
  87. animate = deltaY;
  88. deltaY = deltaX.y;
  89. deltaX = deltaX.x;
  90. }
  91. if (deltaX) {
  92. me.scrollTo('left', Math.max(Math.min(dom.scrollLeft + deltaX, dom.scrollWidth - dom.clientWidth), 0), animate);
  93. }
  94. if (deltaY) {
  95. me.scrollTo('top', Math.max(Math.min(dom.scrollTop + deltaY, dom.scrollHeight - dom.clientHeight), 0), animate);
  96. }
  97. return me;
  98. },
  99. <span id='Ext-dom-Element-method-scrollTo'> /**
  100. </span> * Scrolls this element the specified scroll point. It does NOT do bounds checking so
  101. * if you scroll to a weird value it will try to do it. For auto bounds checking, use #scroll.
  102. * @param {String} side Either &quot;left&quot; for scrollLeft values or &quot;top&quot; for scrollTop values.
  103. * @param {Number} value The new scroll value
  104. * @param {Boolean/Object} [animate] true for the default animation or a standard Element
  105. * animation config object
  106. * @return {Ext.Element} this
  107. */
  108. scrollTo: function(side, value, animate) {
  109. //check if we're scrolling top or left
  110. var top = /top/i.test(side),
  111. me = this,
  112. dom = me.dom,
  113. obj = {},
  114. prop;
  115. if (!animate || !me.anim) {
  116. // just setting the value, so grab the direction
  117. prop = 'scroll' + (top ? 'Top' : 'Left');
  118. dom[prop] = value;
  119. }
  120. else {
  121. if (!Ext.isObject(animate)) {
  122. animate = {};
  123. }
  124. obj['scroll' + (top ? 'Top' : 'Left')] = value;
  125. me.animate(Ext.applyIf({
  126. to: obj
  127. }, animate));
  128. }
  129. return me;
  130. },
  131. <span id='Ext-dom-Element-method-scrollIntoView'> /**
  132. </span> * Scrolls this element into view within the passed container.
  133. * @param {String/HTMLElement/Ext.Element} [container=document.body] The container element
  134. * to scroll. Should be a string (id), dom node, or Ext.Element.
  135. * @param {Boolean} [hscroll=true] False to disable horizontal scroll.
  136. * @return {Ext.dom.Element} this
  137. */
  138. scrollIntoView: function(container, hscroll) {
  139. container = Ext.getDom(container) || Ext.getBody().dom;
  140. var el = this.dom,
  141. offsets = this.getOffsetsTo(container),
  142. // el's box
  143. left = offsets[0] + container.scrollLeft,
  144. top = offsets[1] + container.scrollTop,
  145. bottom = top + el.offsetHeight,
  146. right = left + el.offsetWidth,
  147. // ct's box
  148. ctClientHeight = container.clientHeight,
  149. ctScrollTop = parseInt(container.scrollTop, 10),
  150. ctScrollLeft = parseInt(container.scrollLeft, 10),
  151. ctBottom = ctScrollTop + ctClientHeight,
  152. ctRight = ctScrollLeft + container.clientWidth;
  153. if (el.offsetHeight &gt; ctClientHeight || top &lt; ctScrollTop) {
  154. container.scrollTop = top;
  155. } else if (bottom &gt; ctBottom) {
  156. container.scrollTop = bottom - ctClientHeight;
  157. }
  158. // corrects IE, other browsers will ignore
  159. container.scrollTop = container.scrollTop;
  160. if (hscroll !== false) {
  161. if (el.offsetWidth &gt; container.clientWidth || left &lt; ctScrollLeft) {
  162. container.scrollLeft = left;
  163. }
  164. else if (right &gt; ctRight) {
  165. container.scrollLeft = right - container.clientWidth;
  166. }
  167. container.scrollLeft = container.scrollLeft;
  168. }
  169. return this;
  170. },
  171. // @private
  172. scrollChildIntoView: function(child, hscroll) {
  173. Ext.fly(child, '_scrollChildIntoView').scrollIntoView(this, hscroll);
  174. },
  175. <span id='Ext-dom-Element-method-scroll'> /**
  176. </span> * Scrolls this element the specified direction. Does bounds checking to make sure the scroll is
  177. * within this element's scrollable range.
  178. * @param {String} direction Possible values are:
  179. *
  180. * - `&quot;l&quot;` (or `&quot;left&quot;`)
  181. * - `&quot;r&quot;` (or `&quot;right&quot;`)
  182. * - `&quot;t&quot;` (or `&quot;top&quot;`, or `&quot;up&quot;`)
  183. * - `&quot;b&quot;` (or `&quot;bottom&quot;`, or `&quot;down&quot;`)
  184. *
  185. * @param {Number} distance How far to scroll the element in pixels
  186. * @param {Boolean/Object} [animate] true for the default animation or a standard Element
  187. * animation config object
  188. * @return {Boolean} Returns true if a scroll was triggered or false if the element
  189. * was scrolled as far as it could go.
  190. */
  191. scroll: function(direction, distance, animate) {
  192. if (!this.isScrollable()) {
  193. return false;
  194. }
  195. var el = this.dom,
  196. l = el.scrollLeft, t = el.scrollTop,
  197. w = el.scrollWidth, h = el.scrollHeight,
  198. cw = el.clientWidth, ch = el.clientHeight,
  199. scrolled = false, v,
  200. hash = {
  201. l: Math.min(l + distance, w - cw),
  202. r: v = Math.max(l - distance, 0),
  203. t: Math.max(t - distance, 0),
  204. b: Math.min(t + distance, h - ch)
  205. };
  206. hash.d = hash.b;
  207. hash.u = hash.t;
  208. direction = direction.substr(0, 1);
  209. if ((v = hash[direction]) &gt; -1) {
  210. scrolled = true;
  211. this.scrollTo(direction == 'l' || direction == 'r' ? 'left' : 'top', v, this.anim(animate));
  212. }
  213. return scrolled;
  214. }
  215. });
  216. </pre>
  217. </body>
  218. </html>