function getParents(el, parentSelector) {
if (parentSelector === undefined) {
parentSelector = document
}
var parents = []
var p = el.parentNode
while (p !== parentSelector) {
var o = p
parents.push(o)
p = o.parentNode
}
parents.push(parentSelector)
return parents
}
var a = getParents(e.target)
function getParents(elem, callback) {
let parents = []
let parent = elem.parentNode
let index = 0
if (typeof callback !== 'function') {
callback = null
}
while (parent && parent !== document) {
if (callback) {
if (callback(parent, index, elem)) {
parents.push(parent)
}
} else {
parents.push(parent)
}
index++
parent = parent.parentNode
}
return parents
}
var getParentsBak = function (elem, selector) {
if (!Element.prototype.matches) {
Element.prototype.matches =
Element.prototype.matchesSelector ||
Element.prototype.mozMatchesSelector ||
Element.prototype.msMatchesSelector ||
Element.prototype.oMatchesSelector ||
Element.prototype.webkitMatchesSelector ||
function (s) {
var matches = (this.document || this.ownerDocument).querySelectorAll(s),
i = matches.length
while (--i >= 0 && matches.item(i) !== this) {}
return i > -1
}
}
var parents = []
for (; elem && elem !== document; elem = elem.parentNode) {
if (selector) {
if (elem.matches(selector)) {
parents.push(elem)
}
continue
}
parents.push(elem)
}
return parents
}