+var attr_op_eval = function(result, operator, check) {
+ if ( result == null ) {
+ return operator === "!=";
+ }
+
+ if ( !operator ) {
+ return true;
+ }
+
+ result += "";
+
+ return operator === "=" ? result === check :
+ operator === "!=" ? result !== check :
+ operator === "^=" ? check && result.indexOf( check ) === 0 :
+ operator === "*=" ? check && result.indexOf( check ) > -1 :
+ operator === "$=" ? check && result.substr( result.length - check.length ) === check :
+ operator === "~=" ? ( " " + result + " " ).indexOf( check ) > -1 :
+ operator === "|=" ? result === check || result.substr( 0, check.length + 1 ) === check + "-" :
+ false;
+};
+
+//Modify the ATTR filter function to account for namespace selector.
+//Unfortunately this means factoring out the attribute-checking code
+//into a separate function, since it might be called multiple times.
+//
+function filter_attr( prefixedName, ns, name, op, check ) {
+ return function( elem, context ) {
+ if(ns == "") {
+ var result = $(elem).attr(name);
+ return attr_op_eval(result, op, check);
+ } else {
+ if(ns != "*" && typeof elem.getAttributeNS != "undefined") {
+ return attr_op_eval(elem.getAttributeNS(ns,name), op, check);
+ }
+
+ // Need to iterate over all attributes, either because we couldn't
+ // look it up or because we need to match all namespaces.
+ var attrs = elem.attributes;
+ for (var i=0; attrs[i]; i++) {
+ var ln = attrs[i].localName;
+ if(!ln) {
+ ln = attrs[i].nodeName;
+ var idx = ln.indexOf(":");
+ if(idx >= 0) {
+ ln = ln.substr(idx+1);
+ }
+ }
+ if(ln == name) {
+ result = attrs[i].nodeValue;
+ if(ns == "*" || attrs[i].namespaceURI == ns) {
+ if(attr_op_eval(result, op, check)) {
+ return true;
+ }
+ }
+ if(attrs[i].namespaceURI === "" && attrs[i].prefix) {
+ if(attrs[i].prefix == default_xmlns_rev[ns]) {
+ if(attr_op_eval(result, op, check)) {
+ return true;
+ }
+ }
+ }
+ }
+ }
+ return false;
+ }
+ };
+};