/** @id MochiKit.Selector.Selector.prototype.buildMatchExpression */
buildMatchExpression: function () { var repr = MochiKit.Base.repr; var params = this.params; var conditions = []; var clause, i;
function childElements(element) { return"MochiKit.Base.filter(function (node) { return node.nodeType == 1; }, " + element + ".childNodes)";
}
if (params.wildcard) {
conditions.push('true');
} if (clause = params.id) {
conditions.push('element.id == ' + repr(clause));
} if (clause = params.tagName) {
conditions.push('element.tagName.toUpperCase() == ' + repr(clause));
} if ((clause = params.classNames).length > 0) { for (i = 0; i < clause.length; i++) {
conditions.push('MochiKit.DOM.hasElementClass(element, ' + repr(clause[i]) + ')');
}
} if ((clause = params.pseudoClassNames).length > 0) { for (i = 0; i < clause.length; i++) { var match = clause[i].match(/^([^(]+)(?:\((.*)\))?$/); var pseudoClass = match[1]; var pseudoClassArgument = match[2]; switch (pseudoClass) { case'root':
conditions.push('element.nodeType == 9 || element === element.ownerDocument.documentElement'); break; case'nth-child': case'nth-last-child': case'nth-of-type': case'nth-last-of-type':
match = pseudoClassArgument.match(/^((?:(\d+)n\+)?(\d+)|odd|even)$/); if (!match) { throw"Invalid argument to pseudo element nth-child: " + pseudoClassArgument;
} var a, b; if (match[0] == 'odd') {
a = 2;
b = 1;
} elseif (match[0] == 'even') {
a = 2;
b = 0;
} else {
a = match[2] && parseInt(match) || null;
b = parseInt(match[3]);
}
conditions.push('this.nthChild(element,' + a + ',' + b
+ ',' + !!pseudoClass.match('^nth-last') // Reverse
+ ',' + !!pseudoClass.match('of-type$') // Restrict to same tagName
+ ')'); break; case'first-child':
conditions.push('this.nthChild(element, null, 1)'); break; case'last-child':
conditions.push('this.nthChild(element, null, 1, true)'); break; case'first-of-type':
conditions.push('this.nthChild(element, null, 1, false, true)'); break; case'last-of-type':
conditions.push('this.nthChild(element, null, 1, true, true)'); break; case'only-child':
conditions.push(childElements('element.parentNode') + '.length == 1'); break; case'only-of-type':
conditions.push('MochiKit.Base.filter(function (node) { return node.tagName == element.tagName; }, ' + childElements('element.parentNode') + ').length == 1'); break; case'empty':
conditions.push('element.childNodes.length == 0'); break; case'enabled':
conditions.push('(this.isUIElement(element) && element.disabled === false)'); break; case'disabled':
conditions.push('(this.isUIElement(element) && element.disabled === true)'); break; case'checked':
conditions.push('(this.isUIElement(element) && element.checked === true)'); break; case'not': var subselector = new MochiKit.Selector.Selector(pseudoClassArgument);
conditions.push('!( ' + subselector.buildMatchExpression() + ')') break;
}
}
} if (clause = params.attributes) {
MochiKit.Base.map(function (attribute) { var value = 'MochiKit.DOM.getNodeAttribute(element, ' + repr(attribute.name) + ')'; var splitValueBy = function (delimiter) { return value + '.split(' + repr(delimiter) + ')';
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.