touchPolyfill.ts 1.0 KB

123456789101112131415161718192021222324252627282930
  1. import warning from './warning';
  2. const touchEventPolyfill = (touch: any, touchEvent: any) => {
  3. /* Touch is the first point of multi-touch. In order to minimize the change of slider code to support touch,
  4. some methods that will be used on touchEvent are mounted on the multi-touch Touch object.*/
  5. // polyfill for firefox
  6. if (!globalThis.Touch || (!(touch instanceof Touch))) {
  7. return touch;
  8. }
  9. const keysNeedPolyfill = ['stopPropagation', 'preventDefault'];
  10. keysNeedPolyfill.forEach(key => {
  11. let value = touchEvent[key];
  12. if (value) {
  13. if (typeof value === 'function') {
  14. // bind 'this' for function of touchEvent running in Touch Point Object
  15. value = (...args: any) => touchEvent[key](...args);
  16. }
  17. if (touch[key]) {
  18. warning(true, `"The key ${key}" exist in Touch.`);
  19. } else {
  20. touch[key] = value;
  21. }
  22. }
  23. });
  24. return touch;
  25. };
  26. export default touchEventPolyfill;