scroll.ts 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. // ///<reference path="../../headers/common.d.ts" />
  2. //
  3. // import _ from 'lodash';
  4. //
  5. // var objectAssign = require('object-assign');
  6. // var Emitter = require('tiny-emitter');
  7. // var Lethargy = require('lethargy').Lethargy;
  8. // var support = require('./support');
  9. // var clone = require('./clone');
  10. // var bindAll = require('bindall-standalone');
  11. // var EVT_ID = 'virtualscroll';
  12. //
  13. // var keyCodes = {
  14. // LEFT: 37,
  15. // UP: 38,
  16. // RIGHT: 39,
  17. // DOWN: 40
  18. // };
  19. //
  20. // function VirtualScroll(this: any, options) {
  21. // _.bindAll(this, '_onWheel', '_onMouseWheel', '_onTouchStart', '_onTouchMove', '_onKeyDown');
  22. //
  23. // this.el = window;
  24. // if (options && options.el) {
  25. // this.el = options.el;
  26. // delete options.el;
  27. // }
  28. //
  29. // this.options = _.assign({
  30. // mouseMultiplier: 1,
  31. // touchMultiplier: 2,
  32. // firefoxMultiplier: 15,
  33. // keyStep: 120,
  34. // preventTouch: false,
  35. // unpreventTouchClass: 'vs-touchmove-allowed',
  36. // limitInertia: false
  37. // }, options);
  38. //
  39. // if (this.options.limitInertia) this._lethargy = new Lethargy();
  40. //
  41. // this._emitter = new Emitter();
  42. // this._event = {
  43. // y: 0,
  44. // x: 0,
  45. // deltaX: 0,
  46. // deltaY: 0
  47. // };
  48. //
  49. // this.touchStartX = null;
  50. // this.touchStartY = null;
  51. // this.bodyTouchAction = null;
  52. // }
  53. //
  54. // VirtualScroll.prototype._notify = function(e) {
  55. // var evt = this._event;
  56. // evt.x += evt.deltaX;
  57. // evt.y += evt.deltaY;
  58. //
  59. // this._emitter.emit(EVT_ID, {
  60. // x: evt.x,
  61. // y: evt.y,
  62. // deltaX: evt.deltaX,
  63. // deltaY: evt.deltaY,
  64. // originalEvent: e
  65. // });
  66. // };
  67. //
  68. // VirtualScroll.prototype._onWheel = function(e) {
  69. // var options = this.options;
  70. // if (this._lethargy && this._lethargy.check(e) === false) return;
  71. //
  72. // var evt = this._event;
  73. //
  74. // // In Chrome and in Firefox (at least the new one)
  75. // evt.deltaX = e.wheelDeltaX || e.deltaX * -1;
  76. // evt.deltaY = e.wheelDeltaY || e.deltaY * -1;
  77. //
  78. // // for our purpose deltamode = 1 means user is on a wheel mouse, not touch pad
  79. // // real meaning: https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent#Delta_modes
  80. // if(support.isFirefox && e.deltaMode == 1) {
  81. // evt.deltaX *= options.firefoxMultiplier;
  82. // evt.deltaY *= options.firefoxMultiplier;
  83. // }
  84. //
  85. // evt.deltaX *= options.mouseMultiplier;
  86. // evt.deltaY *= options.mouseMultiplier;
  87. //
  88. // this._notify(e);
  89. // };
  90. //
  91. // VirtualScroll.prototype._onMouseWheel = function(e) {
  92. // if (this.options.limitInertia && this._lethargy.check(e) === false) return;
  93. //
  94. // var evt = this._event;
  95. //
  96. // // In Safari, IE and in Chrome if 'wheel' isn't defined
  97. // evt.deltaX = (e.wheelDeltaX) ? e.wheelDeltaX : 0;
  98. // evt.deltaY = (e.wheelDeltaY) ? e.wheelDeltaY : e.wheelDelta;
  99. //
  100. // this._notify(e);
  101. // };
  102. //
  103. // VirtualScroll.prototype._onTouchStart = function(e) {
  104. // var t = (e.targetTouches) ? e.targetTouches[0] : e;
  105. // this.touchStartX = t.pageX;
  106. // this.touchStartY = t.pageY;
  107. // };
  108. //
  109. // VirtualScroll.prototype._onTouchMove = function(e) {
  110. // var options = this.options;
  111. // if(options.preventTouch
  112. // && !e.target.classList.contains(options.unpreventTouchClass)) {
  113. // e.preventDefault();
  114. // }
  115. //
  116. // var evt = this._event;
  117. //
  118. // var t = (e.targetTouches) ? e.targetTouches[0] : e;
  119. //
  120. // evt.deltaX = (t.pageX - this.touchStartX) * options.touchMultiplier;
  121. // evt.deltaY = (t.pageY - this.touchStartY) * options.touchMultiplier;
  122. //
  123. // this.touchStartX = t.pageX;
  124. // this.touchStartY = t.pageY;
  125. //
  126. // this._notify(e);
  127. // };
  128. //
  129. // VirtualScroll.prototype._onKeyDown = function(e) {
  130. // var evt = this._event;
  131. // evt.deltaX = evt.deltaY = 0;
  132. //
  133. // switch(e.keyCode) {
  134. // case keyCodes.LEFT:
  135. // case keyCodes.UP:
  136. // evt.deltaY = this.options.keyStep;
  137. // break;
  138. //
  139. // case keyCodes.RIGHT:
  140. // case keyCodes.DOWN:
  141. // evt.deltaY = - this.options.keyStep;
  142. // break;
  143. //
  144. // default:
  145. // return;
  146. // }
  147. //
  148. // this._notify(e);
  149. // };
  150. //
  151. // VirtualScroll.prototype._bind = function() {
  152. // if(support.hasWheelEvent) this.el.addEventListener('wheel', this._onWheel);
  153. // if(support.hasMouseWheelEvent) this.el.addEventListener('mousewheel', this._onMouseWheel);
  154. //
  155. // if(support.hasTouch) {
  156. // this.el.addEventListener('touchstart', this._onTouchStart);
  157. // this.el.addEventListener('touchmove', this._onTouchMove);
  158. // }
  159. //
  160. // if(support.hasPointer && support.hasTouchWin) {
  161. // this.bodyTouchAction = document.body.style.msTouchAction;
  162. // document.body.style.msTouchAction = 'none';
  163. // this.el.addEventListener('MSPointerDown', this._onTouchStart, true);
  164. // this.el.addEventListener('MSPointerMove', this._onTouchMove, true);
  165. // }
  166. //
  167. // if(support.hasKeyDown) document.addEventListener('keydown', this._onKeyDown);
  168. // };
  169. //
  170. // VirtualScroll.prototype._unbind = function() {
  171. // if(support.hasWheelEvent) this.el.removeEventListener('wheel', this._onWheel);
  172. // if(support.hasMouseWheelEvent) this.el.removeEventListener('mousewheel', this._onMouseWheel);
  173. //
  174. // if(support.hasTouch) {
  175. // this.el.removeEventListener('touchstart', this._onTouchStart);
  176. // this.el.removeEventListener('touchmove', this._onTouchMove);
  177. // }
  178. //
  179. // if(support.hasPointer && support.hasTouchWin) {
  180. // document.body.style.msTouchAction = this.bodyTouchAction;
  181. // this.el.removeEventListener('MSPointerDown', this._onTouchStart, true);
  182. // this.el.removeEventListener('MSPointerMove', this._onTouchMove, true);
  183. // }
  184. //
  185. // if(support.hasKeyDown) document.removeEventListener('keydown', this._onKeyDown);
  186. // };
  187. //
  188. // VirtualScroll.prototype.on = function(cb, ctx) {
  189. // this._emitter.on(EVT_ID, cb, ctx);
  190. //
  191. // var events = this._emitter.e;
  192. // if (events && events[EVT_ID] && events[EVT_ID].length === 1) this._bind();
  193. // };
  194. //
  195. // VirtualScroll.prototype.off = function(cb, ctx) {
  196. // this._emitter.off(EVT_ID, cb, ctx);
  197. //
  198. // var events = this._emitter.e;
  199. // if (!events[EVT_ID] || events[EVT_ID].length <= 0) this._unbind();
  200. // };
  201. //
  202. // VirtualScroll.prototype.reset = function() {
  203. // var evt = this._event;
  204. // evt.x = 0;
  205. // evt.y = 0;
  206. // };
  207. //
  208. // VirtualScroll.prototype.destroy = function() {
  209. // this._emitter.off();
  210. // this._unbind();
  211. // };