Katochimoto/xblocks

View on GitHub
src/dom/matchesSelector.js

Summary

Maintainability
A
0 mins
Test Coverage
import context from 'context';
import vendor from 'utils/vendor';

const indexOf = Array.prototype.indexOf;
const proto = context.Element.prototype;
const matches = proto.matches ||
    vendor('matchesSelector', proto) ||
    function (selector) {
        return (indexOf.call((this.parentNode || this.ownerDocument).querySelectorAll(selector), this) !== -1);
    };

/**
 * @function xblocks.dom.matchesSelector
 * @param   {[type]} element  [description]
 * @param   {[type]} selector [description]
 * @returns {boolean}
 */
export default function (element, selector) {
    return (element.nodeType === 1 ? matches.call(element, selector) : false);
}