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.
 
 
 
 

68 lines
1.5 KiB

  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.buffer = buffer;
  6. exports.isSamePoint = isSamePoint;
  7. exports.isWindow = isWindow;
  8. exports.isSimilarValue = isSimilarValue;
  9. exports.restoreFocus = restoreFocus;
  10. var _contains = require('rc-util/lib/Dom/contains');
  11. var _contains2 = _interopRequireDefault(_contains);
  12. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  13. function buffer(fn, ms) {
  14. var timer = void 0;
  15. function clear() {
  16. if (timer) {
  17. clearTimeout(timer);
  18. timer = null;
  19. }
  20. }
  21. function bufferFn() {
  22. clear();
  23. timer = setTimeout(fn, ms);
  24. }
  25. bufferFn.clear = clear;
  26. return bufferFn;
  27. }
  28. function isSamePoint(prev, next) {
  29. if (prev === next) return true;
  30. if (!prev || !next) return false;
  31. if ('pageX' in next && 'pageY' in next) {
  32. return prev.pageX === next.pageX && prev.pageY === next.pageY;
  33. }
  34. if ('clientX' in next && 'clientY' in next) {
  35. return prev.clientX === next.clientX && prev.clientY === next.clientY;
  36. }
  37. return false;
  38. }
  39. function isWindow(obj) {
  40. return obj && typeof obj === 'object' && obj.window === obj;
  41. }
  42. function isSimilarValue(val1, val2) {
  43. var int1 = Math.floor(val1);
  44. var int2 = Math.floor(val2);
  45. return Math.abs(int1 - int2) <= 1;
  46. }
  47. function restoreFocus(activeElement, container) {
  48. // Focus back if is in the container
  49. if (activeElement !== document.activeElement && (0, _contains2['default'])(container, activeElement)) {
  50. activeElement.focus();
  51. }
  52. }