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.

520 lines
20 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-layout-boxOverflow-Scroller'>/**
  19. </span> * @class Ext.layout.boxOverflow.Scroller
  20. * @extends Ext.layout.boxOverflow.None
  21. * Description
  22. */
  23. Ext.layout.boxOverflow.Scroller = Ext.extend(Ext.layout.boxOverflow.None, {
  24. <span id='Ext-layout-boxOverflow-Scroller-property-animateScroll'> /**
  25. </span> * @cfg animateScroll
  26. * @type Boolean
  27. * True to animate the scrolling of items within the layout (defaults to true, ignored if enableScroll is false)
  28. */
  29. animateScroll: true,
  30. <span id='Ext-layout-boxOverflow-Scroller-property-scrollIncrement'> /**
  31. </span> * @cfg scrollIncrement
  32. * @type Number
  33. * The number of pixels to scroll by on scroller click (defaults to 100)
  34. */
  35. scrollIncrement: 100,
  36. <span id='Ext-layout-boxOverflow-Scroller-property-wheelIncrement'> /**
  37. </span> * @cfg wheelIncrement
  38. * @type Number
  39. * The number of pixels to increment on mouse wheel scrolling (defaults to &lt;tt&gt;3&lt;/tt&gt;).
  40. */
  41. wheelIncrement: 3,
  42. <span id='Ext-layout-boxOverflow-Scroller-property-scrollRepeatInterval'> /**
  43. </span> * @cfg scrollRepeatInterval
  44. * @type Number
  45. * Number of milliseconds between each scroll while a scroller button is held down (defaults to 400)
  46. */
  47. scrollRepeatInterval: 400,
  48. <span id='Ext-layout-boxOverflow-Scroller-property-scrollDuration'> /**
  49. </span> * @cfg scrollDuration
  50. * @type Number
  51. * Number of seconds that each scroll animation lasts (defaults to 0.4)
  52. */
  53. scrollDuration: 0.4,
  54. <span id='Ext-layout-boxOverflow-Scroller-property-beforeCls'> /**
  55. </span> * @cfg beforeCls
  56. * @type String
  57. * CSS class added to the beforeCt element. This is the element that holds any special items such as scrollers,
  58. * which must always be present at the leftmost edge of the Container
  59. */
  60. beforeCls: 'x-strip-left',
  61. <span id='Ext-layout-boxOverflow-Scroller-property-afterCls'> /**
  62. </span> * @cfg afterCls
  63. * @type String
  64. * CSS class added to the afterCt element. This is the element that holds any special items such as scrollers,
  65. * which must always be present at the rightmost edge of the Container
  66. */
  67. afterCls: 'x-strip-right',
  68. <span id='Ext-layout-boxOverflow-Scroller-property-scrollerCls'> /**
  69. </span> * @cfg scrollerCls
  70. * @type String
  71. * CSS class added to both scroller elements if enableScroll is used
  72. */
  73. scrollerCls: 'x-strip-scroller',
  74. <span id='Ext-layout-boxOverflow-Scroller-property-beforeScrollerCls'> /**
  75. </span> * @cfg beforeScrollerCls
  76. * @type String
  77. * CSS class added to the left scroller element if enableScroll is used
  78. */
  79. beforeScrollerCls: 'x-strip-scroller-left',
  80. <span id='Ext-layout-boxOverflow-Scroller-property-afterScrollerCls'> /**
  81. </span> * @cfg afterScrollerCls
  82. * @type String
  83. * CSS class added to the right scroller element if enableScroll is used
  84. */
  85. afterScrollerCls: 'x-strip-scroller-right',
  86. <span id='Ext-layout-boxOverflow-Scroller-method-createWheelListener'> /**
  87. </span> * @private
  88. * Sets up an listener to scroll on the layout's innerCt mousewheel event
  89. */
  90. createWheelListener: function() {
  91. this.layout.innerCt.on({
  92. scope : this,
  93. mousewheel: function(e) {
  94. e.stopEvent();
  95. this.scrollBy(e.getWheelDelta() * this.wheelIncrement * -1, false);
  96. }
  97. });
  98. },
  99. <span id='Ext-layout-boxOverflow-Scroller-method-handleOverflow'> /**
  100. </span> * @private
  101. * Most of the heavy lifting is done in the subclasses
  102. */
  103. handleOverflow: function(calculations, targetSize) {
  104. this.createInnerElements();
  105. this.showScrollers();
  106. },
  107. <span id='Ext-layout-boxOverflow-Scroller-method-clearOverflow'> /**
  108. </span> * @private
  109. */
  110. clearOverflow: function() {
  111. this.hideScrollers();
  112. },
  113. <span id='Ext-layout-boxOverflow-Scroller-method-showScrollers'> /**
  114. </span> * @private
  115. * Shows the scroller elements in the beforeCt and afterCt. Creates the scrollers first if they are not already
  116. * present.
  117. */
  118. showScrollers: function() {
  119. this.createScrollers();
  120. this.beforeScroller.show();
  121. this.afterScroller.show();
  122. this.updateScrollButtons();
  123. },
  124. <span id='Ext-layout-boxOverflow-Scroller-method-hideScrollers'> /**
  125. </span> * @private
  126. * Hides the scroller elements in the beforeCt and afterCt
  127. */
  128. hideScrollers: function() {
  129. if (this.beforeScroller != undefined) {
  130. this.beforeScroller.hide();
  131. this.afterScroller.hide();
  132. }
  133. },
  134. <span id='Ext-layout-boxOverflow-Scroller-method-createScrollers'> /**
  135. </span> * @private
  136. * Creates the clickable scroller elements and places them into the beforeCt and afterCt
  137. */
  138. createScrollers: function() {
  139. if (!this.beforeScroller &amp;&amp; !this.afterScroller) {
  140. var before = this.beforeCt.createChild({
  141. cls: String.format(&quot;{0} {1} &quot;, this.scrollerCls, this.beforeScrollerCls)
  142. });
  143. var after = this.afterCt.createChild({
  144. cls: String.format(&quot;{0} {1}&quot;, this.scrollerCls, this.afterScrollerCls)
  145. });
  146. before.addClassOnOver(this.beforeScrollerCls + '-hover');
  147. after.addClassOnOver(this.afterScrollerCls + '-hover');
  148. before.setVisibilityMode(Ext.Element.DISPLAY);
  149. after.setVisibilityMode(Ext.Element.DISPLAY);
  150. this.beforeRepeater = new Ext.util.ClickRepeater(before, {
  151. interval: this.scrollRepeatInterval,
  152. handler : this.scrollLeft,
  153. scope : this
  154. });
  155. this.afterRepeater = new Ext.util.ClickRepeater(after, {
  156. interval: this.scrollRepeatInterval,
  157. handler : this.scrollRight,
  158. scope : this
  159. });
  160. <span id='Ext-layout-boxOverflow-Scroller-property-beforeScroller'> /**
  161. </span> * @property beforeScroller
  162. * @type Ext.Element
  163. * The left scroller element. Only created when needed.
  164. */
  165. this.beforeScroller = before;
  166. <span id='Ext-layout-boxOverflow-Scroller-property-afterScroller'> /**
  167. </span> * @property afterScroller
  168. * @type Ext.Element
  169. * The left scroller element. Only created when needed.
  170. */
  171. this.afterScroller = after;
  172. }
  173. },
  174. <span id='Ext-layout-boxOverflow-Scroller-method-destroy'> /**
  175. </span> * @private
  176. */
  177. destroy: function() {
  178. Ext.destroy(this.beforeScroller, this.afterScroller, this.beforeRepeater, this.afterRepeater, this.beforeCt, this.afterCt);
  179. },
  180. <span id='Ext-layout-boxOverflow-Scroller-method-scrollBy'> /**
  181. </span> * @private
  182. * Scrolls left or right by the number of pixels specified
  183. * @param {Number} delta Number of pixels to scroll to the right by. Use a negative number to scroll left
  184. */
  185. scrollBy: function(delta, animate) {
  186. this.scrollTo(this.getScrollPosition() + delta, animate);
  187. },
  188. <span id='Ext-layout-boxOverflow-Scroller-method-getItem'> /**
  189. </span> * @private
  190. * Normalizes an item reference, string id or numerical index into a reference to the item
  191. * @param {Ext.Component|String|Number} item The item reference, id or index
  192. * @return {Ext.Component} The item
  193. */
  194. getItem: function(item) {
  195. if (Ext.isString(item)) {
  196. item = Ext.getCmp(item);
  197. } else if (Ext.isNumber(item)) {
  198. item = this.items[item];
  199. }
  200. return item;
  201. },
  202. <span id='Ext-layout-boxOverflow-Scroller-method-getScrollAnim'> /**
  203. </span> * @private
  204. * @return {Object} Object passed to scrollTo when scrolling
  205. */
  206. getScrollAnim: function() {
  207. return {
  208. duration: this.scrollDuration,
  209. callback: this.updateScrollButtons,
  210. scope : this
  211. };
  212. },
  213. <span id='Ext-layout-boxOverflow-Scroller-method-updateScrollButtons'> /**
  214. </span> * @private
  215. * Enables or disables each scroller button based on the current scroll position
  216. */
  217. updateScrollButtons: function() {
  218. if (this.beforeScroller == undefined || this.afterScroller == undefined) {
  219. return;
  220. }
  221. var beforeMeth = this.atExtremeBefore() ? 'addClass' : 'removeClass',
  222. afterMeth = this.atExtremeAfter() ? 'addClass' : 'removeClass',
  223. beforeCls = this.beforeScrollerCls + '-disabled',
  224. afterCls = this.afterScrollerCls + '-disabled';
  225. this.beforeScroller[beforeMeth](beforeCls);
  226. this.afterScroller[afterMeth](afterCls);
  227. this.scrolling = false;
  228. },
  229. <span id='Ext-layout-boxOverflow-Scroller-method-atExtremeBefore'> /**
  230. </span> * @private
  231. * Returns true if the innerCt scroll is already at its left-most point
  232. * @return {Boolean} True if already at furthest left point
  233. */
  234. atExtremeBefore: function() {
  235. return this.getScrollPosition() === 0;
  236. },
  237. <span id='Ext-layout-boxOverflow-Scroller-method-scrollLeft'> /**
  238. </span> * @private
  239. * Scrolls to the left by the configured amount
  240. */
  241. scrollLeft: function(animate) {
  242. this.scrollBy(-this.scrollIncrement, animate);
  243. },
  244. <span id='Ext-layout-boxOverflow-Scroller-method-scrollRight'> /**
  245. </span> * @private
  246. * Scrolls to the right by the configured amount
  247. */
  248. scrollRight: function(animate) {
  249. this.scrollBy(this.scrollIncrement, animate);
  250. },
  251. <span id='Ext-layout-boxOverflow-Scroller-method-scrollToItem'> /**
  252. </span> * Scrolls to the given component.
  253. * @param {String|Number|Ext.Component} item The item to scroll to. Can be a numerical index, component id
  254. * or a reference to the component itself.
  255. * @param {Boolean} animate True to animate the scrolling
  256. */
  257. scrollToItem: function(item, animate) {
  258. item = this.getItem(item);
  259. if (item != undefined) {
  260. var visibility = this.getItemVisibility(item);
  261. if (!visibility.fullyVisible) {
  262. var box = item.getBox(true, true),
  263. newX = box.x;
  264. if (visibility.hiddenRight) {
  265. newX -= (this.layout.innerCt.getWidth() - box.width);
  266. }
  267. this.scrollTo(newX, animate);
  268. }
  269. }
  270. },
  271. <span id='Ext-layout-boxOverflow-Scroller-method-getItemVisibility'> /**
  272. </span> * @private
  273. * For a given item in the container, return an object with information on whether the item is visible
  274. * with the current innerCt scroll value.
  275. * @param {Ext.Component} item The item
  276. * @return {Object} Values for fullyVisible, hiddenLeft and hiddenRight
  277. */
  278. getItemVisibility: function(item) {
  279. var box = this.getItem(item).getBox(true, true),
  280. itemLeft = box.x,
  281. itemRight = box.x + box.width,
  282. scrollLeft = this.getScrollPosition(),
  283. scrollRight = this.layout.innerCt.getWidth() + scrollLeft;
  284. return {
  285. hiddenLeft : itemLeft &lt; scrollLeft,
  286. hiddenRight : itemRight &gt; scrollRight,
  287. fullyVisible: itemLeft &gt; scrollLeft &amp;&amp; itemRight &lt; scrollRight
  288. };
  289. }
  290. });
  291. Ext.layout.boxOverflow.scroller = Ext.layout.boxOverflow.Scroller;
  292. <span id='Ext-layout-boxOverflow-VerticalScroller'>/**
  293. </span> * @class Ext.layout.boxOverflow.VerticalScroller
  294. * @extends Ext.layout.boxOverflow.Scroller
  295. * Description
  296. */
  297. Ext.layout.boxOverflow.VerticalScroller = Ext.extend(Ext.layout.boxOverflow.Scroller, {
  298. <span id='Ext-layout-boxOverflow-VerticalScroller-property-scrollIncrement'> scrollIncrement: 75,
  299. </span><span id='Ext-layout-boxOverflow-VerticalScroller-property-wheelIncrement'> wheelIncrement : 2,
  300. </span>
  301. <span id='Ext-layout-boxOverflow-VerticalScroller-method-handleOverflow'> handleOverflow: function(calculations, targetSize) {
  302. </span> Ext.layout.boxOverflow.VerticalScroller.superclass.handleOverflow.apply(this, arguments);
  303. return {
  304. targetSize: {
  305. height: targetSize.height - (this.beforeCt.getHeight() + this.afterCt.getHeight()),
  306. width : targetSize.width
  307. }
  308. };
  309. },
  310. <span id='Ext-layout-boxOverflow-VerticalScroller-method-createInnerElements'> /**
  311. </span> * @private
  312. * Creates the beforeCt and afterCt elements if they have not already been created
  313. */
  314. createInnerElements: function() {
  315. var target = this.layout.innerCt;
  316. //normal items will be rendered to the innerCt. beforeCt and afterCt allow for fixed positioning of
  317. //special items such as scrollers or dropdown menu triggers
  318. if (!this.beforeCt) {
  319. this.beforeCt = target.insertSibling({cls: this.beforeCls}, 'before');
  320. this.afterCt = target.insertSibling({cls: this.afterCls}, 'after');
  321. this.createWheelListener();
  322. }
  323. },
  324. <span id='Ext-layout-boxOverflow-VerticalScroller-method-scrollTo'> /**
  325. </span> * @private
  326. * Scrolls to the given position. Performs bounds checking.
  327. * @param {Number} position The position to scroll to. This is constrained.
  328. * @param {Boolean} animate True to animate. If undefined, falls back to value of this.animateScroll
  329. */
  330. scrollTo: function(position, animate) {
  331. var oldPosition = this.getScrollPosition(),
  332. newPosition = position.constrain(0, this.getMaxScrollBottom());
  333. if (newPosition != oldPosition &amp;&amp; !this.scrolling) {
  334. if (animate == undefined) {
  335. animate = this.animateScroll;
  336. }
  337. this.layout.innerCt.scrollTo('top', newPosition, animate ? this.getScrollAnim() : false);
  338. if (animate) {
  339. this.scrolling = true;
  340. } else {
  341. this.scrolling = false;
  342. this.updateScrollButtons();
  343. }
  344. }
  345. },
  346. <span id='Ext-layout-boxOverflow-VerticalScroller-method-getScrollPosition'> /**
  347. </span> * Returns the current scroll position of the innerCt element
  348. * @return {Number} The current scroll position
  349. */
  350. getScrollPosition: function(){
  351. return parseInt(this.layout.innerCt.dom.scrollTop, 10) || 0;
  352. },
  353. <span id='Ext-layout-boxOverflow-VerticalScroller-method-getMaxScrollBottom'> /**
  354. </span> * @private
  355. * Returns the maximum value we can scrollTo
  356. * @return {Number} The max scroll value
  357. */
  358. getMaxScrollBottom: function() {
  359. return this.layout.innerCt.dom.scrollHeight - this.layout.innerCt.getHeight();
  360. },
  361. <span id='Ext-layout-boxOverflow-VerticalScroller-method-atExtremeAfter'> /**
  362. </span> * @private
  363. * Returns true if the innerCt scroll is already at its right-most point
  364. * @return {Boolean} True if already at furthest right point
  365. */
  366. atExtremeAfter: function() {
  367. return this.getScrollPosition() &gt;= this.getMaxScrollBottom();
  368. }
  369. });
  370. Ext.layout.boxOverflow.scroller.vbox = Ext.layout.boxOverflow.VerticalScroller;
  371. <span id='Ext-layout-boxOverflow-HorizontalScroller'>/**
  372. </span> * @class Ext.layout.boxOverflow.HorizontalScroller
  373. * @extends Ext.layout.boxOverflow.Scroller
  374. * Description
  375. */
  376. Ext.layout.boxOverflow.HorizontalScroller = Ext.extend(Ext.layout.boxOverflow.Scroller, {
  377. <span id='Ext-layout-boxOverflow-HorizontalScroller-method-handleOverflow'> handleOverflow: function(calculations, targetSize) {
  378. </span> Ext.layout.boxOverflow.HorizontalScroller.superclass.handleOverflow.apply(this, arguments);
  379. return {
  380. targetSize: {
  381. height: targetSize.height,
  382. width : targetSize.width - (this.beforeCt.getWidth() + this.afterCt.getWidth())
  383. }
  384. };
  385. },
  386. <span id='Ext-layout-boxOverflow-HorizontalScroller-method-createInnerElements'> /**
  387. </span> * @private
  388. * Creates the beforeCt and afterCt elements if they have not already been created
  389. */
  390. createInnerElements: function() {
  391. var target = this.layout.innerCt;
  392. //normal items will be rendered to the innerCt. beforeCt and afterCt allow for fixed positioning of
  393. //special items such as scrollers or dropdown menu triggers
  394. if (!this.beforeCt) {
  395. this.afterCt = target.insertSibling({cls: this.afterCls}, 'before');
  396. this.beforeCt = target.insertSibling({cls: this.beforeCls}, 'before');
  397. this.createWheelListener();
  398. }
  399. },
  400. <span id='Ext-layout-boxOverflow-HorizontalScroller-method-scrollTo'> /**
  401. </span> * @private
  402. * Scrolls to the given position. Performs bounds checking.
  403. * @param {Number} position The position to scroll to. This is constrained.
  404. * @param {Boolean} animate True to animate. If undefined, falls back to value of this.animateScroll
  405. */
  406. scrollTo: function(position, animate) {
  407. var oldPosition = this.getScrollPosition(),
  408. newPosition = position.constrain(0, this.getMaxScrollRight());
  409. if (newPosition != oldPosition &amp;&amp; !this.scrolling) {
  410. if (animate == undefined) {
  411. animate = this.animateScroll;
  412. }
  413. this.layout.innerCt.scrollTo('left', newPosition, animate ? this.getScrollAnim() : false);
  414. if (animate) {
  415. this.scrolling = true;
  416. } else {
  417. this.scrolling = false;
  418. this.updateScrollButtons();
  419. }
  420. }
  421. },
  422. <span id='Ext-layout-boxOverflow-HorizontalScroller-method-getScrollPosition'> /**
  423. </span> * Returns the current scroll position of the innerCt element
  424. * @return {Number} The current scroll position
  425. */
  426. getScrollPosition: function(){
  427. return parseInt(this.layout.innerCt.dom.scrollLeft, 10) || 0;
  428. },
  429. <span id='Ext-layout-boxOverflow-HorizontalScroller-method-getMaxScrollRight'> /**
  430. </span> * @private
  431. * Returns the maximum value we can scrollTo
  432. * @return {Number} The max scroll value
  433. */
  434. getMaxScrollRight: function() {
  435. return this.layout.innerCt.dom.scrollWidth - this.layout.innerCt.getWidth();
  436. },
  437. <span id='Ext-layout-boxOverflow-HorizontalScroller-method-atExtremeAfter'> /**
  438. </span> * @private
  439. * Returns true if the innerCt scroll is already at its right-most point
  440. * @return {Boolean} True if already at furthest right point
  441. */
  442. atExtremeAfter: function() {
  443. return this.getScrollPosition() &gt;= this.getMaxScrollRight();
  444. }
  445. });
  446. Ext.layout.boxOverflow.scroller.hbox = Ext.layout.boxOverflow.HorizontalScroller;</pre>
  447. </body>
  448. </html>