UNPKG

@mdui/jq

Version:

拥有和 jQuery 相似 API 的轻量级 JavaScript 工具库

36 lines (35 loc) 1.04 kB
import { $ } from '../$.js'; import { isDocument, isFunction, isString, isWindow, } from '../shared/helper.js'; import './each.js'; // eslint-disable-next-line @typescript-eslint/no-explicit-any $.fn.is = function (selector) { let isMatched = false; if (isFunction(selector)) { this.each((index, element) => { if (selector.call(element, index, element)) { isMatched = true; } }); return isMatched; } if (isString(selector)) { this.each((_, element) => { if (isDocument(element) || isWindow(element)) { return; } if (element.matches.call(element, selector)) { isMatched = true; } }); return isMatched; } const $compareWith = $(selector); this.each((_, element) => { $compareWith.each((_, compare) => { if (element === compare) { isMatched = true; } }); }); return isMatched; };