X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/5913c54d19b8f6775633176032161d49f9b2f1aa..5fa4673581da8c9ebe6ff327c4520989a6675c8c:/src/redakcja/static/js/lib/jquery/jquery.xmlns.js?ds=inline diff --git a/src/redakcja/static/js/lib/jquery/jquery.xmlns.js b/src/redakcja/static/js/lib/jquery/jquery.xmlns.js index 96c5a559..3a4689e6 100644 --- a/src/redakcja/static/js/lib/jquery/jquery.xmlns.js +++ b/src/redakcja/static/js/lib/jquery/jquery.xmlns.js @@ -64,6 +64,7 @@ (function($) { +var jquery_gt_18 = jQuery.fn.jquery >= "1.8"; // Some common default namespaces, that are treated specially by browsers. // var default_xmlns = { @@ -72,6 +73,7 @@ var default_xmlns = { "html": "http://www.w3.org/1999/xhtml/" }; +rbackslash = /\\(?!\\)/g; // A reverse mapping for common namespace prefixes. // @@ -162,22 +164,25 @@ var getNamespaceURI = function(id) { // // This logic is taken straight from the jQuery/Sizzle sources. // -var setExprMatchRegex = function(type,regex) { - $.expr.match[type] = new RegExp(regex.source + /(?![^\[]*\])(?![^\(]*\))/.source); - if($.expr.leftMatch) { - $.expr.leftMatch[type] = new RegExp(/(^(?:.|\r|\n)*?)/.source + $.expr.match[type].source.replace(/\\(\d+)/g, function(all, num){ - return "\\" + (num - 0 + 1); - })); - } -} - - +var setExprMatchRegex = (jquery_gt_18) ? function(type,regex) { + $.expr.match[type] = regex; + } : function(type,regex) { + $.expr.match[type] = new RegExp(regex.source + /(?![^\[]*\])(?![^\(]*\))/.source); + if($.expr.leftMatch) { + $.expr.leftMatch[type] = new RegExp(/(^(?:.|\r|\n)*?)/.source + $.expr.match[type].source.replace(/\\(\d+)/g, function(all, num){ + return "\\" + (num - 0 + 1); + })); + } + }; // Modify the TAG match regexp to include optional namespace selector. // This is basically (namespace|)?(tagname). // -setExprMatchRegex("TAG",/^((?:((?:[\w\u00c0-\uFFFF\*_-]*\|)?)((?:[\w\u00c0-\uFFFF\*_-]|\\.)+)))/); - +if (jquery_gt_18) { + setExprMatchRegex("TAG",/^((?:((?:\\.|[-\w*]|[^\x00-\xa0])+\|)?((?:\\.|[-\w*]|[^\x00-\xa0])+)))/); +} else { + setExprMatchRegex("TAG",/^((?:((?:[\w\u00c0-\uFFFF\*_-]*\|)?)((?:[\w\u00c0-\uFFFF\*_-]|\\.)+)))/); +} // Perform some capability-testing. // @@ -203,13 +208,29 @@ if(div.localName && div.localName == "div") { // div = null; - -// Modify the TAG find function to account for a namespace selector. -// -$.expr.find.TAG = function(match,context,isXML) { +function find_tag_17(match, context, isXML) { var ns = getNamespaceURI(match[2]); var ln = match[3]; - var res; + return find_tag(ns, ln, match, context, isXML); +} + +function find_tag_18(match, context, isXML) { + var index = match.indexOf("|"); + + if (index == -1) { + if ( typeof context.getElementsByTagName !== "undefined" ) { + return context.getElementsByTagName(match); + } + } + + var ns = getNamespaceURI(match.substring(0,index + 1)); + var ln = match.substring(index + 1); + + return find_tag(ns, ln, match, context, isXML); +} + +function find_tag(ns, ln, match, context, isXML) { + var res; if(typeof context.getElementsByTagNameNS != "undefined") { // Easy case - we have getElementsByTagNameNS res = context.getElementsByTagNameNS(ns,ln); @@ -260,8 +281,11 @@ $.expr.find.TAG = function(match,context,isXML) { } } return res; -}; +} +// Modify the TAG find function to account for a namespace selector. +// +$.expr.find.TAG = (jquery_gt_18)? find_tag_18 : find_tag_17; // Check whether a node is part of an XML document. // Copied verbatim from jQuery sources, needed in TAG preFilter below. @@ -271,11 +295,10 @@ var isXML = function(elem){ !!elem.ownerDocument && elem.ownerDocument.documentElement.nodeName !== "HTML"; }; - // Modify the TAG preFilter function to work with modified match regexp. // This normalises case of the tag name if we're in a HTML document. // -$.expr.preFilter.TAG = function(match, curLoop, inplace, result, not, isXML) { +$.expr.preFilter.TAG = (jquery_gt_18)? function(match, curLoop, inplace, result, not, isXML) { var ln = match[3]; if(!isXML) { if(localname_is_uppercase) { @@ -284,34 +307,72 @@ $.expr.preFilter.TAG = function(match, curLoop, inplace, result, not, isXML) { ln = ln.toLowerCase(); } } - return [match[0],getNamespaceURI(match[2]),ln]; + return [match[0], match[0],getNamespaceURI(match[2]),ln]; +} : function(match, curLoop, inplace, result, not, isXML) { + var ln = match[3]; + if(!isXML) { + if(localname_is_uppercase) { + ln = ln.toUpperCase(); + } else { + ln = ln.toLowerCase(); + } + } + return [match[0],getNamespaceURI(match[2]),ln]; }; +function filter_tag(ln, ns) { + var index = ln.indexOf("|"); + if (index != -1) + ln = ln.substring(index+1); + return function( elem ) { + var e_ns = elem.namespaceURI ? elem.namespaceURI : elem.tagUrn; + var e_ln = elem.localName ? elem.localName : elem.tagName; + if(ns == "*" || e_ns == ns || (ns == "" && !e_ns)) { + return ((ln == "*" && elem.nodeType == 1) || e_ln == ln); + } + + return false; + }; +}; -// Modify the TAG filter function to account for a namespace selector. +//Modify the TAG filter function to account for a namespace selector. // -$.expr.filter.TAG = function(elem,match) { - var ns = match[1]; +$.expr.filter.TAG = (jquery_gt_18)? filter_tag : function(elem, match) { + var ns = match[1]; var ln = match[2]; - var e_ns = elem.namespaceURI ? elem.namespaceURI : elem.tagUrn; - var e_ln = elem.localName ? elem.localName : elem.tagName; - if(ns == "*" || e_ns == ns || (ns == "" && !e_ns)) { - return ((ln == "*" && elem.nodeType == 1) || e_ln == ln); - } - return false; + return filter_tag(ln, ns).call(this, elem, null); }; - // Modify the ATTR match regexp to extract a namespace selector. // This is basically ([namespace|])(attrname)(op)(quote)(pattern)(quote) // -setExprMatchRegex("ATTR",/\[\s*((?:((?:[\w\u00c0-\uFFFF\*_-]*\|)?)((?:[\w\u00c0-\uFFFF_-]|\\.)+)))\s*(?:(\S?=)\s*(['"]*)(.*?)\5|)\s*\]/); - +if (jquery_gt_18) { + setExprMatchRegex("ATTR",/^\[[\x20\t\r\n\f]*(((?:\\.|[-\w]|[^\x00-\xa0])+\|)?((?:\\.|[-\w]|[^\x00-\xa0])+))[\x20\t\r\n\f]*(?:([*^$|!~]?=)[\x20\t\r\n\f]*(?:(['"])((?:\\.|[^\\])*?)\5|((?:\\.|[-\w]|[^\x00-\xa0])+\|)?((?:\\.|[-\w#]|[^\x00-\xa0])+)|)|)[\x20\t\r\n\f]*\]/); +} else { + setExprMatchRegex("ATTR",/\[\s*((?:((?:[\w\u00c0-\uFFFF\*_-]*\|)?)((?:[\w\u00c0-\uFFFF_-]|\\.)+)))\s*(?:(\S?=)\s*(['"]*)(.*?)\5|)\s*\]/); +} // Modify the ATTR preFilter function to account for new regexp match groups, // and normalise the namespace URI. // -$.expr.preFilter.ATTR = function(match, curLoop, inplace, result, not, isXML) { +$.expr.preFilter.ATTR = (jquery_gt_18)? function( match, context, isXml ) { + var name = match[1].replace(rbackslash, ""); + + if( match[4] == "~=" ) { + match[6] = " " + match[6] + " "; + } + + // Move the given value to match[5] whether quoted or unquoted + match[5] = ( match[6] || match[7] || "" ).replace( rbackslash, "" ); + + if(!match[2] || match[2] == "|") { + match[2] = ""; + } else { + match[2] = getNamespaceURI(match[2]); + } + + return match.slice( 0, 6 ); +} : function(match, curLoop, inplace, result, not, isXML) { var name = match[3].replace(/\\/g, ""); if(!isXML && $.expr.attrMap[name]) { match[3] = $.expr.attrMap[name]; @@ -328,84 +389,82 @@ $.expr.preFilter.ATTR = function(match, curLoop, inplace, result, not, isXML) { }; -// 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. -// -var filter_attr = function(result,type,check) { - var value = result + ""; - return result == null ? - type === "!=" : - type === "=" ? - value === check : - type === "*=" ? - value.indexOf(check) >= 0 : - type === "~=" ? - (" " + value + " ").indexOf(check) >= 0 : - !check ? - value && result !== false : - type === "!=" ? - value != check : - type === "^=" ? - value.indexOf(check) === 0 : - type === "$=" ? - value.substr(value.length - check.length) === check : - type === "|=" ? - value === check || value.substr(0,check.length+1)===check+"-" : - false; -} +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; + } + }; +}; -$.expr.filter.ATTR = function(elem, match) { - var ns = match[2]; +$.expr.filter.ATTR = (jquery_gt_18)? filter_attr : function(elem, match) { + var ns = match[2]; var name = match[3]; var type = match[4]; var check = match[6]; - var result; - // No namespace, just use ordinary attribute lookup. - if(ns == "") { - result = $.expr.attrHandle[name] ? - $.expr.attrHandle[name](elem) : - elem[name] != null ? - elem[name] : - elem.getAttribute(name); - return filter_attr(result,type,check); - } - // Directly use getAttributeNS if applicable and available - if(ns != "*" && typeof elem.getAttributeNS != "undefined") { - return filter_attr(elem.getAttributeNS(ns,name),type,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(filter_attr(result,type,check)) { - return true; - } - } - if(attrs[i].namespaceURI === "" && attrs[i].prefix) { - if(attrs[i].prefix == default_xmlns_rev[ns]) { - if(filter_attr(result,type,check)) { - return true; - } - } - } - } - } - return false; + return filter_attr(null, ns, name, type, check).call(this, elem, null); }; -})(jQuery); - +})(jQuery); \ No newline at end of file