/**
 * closest.js
 *
 * @Author: jruif
 * @Date: 2017/7/25 下午3:46
 */
if (window.Element && !Element.prototype.closest) {
  Element.prototype.closest = function (s) {
    var matches = (this.document || this.ownerDocument).querySelectorAll(s);
    var i;
    var el = this;

    do {
      el = el.parentElement;
      i = matches.length;

      while (--i >= 0 && matches.item(i) !== el) {}
    } while (i < 0 && el.parentElement);

    return el;
  };
}