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.

226 lines
8.0 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
2 years ago
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
2 years ago
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
2 years ago
​
2 years ago
2 years ago
​
2 years ago
2 years ago
​
2 years ago
2 years ago
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
2 years ago
​
​
​
​
​
​
​
2 years ago
​
​
​
​
2 years ago
​
​
​
​
​
​
​
2 years ago
​
​
​
​
2 years ago
​
​
​
​
​
2 years ago
​
​
​
​
2 years ago
​
​
​
​
2 years ago
​
​
​
​
2 years ago
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
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-dd-ScrollManager'>/**
  19. </span> * @class Ext.dd.ScrollManager
  20. * &lt;p&gt;Provides automatic scrolling of overflow regions in the page during drag operations.&lt;/p&gt;
  21. * &lt;p&gt;The ScrollManager configs will be used as the defaults for any scroll container registered with it,
  22. * but you can also override most of the configs per scroll container by adding a
  23. * &lt;tt&gt;ddScrollConfig&lt;/tt&gt; object to the target element that contains these properties: {@link #hthresh},
  24. * {@link #vthresh}, {@link #increment} and {@link #frequency}. Example usage:
  25. * &lt;pre&gt;&lt;code&gt;
  26. var el = Ext.get('scroll-ct');
  27. el.ddScrollConfig = {
  28. vthresh: 50,
  29. hthresh: -1,
  30. frequency: 100,
  31. increment: 200
  32. };
  33. Ext.dd.ScrollManager.register(el);
  34. &lt;/code&gt;&lt;/pre&gt;
  35. * &lt;b&gt;Note: This class uses &quot;Point Mode&quot; and is untested in &quot;Intersect Mode&quot;.&lt;/b&gt;
  36. * @singleton
  37. */
  38. Ext.dd.ScrollManager = function(){
  39. var ddm = Ext.dd.DragDropMgr;
  40. var els = {};
  41. var dragEl = null;
  42. var proc = {};
  43. var onStop = function(e){
  44. dragEl = null;
  45. clearProc();
  46. };
  47. var triggerRefresh = function(){
  48. if(ddm.dragCurrent){
  49. ddm.refreshCache(ddm.dragCurrent.groups);
  50. }
  51. };
  52. var doScroll = function(){
  53. if(ddm.dragCurrent){
  54. var dds = Ext.dd.ScrollManager;
  55. var inc = proc.el.ddScrollConfig ?
  56. proc.el.ddScrollConfig.increment : dds.increment;
  57. if(!dds.animate){
  58. if(proc.el.scroll(proc.dir, inc)){
  59. triggerRefresh();
  60. }
  61. }else{
  62. proc.el.scroll(proc.dir, inc, true, dds.animDuration, triggerRefresh);
  63. }
  64. }
  65. };
  66. var clearProc = function(){
  67. if(proc.id){
  68. clearInterval(proc.id);
  69. }
  70. proc.id = 0;
  71. proc.el = null;
  72. proc.dir = &quot;&quot;;
  73. };
  74. var startProc = function(el, dir){
  75. clearProc();
  76. proc.el = el;
  77. proc.dir = dir;
  78. var group = el.ddScrollConfig ? el.ddScrollConfig.ddGroup : undefined,
  79. freq = (el.ddScrollConfig &amp;&amp; el.ddScrollConfig.frequency)
  80. ? el.ddScrollConfig.frequency
  81. : Ext.dd.ScrollManager.frequency;
  82. if (group === undefined || ddm.dragCurrent.ddGroup == group) {
  83. proc.id = setInterval(doScroll, freq);
  84. }
  85. };
  86. var onFire = function(e, isDrop){
  87. if(isDrop || !ddm.dragCurrent){ return; }
  88. var dds = Ext.dd.ScrollManager;
  89. if(!dragEl || dragEl != ddm.dragCurrent){
  90. dragEl = ddm.dragCurrent;
  91. // refresh regions on drag start
  92. dds.refreshCache();
  93. }
  94. var xy = Ext.lib.Event.getXY(e);
  95. var pt = new Ext.lib.Point(xy[0], xy[1]);
  96. for(var id in els){
  97. var el = els[id], r = el._region;
  98. var c = el.ddScrollConfig ? el.ddScrollConfig : dds;
  99. if(r &amp;&amp; r.contains(pt) &amp;&amp; el.isScrollable()){
  100. if(r.bottom - pt.y &lt;= c.vthresh){
  101. if(proc.el != el){
  102. startProc(el, &quot;down&quot;);
  103. }
  104. return;
  105. }else if(r.right - pt.x &lt;= c.hthresh){
  106. if(proc.el != el){
  107. startProc(el, &quot;left&quot;);
  108. }
  109. return;
  110. }else if(pt.y - r.top &lt;= c.vthresh){
  111. if(proc.el != el){
  112. startProc(el, &quot;up&quot;);
  113. }
  114. return;
  115. }else if(pt.x - r.left &lt;= c.hthresh){
  116. if(proc.el != el){
  117. startProc(el, &quot;right&quot;);
  118. }
  119. return;
  120. }
  121. }
  122. }
  123. clearProc();
  124. };
  125. ddm.fireEvents = ddm.fireEvents.createSequence(onFire, ddm);
  126. ddm.stopDrag = ddm.stopDrag.createSequence(onStop, ddm);
  127. return {
  128. <span id='Ext-dd-ScrollManager-method-register'> /**
  129. </span> * Registers new overflow element(s) to auto scroll
  130. * @param {Mixed/Array} el The id of or the element to be scrolled or an array of either
  131. */
  132. register : function(el){
  133. if(Ext.isArray(el)){
  134. for(var i = 0, len = el.length; i &lt; len; i++) {
  135. this.register(el[i]);
  136. }
  137. }else{
  138. el = Ext.get(el);
  139. els[el.id] = el;
  140. }
  141. },
  142. <span id='Ext-dd-ScrollManager-method-unregister'> /**
  143. </span> * Unregisters overflow element(s) so they are no longer scrolled
  144. * @param {Mixed/Array} el The id of or the element to be removed or an array of either
  145. */
  146. unregister : function(el){
  147. if(Ext.isArray(el)){
  148. for(var i = 0, len = el.length; i &lt; len; i++) {
  149. this.unregister(el[i]);
  150. }
  151. }else{
  152. el = Ext.get(el);
  153. delete els[el.id];
  154. }
  155. },
  156. <span id='Ext-dd-ScrollManager-property-vthresh'> /**
  157. </span> * The number of pixels from the top or bottom edge of a container the pointer needs to be to
  158. * trigger scrolling (defaults to 25)
  159. * @type Number
  160. */
  161. vthresh : 25,
  162. <span id='Ext-dd-ScrollManager-property-hthresh'> /**
  163. </span> * The number of pixels from the right or left edge of a container the pointer needs to be to
  164. * trigger scrolling (defaults to 25)
  165. * @type Number
  166. */
  167. hthresh : 25,
  168. <span id='Ext-dd-ScrollManager-property-increment'> /**
  169. </span> * The number of pixels to scroll in each scroll increment (defaults to 100)
  170. * @type Number
  171. */
  172. increment : 100,
  173. <span id='Ext-dd-ScrollManager-property-frequency'> /**
  174. </span> * The frequency of scrolls in milliseconds (defaults to 500)
  175. * @type Number
  176. */
  177. frequency : 500,
  178. <span id='Ext-dd-ScrollManager-property-animate'> /**
  179. </span> * True to animate the scroll (defaults to true)
  180. * @type Boolean
  181. */
  182. animate: true,
  183. <span id='Ext-dd-ScrollManager-property-animDuration'> /**
  184. </span> * The animation duration in seconds -
  185. * MUST BE less than Ext.dd.ScrollManager.frequency! (defaults to .4)
  186. * @type Number
  187. */
  188. animDuration: .4,
  189. <span id='Ext-dd-ScrollManager-property-ddGroup'> /**
  190. </span> * The named drag drop {@link Ext.dd.DragSource#ddGroup group} to which this container belongs (defaults to undefined).
  191. * If a ddGroup is specified, then container scrolling will only occur when a dragged object is in the same ddGroup.
  192. * @type String
  193. */
  194. ddGroup: undefined,
  195. <span id='Ext-dd-ScrollManager-method-refreshCache'> /**
  196. </span> * Manually trigger a cache refresh.
  197. */
  198. refreshCache : function(){
  199. for(var id in els){
  200. if(typeof els[id] == 'object'){ // for people extending the object prototype
  201. els[id]._region = els[id].getRegion();
  202. }
  203. }
  204. }
  205. };
  206. }();</pre>
  207. </body>
  208. </html>