2017-11-03 07:35:25 +00:00
|
|
|
function getScroll (w, top) {
|
|
|
|
let ret = top ? w.pageYOffset : w.pageXOffset
|
|
|
|
const method = top ? 'scrollTop' : 'scrollLeft'
|
2017-11-01 09:03:42 +00:00
|
|
|
if (typeof ret !== 'number') {
|
2017-11-03 07:35:25 +00:00
|
|
|
const d = w.document
|
2017-11-01 09:03:42 +00:00
|
|
|
// ie6,7,8 standard mode
|
2017-11-03 07:35:25 +00:00
|
|
|
ret = d.documentElement[method]
|
2017-11-01 09:03:42 +00:00
|
|
|
if (typeof ret !== 'number') {
|
|
|
|
// quirks mode
|
2017-11-03 07:35:25 +00:00
|
|
|
ret = d.body[method]
|
2017-11-01 09:03:42 +00:00
|
|
|
}
|
|
|
|
}
|
2017-11-03 07:35:25 +00:00
|
|
|
return ret
|
2017-11-01 09:03:42 +00:00
|
|
|
}
|
|
|
|
|
2017-11-03 07:35:25 +00:00
|
|
|
function getClientPosition (elem) {
|
|
|
|
let x
|
|
|
|
let y
|
|
|
|
const doc = elem.ownerDocument
|
|
|
|
const body = doc.body
|
|
|
|
const docElem = doc && doc.documentElement
|
|
|
|
const box = elem.getBoundingClientRect()
|
|
|
|
x = box.left
|
|
|
|
y = box.top
|
|
|
|
x -= docElem.clientLeft || body.clientLeft || 0
|
|
|
|
y -= docElem.clientTop || body.clientTop || 0
|
2017-11-01 09:03:42 +00:00
|
|
|
return {
|
|
|
|
left: x,
|
|
|
|
top: y,
|
2017-11-03 07:35:25 +00:00
|
|
|
}
|
2017-11-01 09:03:42 +00:00
|
|
|
}
|
|
|
|
|
2017-11-09 09:24:00 +00:00
|
|
|
export function getOffsetLeft (el) {
|
2017-11-03 07:35:25 +00:00
|
|
|
const pos = getClientPosition(el)
|
|
|
|
const doc = el.ownerDocument
|
|
|
|
const w = doc.defaultView || doc.parentWindow
|
|
|
|
pos.left += getScroll(w)
|
|
|
|
return pos.left
|
2017-11-01 09:03:42 +00:00
|
|
|
}
|
2017-12-13 09:58:05 +00:00
|
|
|
|
|
|
|
export function deepClone (vnodes, createElement) {
|
|
|
|
function cloneVNode (vnode) {
|
|
|
|
const clonedChildren = vnode.children && vnode.children.map(vnode => cloneVNode(vnode))
|
|
|
|
const cloned = createElement(vnode.tag, vnode.data, clonedChildren)
|
|
|
|
cloned.text = vnode.text
|
|
|
|
cloned.isComment = vnode.isComment
|
|
|
|
cloned.componentOptions = vnode.componentOptions
|
|
|
|
cloned.elm = vnode.elm
|
|
|
|
cloned.context = vnode.context
|
|
|
|
cloned.ns = vnode.ns
|
|
|
|
cloned.isStatic = vnode.isStatic
|
|
|
|
cloned.key = vnode.key
|
|
|
|
|
|
|
|
return cloned
|
|
|
|
}
|
|
|
|
|
|
|
|
const clonedVNodes = vnodes.map(vnode => cloneVNode(vnode))
|
|
|
|
return clonedVNodes
|
|
|
|
}
|