update vc-align to 2.4.5
parent
508bc33cfa
commit
0eef790e6b
|
@ -1,7 +1,7 @@
|
|||
import PropTypes from '../_util/vue-types';
|
||||
import { alignElement, alignPoint } from 'dom-align';
|
||||
import addEventListener from '../_util/Dom/addEventListener';
|
||||
import { isWindow, buffer, isSamePoint } from './util';
|
||||
import { isWindow, buffer, isSamePoint, isSimilarValue, restoreFocus } from './util';
|
||||
import { cloneElement } from '../_util/vnode.js';
|
||||
import clonedeep from 'lodash/cloneDeep';
|
||||
import { getSlot } from '../_util/props-util';
|
||||
|
@ -73,7 +73,7 @@ export default {
|
|||
if (
|
||||
!reAlign &&
|
||||
source &&
|
||||
(preRect.width !== sourceRect.width || preRect.height !== sourceRect.height)
|
||||
(!isSimilarValue(preRect.width, sourceRect.width) || !isSimilarValue(preRect.height, sourceRect.height))
|
||||
) {
|
||||
reAlign = true;
|
||||
}
|
||||
|
@ -121,11 +121,16 @@ export default {
|
|||
const element = getElement(target);
|
||||
const point = getPoint(target);
|
||||
|
||||
// IE lose focus after element realign
|
||||
// We should record activeElement and restore later
|
||||
const activeElement = document.activeElement;
|
||||
|
||||
if (element) {
|
||||
result = alignElement(source, element, align);
|
||||
} else if (point) {
|
||||
result = alignPoint(source, point, align);
|
||||
}
|
||||
restoreFocus(activeElement, source);
|
||||
this.aligned = true;
|
||||
this.$listeners.align && this.$listeners.align(source, result);
|
||||
}
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
// based on vc-align 2.4.3
|
||||
// based on vc-align 2.4.5
|
||||
import Align from './Align';
|
||||
export default Align;
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import contains from '../_util/Dom/contains';
|
||||
export function buffer(fn, ms) {
|
||||
let timer;
|
||||
|
||||
|
@ -36,3 +37,19 @@ export function isSamePoint(prev, next) {
|
|||
export function isWindow(obj) {
|
||||
return obj && typeof obj === 'object' && obj.window === obj;
|
||||
}
|
||||
|
||||
export function isSimilarValue(val1, val2) {
|
||||
const int1 = Math.floor(val1);
|
||||
const int2 = Math.floor(val2);
|
||||
return Math.abs(int1 - int2) <= 1;
|
||||
}
|
||||
|
||||
export function restoreFocus(activeElement, container) {
|
||||
// Focus back if is in the container
|
||||
if (
|
||||
activeElement !== document.activeElement &&
|
||||
contains(container, activeElement)
|
||||
) {
|
||||
activeElement.focus();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue