12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- 'use strict';
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- var _typeof2 = require('babel-runtime/helpers/typeof');
- var _typeof3 = _interopRequireDefault(_typeof2);
- exports.buffer = buffer;
- exports.isSamePoint = isSamePoint;
- exports.isWindow = isWindow;
- exports.isSimilarValue = isSimilarValue;
- exports.restoreFocus = restoreFocus;
- var _contains = require('../vc-util/Dom/contains');
- var _contains2 = _interopRequireDefault(_contains);
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
- function buffer(fn, ms) {
- var timer = void 0;
- function clear() {
- if (timer) {
- clearTimeout(timer);
- timer = null;
- }
- }
- function bufferFn() {
- clear();
- timer = setTimeout(fn, ms);
- }
- bufferFn.clear = clear;
- return bufferFn;
- }
- function isSamePoint(prev, next) {
- if (prev === next) return true;
- if (!prev || !next) return false;
- if ('pageX' in next && 'pageY' in next) {
- return prev.pageX === next.pageX && prev.pageY === next.pageY;
- }
- if ('clientX' in next && 'clientY' in next) {
- return prev.clientX === next.clientX && prev.clientY === next.clientY;
- }
- return false;
- }
- function isWindow(obj) {
- return obj && (typeof obj === 'undefined' ? 'undefined' : (0, _typeof3['default'])(obj)) === 'object' && obj.window === obj;
- }
- function isSimilarValue(val1, val2) {
- var int1 = Math.floor(val1);
- var int2 = Math.floor(val2);
- return Math.abs(int1 - int2) <= 1;
- }
- function restoreFocus(activeElement, container) {
- // Focus back if is in the container
- if (activeElement !== document.activeElement && (0, _contains2['default'])(container, activeElement)) {
- activeElement.focus();
- }
- }
|