Ai
3 Star 1 Fork 1

Gitee 极速下载/MojoJS-Query

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/scottcgi/MojoJS-Query
克隆/下载
MojoJS.query.js 40.06 KB
一键复制 编辑 原始数据 按行查看 历史
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052
/*
* Copyright (c) scott.cgi All Rights Reserved.
*
* This source code belongs to project MojocJS-Query, which is a JS CSS Seletor Engine hosted on GitHub,
* and licensed under the MIT License.
*
* License: https://github.com/scottcgi/MojoJS-Query/blob/master/LICENSE
* GitHub : https://github.com/scottcgi/MojoJS-Query
*
* Since : 2009-11-11
* Update : 2019-10-8
* Version: 2.0.0
*/
(function(window) {
var
parser = {
// cache in context
document: window.document,
// cache in context
RegExp : window.RegExp,
// identifies HTMLElement whether matched in one query
tagGuid : 0,
rex: {
// relative
RE_RULE : /[ +>~]/g,
// not relative
NRE_RULE : /[^ +>~]+/g,
TRIM_LR : /^ +| +$/g,
TRIM : / *([^a-zA-Z*.:]) */g,
TRIM_QUOTE: /["']/g,
PSEU_PARAM: /\([^()]+\)/g,
ATTR_PARAM: /[^\[]+(?=\])/g,
ATTR : /[!\^$*|~]?=/,
CLS : /\./g,
PSEU : /[^:]+/g,
NUM : /\d+/,
// css nth
NTH : /(-?\d*)n([+-]?\d*)/,
RULES : /((?:#[^.:\[]+)*)([a-zA-Z*]*)([^\[:]*)((?:\[.+\])*)((?::.+)*)/
},
/**
* Get HTMLElements array by selector and context.
*
* @param {String} selector
* @param {String | HTMLElement | Array<HTMLElement> | NodeList} context (optional)
* @return {Array} matched HTMLElements Array
*/
query: function(selector, context) {
var
contexts, undefined;
switch (typeof context) {
case "string":
selector = context + " " + selector;
// here no break
case "undefined":
contexts = [this.document];
break;
case "object":
if (context.nodeType === 1) {
// HTMLElement
contexts = [context];
} else if (context.length !== undefined) {
// Array or NodeList
contexts = context;
} else {
throw "Type Error: MojoJS.query with wrong object context !";
}
break;
default:
throw "Type Error: MojoJS.query with unsupported context !";
}
return this.parse(this.replaceAttrPseudo(this.trim(selector)).split(","), contexts);
},
/**
* Parse selectors with contexts.
*
* @param {Array} selector
* @param {Array} contexts
* @return {Array} matched HTMLElements array
*/
parse: function(selectors, contexts) {
var
results = [],
relativeFilter = this.relativeFilter,
filterAttr = this.filterAttr,
CLS = this.rex.CLS,
ATTR_PARAM = this.rex.ATTR_PARAM,
PSEU = this.rex.PSEU,
RULES = this.rex.RULES,
RE_RULE = this.rex.RE_RULE,
NRE_RULE = this.rex.NRE_RULE,
reRules, reContexts,
i, j, m, n, k, l,
matched, rules, id, cls, attrs, pseudos;
for (i = 0, j = selectors.length; i < j; ++i) {
// each HTMLElements by css seletor and contextor split by comma
selector = selectors[i];
// relative rule array
// add defalut rule " "
reRules = (" " + selector).match(RE_RULE);
// selector on both sides of relative rule
selector = selector.match(NRE_RULE);
// selector start with relative rule
// remove defalut rule " "
if (reRules.length > selector.length) {
reRules.shift();
}
// contexts for relative rule
reContexts = contexts;
// parse each relative rule
for (n = 0, m = reRules.length; n < m; ++n) {
// [1]: id
// [2]: tag
// [3]: class
// [4]: attribute
// [5]: pseudo
// selector[n]: each on both sides of relative rule
rules = selector[n].match(RULES);
if ((id = rules[1])) {
if ((id = this.document.getElementById(id.substring(1)))) {
matched = [id];
} else {
matched = [];
}
} else {
matched = relativeFilter[reRules[n]](this, reContexts, rules[2] || "*");
if ((cls = rules[3])) {
matched = this.filterClass(matched, cls.replace(CLS, ""));
}
if ((attrs = rules[4])) {
matched = filterAttr(
matched,
this.getAttrRules(attrs.match(ATTR_PARAM), this.attrParams)
);
}
if ((pseudos = rules[5])) {
matched = this.filterPseudo(
matched,
this.getPseudoRules(pseudos.match(PSEU), this.pseudoParams)
);
}
}
// each iteration, use before parse result as this context
reContexts = matched;
}
// concat results of comma delimited selector
for (k = 0, l = reContexts.length; k < l; ++k) {
results.push(reContexts[k]);
}
}
if (j > 1) {
// if here, may hava duplicate HTMLElement
// remove duplicate HTMLElements
return this.makeDiff(results);
}
return results;
},
/**
* Trim extra spaces and quotes.
*
* @param {String} selector
* @return {String} selector without spaces and quotes
*/
trim: function(selector) {
return selector
// trim left and right spaces
.replace(this.rex.TRIM_LR, "")
// trim spaces in selector
.replace(this.rex.TRIM, "$1")
// trim quotes in selector
.replace(this.rex.TRIM_QUOTE, "");
},
/**
* Put attribute and pseudo selector (in "[]" and "()") to array,
* and replace the original string with the array index.
*
* @param {String} selector
* @return {Array} selectors split by comma
*/
replaceAttrPseudo: function(selector) {
var
pseudoParams = [],
attrParams = [],
PSEU_PARAM = this.rex.PSEU_PARAM;
this.pseudoParams = pseudoParams;
this.attrParams = attrParams;
// remove attribute and put in array
selector = selector.replace(this.rex.ATTR_PARAM, function(matched) {
// record the index
return attrParams.push(matched) - 1;
});
// remove pseudo and put in array
while (selector.indexOf("(") !== -1) {
selector = selector.replace(PSEU_PARAM, function(matched) {
// record the index
return pseudoParams.push(matched.substring(1, matched.length - 1)) - 1;
});
}
return selector;
},
/**
* Get all types of rules.
*
* rules[1]: id
* rules[2]: tag
* rules[3]: class
* rules[4]: attribute
* rules[5]: pseudo
*
* @param {String} selector
* @return {Array} rules
*/
getRules: function(selector) {
var
rules, attrs, pseudos;
rules = selector.match(this.rex.RULES);
rules[2] = rules[2] || "*";
rules[3] = rules[3].replace(this.rex.CLS, "");
if ((attrs = rules[4])) {
// attritubte parse rules
rules[4] = this.getAttrRules(attrs.match(this.rex.ATTR_PARAM), this.attrParams);
}
if ((pseudos = rules[5])) {
// pseudo parse rules
rules[5] = this.getPseudoRules(pseudos.match(this.rex.PSEU), this.pseudoParams)
}
return rules;
},
/**
* Get attribute parse rules.
*
* rule[index + 0]: parse function
* rule[index + 1]: attr name
* rule[index + 2]: attr value
*
* @param {Array} attrs
* @param {Array} attrParams
* @return {Array} attribute parse rules
*/
getAttrRules: function(attrs, attrParams) {
var
arr = [],
ATTR = this.rex.ATTR,
RegExp = this.RegExp,
attributeFilter = this.attributeFilter,
len, i, attr;
for (i = 0, len = attrs.length; i < len; ++i) {
attr = attrParams[attrs[i]];
if (ATTR.test(attr)) {
attr = RegExp["$'"];
arr.push(attributeFilter[RegExp["$&"]], RegExp["$`"], attr);
} else {
arr.push(attributeFilter[" "], attr, "");
}
}
return arr;
},
/**
* Get pseudo parse rules.
*
* rule[index + 0]: whether has parameter
* rule[index + 1]: parse function
* rule[index + 2]: parameter
*
* @param {Array} pseudos
* @param {Array} pseudoParams
* @return {Array} pseudo parse rules
*/
getPseudoRules: function(pseudos, pseudoParams) {
var
arr = [],
guid = ++this.tagGuid,
NUM = this.rex.NUM,
RegExp = this.RegExp,
pseudoFilter = this.pseudoFilter,
len, i, pseudo, param;
for (i = 0, len = pseudos.length; i < len; ++i) {
pseudo = pseudos[i];
// pseudo with parameter
if (NUM.test(pseudo)) {
// pseudo filter rule object
pseudo = pseudoFilter[RegExp["$`"]];
// pseudo parameter
param = pseudoParams[RegExp["$&"]];
arr.push(
true,
pseudo.fn,
// if has getFnParam then do with param
pseudo.getFnParam ? pseudo.getFnParam(this, guid, param) : param
);
} else {
arr.push(false, pseudoFilter[pseudo], null);
}
}
return arr;
},
/**
* Filter HTMLElements whether matched pseudo rules.
*
* @param {Array} els
* @param {Array} pseudoRules
* @return {Array} matched HTMLElements array
*/
filterPseudo: function(els, pseudoRules) {
var
pseudoFn, hasParam, nthDataOrParam, matched,
el, eLen, i, pLen, j;
for (j = 0, pLen = pseudoRules.length; j < pLen; j += 3) {
hasParam = pseudoRules[j];
pseudoFn = pseudoRules[j + 1];
nthDataOrParam = pseudoRules[j + 2];
matched = [];
for (i = 0, eLen = els.length; i < eLen; ++i) {
el = els[i];
// pseudoFn write twice for reduce define var
if (hasParam) {
if (pseudoFn(this, el, i, nthDataOrParam) === false) {
continue;
}
} else {
if (pseudoFn(this, el, i, eLen) === false) {
continue;
}
}
matched.push(el);
}
els = matched;
}
return matched;
},
/**
* Filter HTMLElements whether matched attribute rules
*
* @param {Array} els
* @param {Array} attrRules
* @return {Array} matched HTMLElements array
*/
filterAttr: function(els, attrRules) {
var
matched = [],
name, value, rule, el, undefined,
elen, i, aLen, j;
for (i = 0, elen = els.length, aLen = attrRules.length; i < elen; ++i) {
el = els[i];
for (j = 0; j < aLen; j += 3) {
rule = attrRules[j];
name = attrRules[j + 1];
if ((value = el.getAttribute(name)) === null) {
if ((value = el[name]) === undefined) {
break;
}
}
if (rule(value + "", attrRules[j + 2]) === false) {
break;
}
}
if (j === aLen) {
matched.push(el);
}
}
return matched;
},
/**
* Filter HTMLElements whether matched class attribute.
*
* @param {Array} els
* @param {String} cls
* @return {Array} matched HTMLElements array
*/
filterClass: function(els, cls) {
var
matched = [],
RegExp = this.RegExp,
clsName, rex, len, i;
for (i = 0, len = els.length; i < len; ++i) {
el = els[i];
if ((clsName = el.className)) {
rex = new RegExp(clsName.replace(" ", "|"), "g");
if (cls.replace(rex, "") === "") {
matched.push(el);
}
}
}
return matched;
},
/**
* Filter HTMLElement whether matched rules.
*
* @param {HTMLElement} el
* @param {String} tag
* @param {String} cls
* @param {Array} attrRules
* @param {Array} pseudoRules
* @return {Boolean} matched or not
*/
filterEl: function(el, tag, cls, attrRules, pseudoRules) {
if (tag !== "*" && el.nodeName.toLowerCase() !== tag) {
return false;
}
if (cls !== "" && this.filterClass([el], cls).length === 0) {
return false;
}
if (attrRules !== "" && this.filterAttr([el], attrRules).length === 0) {
return false;
}
if (pseudoRules !== "" && this.filterPseudo([el], pseudoRules).length === 0) {
return false;
}
return true;
},
/**
* Reomve duplicate HTMLElements.
*
* @param {Array} els
* @return {Array} unique HTMLElements array
*/
makeDiff: function(els) {
var
diff = [],
guid = ++this.tagGuid,
getElData = this.getElData,
len, i, el, data;
for (i = 0, len = els.length; i < len; ++i) {
el = els[i];
data = getElData(el);
if (data.tagGuid !== guid) {
diff.push(el);
data.tagGuid = guid;
}
}
return diff;
},
/**
* Convert NodeList to NodeArray.
*
* @param {NodeList} nodeList
* @return {Array} nodes array
*/
makeArray: function(nodeList) {
var
arr = [],
len, i;
for (i = 0, len = nodeList.length; i < len; ++i) {
arr.push(nodeList[i]);
}
return arr;
},
/**
* Get the data bind to HTMLElement.
*
* @param {HTMLElement} el
* @return {Object} data binded to HTMLElement.
*/
getElData: function(el) {
var
data = el.dataForMojoJS,
undefined;
if (data === undefined) {
data = el.dataForMojoJS = {};
}
return data;
},
/**
* Get the data of parsed nth pseudo parameter.
*
* @param {Number} guid
* @param {String} param
* @return {Object} parsed nth parameter data
*/
getNthData: function(guid, param) {
if (this.rex.NTH.test(param === "odd" && "2n+1" ||
param === "even" && "2n" || param)) {
param = this.RegExp.$1;
param === "" ?
param = 1 :
param === "-" ?
param = -1 :
param = param * 1;
if (param !== 0) {
return {
// whether "nth-child()" has "n" parameter
hasParam: true,
// identifies HTMLElement
guid : guid,
// parameter before "n"
nFront : param,
// paramter after "n"
nBehind : this.RegExp.$2 * 1
};
}
// the "0n" matched
param = this.RegExp.$2;
}
return {
// whether "nth-child()" has "n" parameter
hasParam: false,
// identifies HTMLElement
guid : guid,
// number in such as "nth-child(5)"
n : param * 1
}
},
/**
* Check the index whether matched nth pseudo parameter.
*
* @param {Number} index
* @param {Object} nthData
* @return {Boolean} matched or not
*/
checkNth: function(index, nthData) {
if (nthData.hasParam) {
index = index - nthData.nBehind;
nthData = nthData.nFront;
return index * nthData >= 0 && index % nthData === 0;
}
return index === nthData.n;
},
/**
* Check el child whether matched nth pseudo parameter.
*
* @param {HTMLElement} el
* @param {Object} nthData
* @return {Booelan} matched or not
*/
checkNthChild: function(el, nthData) {
var
guid = nthData.guid,
first = nthData.first,
next = nthData.next,
getElData = this.getElData,
node, parent, name, index, pData, tagMap, undefined;
pData = getElData(parent = el.parentNode);
if (pData.tagGuid !== guid) {
node = parent[first];
if (nthData.checkType) {
// need to check HTMLElement type
// so record the type
tagMap = pData.tagMap = {};
while (node !== null) {
if (node.nodeType === 1) {
name = node.nodeName;
if (tagMap[name] === undefined) {
tagMap[name] = 0;
}
// count child by diff type
getElData(node).nodeIndex = ++tagMap[name];
}
node = node[next];
}
} else {
index = 0;
while (node !== null) {
if (node.nodeType === 1) {
getElData(node).nodeIndex = ++index;
}
node = node[next];
}
}
pData.tagGuid = guid;
}
return this.checkNth(getElData(el).nodeIndex, nthData);
},
/**
* Check el has sibling.
*
* @param {HTMLElement} el
* @param {String} next
* @param {Boolean} checkType
* @param {String} name
* @return {Boolean} has or not
*/
checkSibling: function(el, next, checkType, name) {
while ((el = el[next]) !== null) {
if (el.nodeType === 1) {
if (checkType === false || name === el.nodeName) {
return false;
}
}
}
return true;
},
//---------------------------------------------------------------------------------------------------------------------
relativeFilter: {
" ": function(parser, contexts, tag) {
var
guid = ++parser.tagGuid,
arr = [],
getElData = parser.getElData,
nodes, el, cLen, i, nLen, j;
nextLoop:
for (i = 0, cLen = contexts.length; i < cLen; ++i) {
el = parent = contexts[i];
// test any parents have queried subelements
while ((parent = parent.parentNode) !== null) {
if (getElData(parent).tagGuid === guid) {
continue nextLoop;
}
}
// el never query subelements
// so mark it
getElData(el).tagGuid = guid;
nodes = el.getElementsByTagName(tag);
for (j = 0, nLen = nodes.length; j < nLen; ++j) {
arr.push(nodes[j]);
}
}
return arr;
},
">": function(parser, contexts, tag) {
var
arr = [],
len, i, el;
for (i = 0, len = contexts.length; i < len; ++i) {
el = contexts[i].firstChild;
while (el !== null) {
if (el.nodeType === 1) {
if (el.nodeName.toLowerCase() === tag || tag === "*") {
arr.push(el);
}
}
el = el.nextSibling;
}
}
return arr;
},
"+": function(parser, contexts, tag) {
var
arr = [],
len, i, el;
for (i = 0, len = contexts.length; i < len; ++i) {
el = contexts[i];
while ((el = el.nextSibling) !== null) {
if (el.nodeType === 1) {
if (el.nodeName.toLowerCase() === tag || tag === "*") {
arr.push(el);
}
break;
}
}
}
return arr;
},
"~": function(parser, contexts, tag) {
var
guid = ++parser.tagGuid,
arr = [],
getElData = parser.getElData,
len, i, el, parent, data;
for (i = 0, len = contexts.length; i < len; ++i) {
el = contexts[i];
if ((parent = el.parentNode)) {
if ((data = getElData(parent)).tagGuid === guid) {
continue;
}
data.tagGuid = guid;
}
while ((el = el.nextSibling) !== null) {
if (el.nodeType === 1) {
if (el.nodeName.toLowerCase() === tag || tag === "*") {
arr.push(el);
}
}
}
}
return arr;
}
},
//---------------------------------------------------------------------------------------------------------------------
attributeFilter: {
" ": function() {
return true;
},
"=": function(attrVal, inputVal) {
return attrVal === inputVal;
},
"!=": function(attrVal, inputVal) {
return attrVal !== inputVal;
},
"^=": function(attrVal, inputVal) {
return attrVal.indexOf(inputVal) === 0;
},
"$=": function(attrVal, inputVal) {
return attrVal.substring(attrVal.length - inputVal.length) === inputVal;
},
"*=": function(attrVal, inputVal) {
return attrVal.indexOf(inputVal) !== -1
},
"~=": function(attrVal, inputVal) {
return (" " + attrVal + " ").indexOf(" " + inputVal + " ") !== -1;
},
"|=" : function(attrVal, inputVal) {
return attrVal === inputVal || attrVal.substring(0, inputVal.length + 1) === inputVal + "-";
}
},
//---------------------------------------------------------------------------------------------------------------------
pseudoFilter: {
/* css */
"nth-child": {
getFnParam: function(parser, guid, param) {
var
nthData = parser.getNthData(guid, param);
nthData.first = "firstChild";
nthData.next = "nextSibling";
nthData.checkType = false;
return nthData;
},
fn: function(parser, el, index, nthData) {
return parser.checkNthChild(el, nthData);
}
},
"nth-last-child": {
getFnParam: function(parser, guid, param) {
var
nthData = parser.getNthData(guid, param);
nthData.first = "lastChild";
nthData.next = "previousSibling";
nthData.checkType = false;
return nthData;
},
fn: function(parser, el, index, nthData) {
return parser.checkNthChild(el, nthData);
}
},
"nth-of-type": {
getFnParam: function(parser, guid, param) {
var
nthData = parser.getNthData(guid, param);
nthData.first = "firstChild";
nthData.next = "nextSibling";
nthData.checkType = true;
return nthData;
},
fn: function(parser, el, index, nthData) {
return parser.checkNthChild(el, nthData);
}
},
"nth-last-of-type": {
getFnParam: function(parser, guid, param) {
var
nthData = parser.getNthData(guid, param);
nthData.first = "lastChild";
nthData.next = "previousSibling";
nthData.checkType = true;
return nthData;
},
fn: function(parser, el, index, nthData) {
return parser.checkNthChild(el, nthData);
}
},
not: {
getFnParam: function(parser, guid, param) {
var
// ":not()" may has "," in parameter
// such as ":not(a, p)"
selectors = param.split(","),
rulesArr = [];
while (selectors.length !== 0) {
rulesArr.push(parser.getRules(selectors.pop()));
}
return rulesArr;
},
fn: function(parser, el, index, rulesArr) {
var
len, i, rules;
for (i = 0, len = rulesArr.length; i < len; ++i) {
rules = rulesArr[i];
if (rules[1]) {
if ("#" + el.id !== rules[1]) {
continue;
}
return false;
}
if (parser.filterEl(el, rules[2], rules[3], rules[4], rules[5])) {
return false;
}
}
return true;
}
},
"first-child": function(parser, el, index, len) {
return parser.checkSibling(el, "previousSibling", false);
},
"last-child": function(parser, el, index, len) {
return parser.checkSibling(el, "nextSibling", false);
},
"only-child": function(parser, el, index, len) {
return parser.checkSibling(el, "previousSibling", false) &&
parser.checkSibling(el, "nextSibling", false);
},
"first-of-type": function(parser, el, index, len) {
return parser.checkSibling(el, "previousSibling", true, el.nodeName);
},
"last-of-type": function(parser, el, index, len) {
return parser.checkSibling(el, "nextSibling", true, el.nodeName);;
},
"only-of-type": function(parser, el, index, len) {
var name = el.nodeName;
return parser.checkSibling(el, "previousSibling", true, name) &&
parser.checkSibling(el, "nextSibling", true, name);
},
enabled: function(parser, el, index, len) {
return el.disabled === false;
},
disabled: function(parser, el, index, len) {
return el.disabled === true;
},
checked: function(parser, el, index, len) {
return el.checked === true;
},
empty: function(parser, el, index, len) {
return el.firstChild === null;
},
selected: function(parser, el, index, len) {
return el.selected === true;
} ,
/* position */
first: function(parser, el, index, len) {
return index === 0;
},
last: function(parser, el, index, len) {
return index === (len - 1);
},
even: function(parser, el, index, len) {
return index % 2 === 0;
},
odd: function(parser, el, index, len) {
return index % 2 === 1;
},
nth: {
getFnParam: function(parser, guid, param) {
return parser.getNthData(guid, param);
},
fn: function(parser, el, index, nthData) {
return parser.checkNth(index, nthData);
}
},
/* additions */
contains: {
fn: function(parser, el, index, param) {
return (el.textContent || el.innerText || "").indexOf(param) !== -1;
}
},
has: {
getFnParam: function(parser, guid, param) {
return param.split(",");
},
fn: function(parser, el, index, selectors) {
return parser.parse(selectors, [el]).length !== 0;
}
}
}
};
//---------------------------------------------------------------------------------------------------------------------
if (window.document.querySelectorAll !== undefined) {
parser.oldQuery = parser.query;
parser.document = window.document;
parser.query = function(selector, context) {
if (context === undefined) {
try {
return this.makeArray(this.document.querySelectorAll(selector));
} catch (e) {}
}
return this.oldQuery(selector, context);
}
}
if (window.MojoJS === undefined) {
window.MojoJS = {};
}
/**
* Query HTMLElements by css seletor and context.
*
* @param {String} selector
* @param {String (selector) | HTMLElement | Array<HTMLElement> | NodeList} context (optional)
* @return {Array<HTMLElement>} HTMLElements
*/
window.MojoJS.query = function(selector, context) {
return parser.query(selector, context);
};
})(window);
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/mirrors/MojoJS-Query.git
git@gitee.com:mirrors/MojoJS-Query.git
mirrors
MojoJS-Query
MojoJS-Query
master

搜索帮助