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.

131 lines
5.3 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. <span id='Ext-Element-method-scrollTo'> /**
  23. </span> * Scrolls this element the specified scroll point. It does NOT do bounds checking so if you scroll to a weird value it will try to do it. For auto bounds checking, use scroll().
  24. * @param {String} side Either &quot;left&quot; for scrollLeft values or &quot;top&quot; for scrollTop values.
  25. * @param {Number} value The new scroll value
  26. * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
  27. * @return {Element} this
  28. */
  29. scrollTo : function(side, value, animate) {
  30. //check if we're scrolling top or left
  31. var top = /top/i.test(side),
  32. me = this,
  33. dom = me.dom,
  34. prop;
  35. if (!animate || !me.anim) {
  36. // just setting the value, so grab the direction
  37. prop = 'scroll' + (top ? 'Top' : 'Left');
  38. dom[prop] = value;
  39. }
  40. else {
  41. // if scrolling top, we need to grab scrollLeft, if left, scrollTop
  42. prop = 'scroll' + (top ? 'Left' : 'Top');
  43. me.anim({scroll: {to: top ? [dom[prop], value] : [value, dom[prop]]}}, me.preanim(arguments, 2), 'scroll');
  44. }
  45. return me;
  46. },
  47. <span id='Ext-Element-method-scrollIntoView'> /**
  48. </span> * Scrolls this element into view within the passed container.
  49. * @param {Mixed} container (optional) The container element to scroll (defaults to document.body). Should be a
  50. * string (id), dom node, or Ext.Element.
  51. * @param {Boolean} hscroll (optional) False to disable horizontal scroll (defaults to true)
  52. * @return {Ext.Element} this
  53. */
  54. scrollIntoView : function(container, hscroll) {
  55. var c = Ext.getDom(container) || Ext.getBody().dom,
  56. el = this.dom,
  57. o = this.getOffsetsTo(c),
  58. l = o[0] + c.scrollLeft,
  59. t = o[1] + c.scrollTop,
  60. b = t + el.offsetHeight,
  61. r = l + el.offsetWidth,
  62. ch = c.clientHeight,
  63. ct = parseInt(c.scrollTop, 10),
  64. cl = parseInt(c.scrollLeft, 10),
  65. cb = ct + ch,
  66. cr = cl + c.clientWidth;
  67. if (el.offsetHeight &gt; ch || t &lt; ct) {
  68. c.scrollTop = t;
  69. }
  70. else if (b &gt; cb) {
  71. c.scrollTop = b-ch;
  72. }
  73. // corrects IE, other browsers will ignore
  74. c.scrollTop = c.scrollTop;
  75. if (hscroll !== false) {
  76. if (el.offsetWidth &gt; c.clientWidth || l &lt; cl) {
  77. c.scrollLeft = l;
  78. }
  79. else if (r &gt; cr) {
  80. c.scrollLeft = r - c.clientWidth;
  81. }
  82. c.scrollLeft = c.scrollLeft;
  83. }
  84. return this;
  85. },
  86. // private
  87. scrollChildIntoView : function(child, hscroll) {
  88. Ext.fly(child, '_scrollChildIntoView').scrollIntoView(this, hscroll);
  89. },
  90. <span id='Ext-Element-method-scroll'> /**
  91. </span> * Scrolls this element the specified direction. Does bounds checking to make sure the scroll is
  92. * within this element's scrollable range.
  93. * @param {String} direction Possible values are: &quot;l&quot; (or &quot;left&quot;), &quot;r&quot; (or &quot;right&quot;), &quot;t&quot; (or &quot;top&quot;, or &quot;up&quot;), &quot;b&quot; (or &quot;bottom&quot;, or &quot;down&quot;).
  94. * @param {Number} distance How far to scroll the element in pixels
  95. * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
  96. * @return {Boolean} Returns true if a scroll was triggered or false if the element
  97. * was scrolled as far as it could go.
  98. */
  99. scroll : function(direction, distance, animate) {
  100. if (!this.isScrollable()) {
  101. return false;
  102. }
  103. var el = this.dom,
  104. l = el.scrollLeft, t = el.scrollTop,
  105. w = el.scrollWidth, h = el.scrollHeight,
  106. cw = el.clientWidth, ch = el.clientHeight,
  107. scrolled = false, v,
  108. hash = {
  109. l: Math.min(l + distance, w-cw),
  110. r: v = Math.max(l - distance, 0),
  111. t: Math.max(t - distance, 0),
  112. b: Math.min(t + distance, h-ch)
  113. };
  114. hash.d = hash.b;
  115. hash.u = hash.t;
  116. direction = direction.substr(0, 1);
  117. if ((v = hash[direction]) &gt; -1) {
  118. scrolled = true;
  119. this.scrollTo(direction == 'l' || direction == 'r' ? 'left' : 'top', v, this.preanim(arguments, 2));
  120. }
  121. return scrolled;
  122. }
  123. });</pre>
  124. </body>
  125. </html>