Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

53 linhas
1.1 KiB

  1. import contains from 'rc-util/es/Dom/contains';
  2. export function buffer(fn, ms) {
  3. var timer = void 0;
  4. function clear() {
  5. if (timer) {
  6. clearTimeout(timer);
  7. timer = null;
  8. }
  9. }
  10. function bufferFn() {
  11. clear();
  12. timer = setTimeout(fn, ms);
  13. }
  14. bufferFn.clear = clear;
  15. return bufferFn;
  16. }
  17. export function isSamePoint(prev, next) {
  18. if (prev === next) return true;
  19. if (!prev || !next) return false;
  20. if ('pageX' in next && 'pageY' in next) {
  21. return prev.pageX === next.pageX && prev.pageY === next.pageY;
  22. }
  23. if ('clientX' in next && 'clientY' in next) {
  24. return prev.clientX === next.clientX && prev.clientY === next.clientY;
  25. }
  26. return false;
  27. }
  28. export function isWindow(obj) {
  29. return obj && typeof obj === 'object' && obj.window === obj;
  30. }
  31. export function isSimilarValue(val1, val2) {
  32. var int1 = Math.floor(val1);
  33. var int2 = Math.floor(val2);
  34. return Math.abs(int1 - int2) <= 1;
  35. }
  36. export function restoreFocus(activeElement, container) {
  37. // Focus back if is in the container
  38. if (activeElement !== document.activeElement && contains(container, activeElement)) {
  39. activeElement.focus();
  40. }
  41. }