Bug Tracker

Ticket #2056: jquery.patch

File jquery.patch, 13.2 KB (added by greg, 4 years ago)

patch file

  • src/core.js

     
    157157        // Determine the position of an element within  
    158158        // the matched set of elements 
    159159        index: function( elem ) { 
    160                 var ret = -1; 
    161  
    162                 // Locate the position of the desired element 
    163                 this.each(function(i){ 
    164                         if ( this == elem ) 
    165                                 ret = i; 
    166                 }); 
    167  
    168                 return ret; 
     160                return jQuery.inArray( elem, this ) 
    169161        }, 
    170162 
    171163        attr: function( name, value, type ) { 
     
    201193                return this.attr( key, value, "curCSS" ); 
    202194        }, 
    203195 
     196        getText: function( elem ) { 
     197                return jQuery.map( elem.childNodes, function(child){ 
     198                        var nt = child.nodeType; 
     199                        return nt == 8 ? null 
     200                                                   : nt == 1 ? jQuery.fn.getText( child ) 
     201                                                   : child.nodeValue; 
     202                }).join(""); 
     203        }, 
     204 
    204205        text: function( text ) { 
    205                 if ( typeof text != "object" && text != null ) 
    206                         return this.empty().append( (this[0] && this[0].ownerDocument || document).createTextNode( text ) ); 
    207  
    208                 var ret = ""; 
    209  
    210                 jQuery.each( text || this, function(){ 
    211                         jQuery.each( this.childNodes, function(){ 
    212                                 if ( this.nodeType != 8 ) 
    213                                         ret += this.nodeType != 1 ? 
    214                                                 this.nodeValue : 
    215                                                 jQuery.fn.text( [ this ] ); 
    216                         }); 
    217                 }); 
    218  
    219                 return ret; 
     206                if ( typeof text != "object" && text !== null && text !== undefined ) 
     207                        return this.empty().append( document.createTextNode( text ) ); 
     208                else 
     209                  return jQuery.map( text || this, jQuery.fn.getText ).join(""); 
    220210        }, 
    221211 
    222212        wrapAll: function( html ) { 
     
    476466        }, 
    477467         
    478468        domManip: function( args, table, reverse, callback ) { 
    479                 var clone = this.length > 1, elems;  
     469                var len = this.length, clone, elems; 
     470                if( len === 0 ) return this; 
     471                else { 
     472                  clone = len > 1 
     473                  elems = jQuery.clean( args, this[0].ownerDocument ); 
     474                  if ( reverse ) elems.reverse(); 
     475                } 
    480476 
    481477                return this.each(function(){ 
    482                         if ( !elems ) { 
    483                                 elems = jQuery.clean( args, this.ownerDocument ); 
    484  
    485                                 if ( reverse ) 
    486                                         elems.reverse(); 
    487                         } 
    488  
    489478                        var obj = this; 
    490479 
    491480                        if ( table && jQuery.nodeName( this, "table" ) && jQuery.nodeName( elems[0], "tr" ) ) 
     
    10771066        }, 
    10781067 
    10791068        makeArray: function( array ) { 
    1080                 var ret = []; 
    1081  
    10821069                // Need to use typeof to fight Safari childNodes crashes 
    1083                 if ( typeof array != "array" ) 
    1084                         for ( var i = 0, length = array.length; i < length; i++ ) 
    1085                                 ret.push( array[ i ] ); 
    1086                 else 
    1087                         ret = array.slice( 0 ); 
     1070                if ( typeof array == "array" ) return array.slice( 0 ); 
    10881071 
     1072                var ret = []; 
     1073                for ( var i = 0, length = array.length; i < length; i++ ) 
     1074                        ret.push( array[ i ] ); 
    10891075                return ret; 
    10901076        }, 
    10911077 
     
    11001086        merge: function( first, second ) { 
    11011087                // We have to loop this way because IE & Opera overwrite the length 
    11021088                // expando of getElementsByTagName 
    1103  
    11041089                // Also, we need to make sure that the correct elements are being returned 
    1105                 // (IE returns comment nodes in a '*' query) 
    1106                 if ( jQuery.browser.msie ) { 
    1107                         for ( var i = 0; second[ i ]; i++ ) 
    1108                                 if ( second[ i ].nodeType != 8 ) 
    1109                                         first.push( second[ i ] ); 
     1090                for ( var i = 0, next=second[1]; ; ){ 
     1091                        if( !next ){ 
     1092                                if( second[i] ) first.push( second[i] ); 
     1093                                break; 
     1094                        } 
     1095                        first.push( second[i], next ); 
     1096                        i+=2 
     1097                        next = second[ i+1 ]; 
     1098                } 
     1099                return first; 
     1100        }, 
    11101101 
    1111                 } else 
    1112                         for ( var i = 0; second[ i ]; i++ ) 
     1102        msie_merge: function(first, second){ 
     1103                for ( var i = 0; second[ i ]; i++ ) 
     1104                        // (IE returns comment nodes in a '*' query) 
     1105                        if ( second[ i ].nodeType != 8 ) 
    11131106                                first.push( second[ i ] ); 
    1114  
    11151107                return first; 
    11161108        }, 
    11171109 
     
    11301122                        } 
    11311123 
    11321124                } catch( e ) { 
    1133                         ret = array; 
     1125                        return array; 
    11341126                } 
    11351127 
    11361128                return ret; 
    11371129        }, 
    11381130 
     1131        reject: function(elems, callback) { 
     1132                var ret = []; 
     1133                for( var i = 0, el = elems.length; i < el; i++ ) { 
     1134                        if ( !callback( elems[i], i ) ) ret.push( elems[i] ); 
     1135                } 
     1136                return ret; 
     1137        }, 
     1138 
    11391139        grep: function( elems, callback, inv ) { 
    11401140                // If a string is passed in for the function, make a function 
    11411141                // for it (a handy shortcut) 
    11421142                if ( typeof callback == "string" ) 
    11431143                        callback = eval("false||function(a,i){return " + callback + "}"); 
    11441144 
     1145                if( inv ) return jQuery.reject(elems, callback); 
     1146 
    11451147                var ret = []; 
    1146  
    1147                 // Go through the array, only saving the items 
    1148                 // that pass the validator function 
    1149                 for ( var i = 0, length = elems.length; i < length; i++ ) 
    1150                         if ( !inv && callback( elems[ i ], i ) || inv && !callback( elems[ i ], i ) ) 
    1151                                 ret.push( elems[ i ] ); 
    1152  
     1148                for ( var i = 0, length = elems.length; i < length; i++ ) { 
     1149                        if ( callback( elems[i], i ) ) ret.push( elems[i] ); 
     1150                } 
    11531151                return ret; 
    11541152        }, 
    11551153 
     1154        // automatically flattens returned arrays 
     1155        // map(xs, function(x) {return [x]}) == xs 
    11561156        map: function( elems, callback ) { 
    1157                 var ret = []; 
     1157                var arrays = []; // array of arrays to be concated together 
    11581158 
    1159                 // Go through the array, translating each of the items to their 
    1160                 // new value (or values). 
    1161                 for ( var i = 0, length = elems.length; i < length; i++ ) { 
     1159                for (var i = 0, length = elems.length; i < length; i++ ) { 
    11621160                        var value = callback( elems[ i ], i ); 
    11631161 
    1164                         if ( value !== null && value != undefined ) { 
    1165                                 if ( value.constructor != Array ) 
    1166                                         value = [ value ]; 
     1162                        if ( value !== null && value !== undefined ) { 
     1163                                if ( value.constructor != Array ) arrays.push( [value] ); 
     1164                                else arrays.push( value ); 
     1165                        }  
     1166                } 
     1167                // if arrays has no members, Array.concat will return undefined 
     1168                if( arrays.length === 0 ) return arrays; 
     1169                return Array.concat.apply(Array, arrays); 
     1170        }, 
    11671171 
    1168                                 ret = ret.concat( value ); 
    1169                         } 
     1172 
     1173        // map without flattening, error on undefined, filter null 
     1174        collect: function( elems, callback ) { 
     1175                ret = [] 
     1176                for (var i = 0, length = elems.length; i < length; i++ ) { 
     1177                        var value = callback( elems[ i ], i ); 
     1178                        if( value === undefined ) 
     1179                          throw("collect: callback return undefined value "); 
     1180                        if( value !== null ) ret.push( value ); 
    11701181                } 
    1171  
    11721182                return ret; 
    11731183        } 
    11741184}); 
     
    13301340                                        this.css( type, size.constructor == String ? size : size + "px" ); 
    13311341        }; 
    13321342}); 
     1343 
     1344if ( jQuery.browser.msie ) jQuery.extend({merge: jQuery.msie_merge}) 
  • src/selector.js

     
    88 
    99jQuery.extend({ 
    1010        expr: { 
    11                 "": "m[2]=='*'||jQuery.nodeName(a,m[2])", 
    12                 "#": "a.getAttribute('id')==m[2]", 
     11                "" : function(a){return m[2]=='*'||jQuery.nodeName(a,m[2])}, 
     12                "#": function(a){return a.getAttribute('id')==m[2]}, 
    1313                ":": { 
    1414                        // Position Checks 
    1515                        lt: "i<m[3]-0", 
     
    6767        }, 
    6868         
    6969        // The regular expressions that power the parsing engine 
    70         parse: [ 
     70        parse: { 
     71                attributes: 
    7172                // Match: [@value='test'], [@foo] 
    7273                /^(\[) *@?([\w-]+) *([!*$^~=]*) *('?"?)(.*?)\4 *\]/, 
    7374 
     75                argument: 
    7476                // Match: :contains('foo') 
    75                 /^(:)([\w-]+)\("?'?(.*?(\(.*?\))?[^(]*?)"?'?\)/, 
     77                /^(:)([\w-]+)\(["']?(.*?(\(.*?\))?[^(]*?)["']?\)/, 
    7678 
    77                 // Match: :even, :last-chlid, #id, .class 
    78                 new RegExp("^([:.#]*)(" + chars + "+)") 
    79         ], 
     79                other: 
     80                // Match: :even, :last-child, #id, .class 
     81                new RegExp("^([:.#]?)(" + chars + "+)") 
     82        }, 
    8083 
    8184        multiFilter: function( expr, elems, not ) { 
    8285                var old, cur = []; 
     
    293296                return tmp; 
    294297        }, 
    295298 
    296         filter: function(t,r,not) { 
    297                 var last; 
     299        //variables used only in the filter function 
     300    //placed here so they can be bound to the expr functions 
     301        m: null, r: null, 
     302        filter: function(t,r_passed,not) { 
     303                var last, p = jQuery.parse; 
     304                m = null, r = r_passed; 
     305                function match(key) { 
     306                        m = p[key].exec(t) 
     307                        if(m){ 
     308                                // Remove what we just matched 
     309                                t = t.substring( m[0].length ); 
    298310 
     311                                m[2] = m[2].replace(/\\/g, ""); 
     312                        } 
     313                        return m; 
     314                } 
     315 
    299316                // Look for common filter expressions 
    300317                while ( t && t != last ) { 
    301318                        last = t; 
    302319 
    303                         var p = jQuery.parse, m; 
    304  
    305                         for ( var i = 0; p[i]; i++ ) { 
    306                                 m = p[i].exec( t ); 
    307  
    308                                 if ( m ) { 
    309                                         // Remove what we just matched 
    310                                         t = t.substring( m[0].length ); 
    311  
    312                                         m[2] = m[2].replace(/\\/g, ""); 
    313                                         break; 
    314                                 } 
    315                         } 
    316  
    317                         if ( !m ) 
    318                                 break; 
    319  
    320                         // :not() is a special case that can be optimized by 
    321                         // keeping it out of the expression list 
    322                         if ( m[1] == ":" && m[2] == "not" ) 
    323                                 // optimize if only one selector found (most common case) 
    324                                 r = isSimple.test( m[3] ) ? 
    325                                         jQuery.filter(m[3], r, true).r : 
    326                                         jQuery( r ).not( m[3] ); 
    327  
    328                         // We can get a big speed boost by filtering by class here 
    329                         else if ( m[1] == "." ) 
    330                                 r = jQuery.classFilter(r, m[2], not); 
    331  
    332                         else if ( m[1] == "[" ) { 
    333                                 var tmp = [], type = m[3]; 
     320                        if ( match("attributes") ){ 
     321                                var tmp = [], type = m[3], m2 = m[2], m5 = m[5]; 
    334322                                 
    335323                                for ( var i = 0, rl = r.length; i < rl; i++ ) { 
    336                                         var a = r[i], z = a[ jQuery.props[m[2]] || m[2] ]; 
     324                                        var a = r[i], z = a[ jQuery.props[m2] || m2 ]; 
    337325                                         
    338                                         if ( z == null || /href|src|selected/.test(m[2]) ) 
    339                                                 z = jQuery.attr(a,m[2]) || ''; 
     326                                        if ( z == null || /href|src|selected/.test(m2) ) 
     327                                                z = jQuery.attr(a,m2) || ''; 
    340328 
    341329                                        if ( (type == "" && !!z || 
    342                                                  type == "=" && z == m[5] || 
    343                                                  type == "!=" && z != m[5] || 
    344                                                  type == "^=" && z && !z.indexOf(m[5]) || 
    345                                                  type == "$=" && z.substr(z.length - m[5].length) == m[5] || 
    346                                                  (type == "*=" || type == "~=") && z.indexOf(m[5]) >= 0) ^ not ) 
     330                                                 type == "=" && z == m5 || 
     331                                                 type == "!=" && z != m5 || 
     332                                                 type == "^=" && z && !z.indexOf(m5) || 
     333                                                 type == "$=" && z.substr(z.length - m5.length) == m5 || 
     334                                                 (type == "*=" || type == "~=") && z.indexOf(m5) >= 0) ^ not ) 
    347335                                                        tmp.push( a ); 
    348336                                } 
    349337                                 
    350338                                r = tmp; 
     339                                continue; 
     340                        } 
    351341 
    352                         // We can get a speed boost by handling nth-child here 
    353                         } else if ( m[1] == ":" && m[2] == "nth-child" ) { 
    354                                 var merge = {}, tmp = [], 
    355                                         // parse equations like 'even', 'odd', '5', '2n', '3n+2', '4n-1', '-n+6' 
    356                                         test = /(-?)(\d*)n((?:\+|-)?\d*)/.exec( 
    357                                                 m[3] == "even" && "2n" || m[3] == "odd" && "2n+1" || 
    358                                                 !/\D/.test(m[3]) && "0n+" + m[3] || m[3]), 
    359                                         // calculate the numbers (first)n+(last) including if they are negative 
    360                                         first = (test[1] + (test[2] || 1)) - 0, last = test[3] - 0; 
    361   
    362                                 // loop through all the elements left in the jQuery object 
    363                                 for ( var i = 0, rl = r.length; i < rl; i++ ) { 
    364                                         var node = r[i], parentNode = node.parentNode, id = jQuery.data(parentNode); 
     342                        if ( match("argument") ){ 
     343                                var m2 = m[2], m3 = m[3] 
     344                                // :not() is a special case that can be optimized by 
     345                                // keeping it out of the expression list 
     346                                if ( m2 == "not" ){ 
     347                                        // optimize if only one selector found (most common case) 
     348                                        r = isSimple.test( m3 ) ? 
     349                                                jQuery.filter(m3, r, true).r : 
     350                                                jQuery( r ).not( m3 ); 
     351                                        continue; 
     352                                } 
     353                                // We can get a speed boost by handling nth-child here 
     354                                else if ( m2 == "nth-child" ) { 
     355                                        var merge = {}, tmp = [], 
     356                                                // parse equations like 'even', 'odd', '5', '2n', '3n+2', '4n-1', '-n+6' 
     357                                                test = /(-?)(\d*)n((?:\+|-)?\d*)/.exec( 
     358                                                        m3 == "even" && "2n" || m3 == "odd" && "2n+1" || 
     359                                                        !/\D/.test(m3) && "0n+" + m3 || m3), 
     360                                                // calculate the numbers (first)n+(last) including if they are negative 
     361                                                first = (test[1] + (test[2] || 1)) - 0, last = test[3] - 0; 
     362          
     363                                        // loop through all the elements left in the jQuery object 
     364                                        for ( var i = 0, rl = r.length; i < rl; i++ ) { 
     365                                                var node = r[i], parentNode = node.parentNode, id = jQuery.data(parentNode); 
    365366 
    366                                         if ( !merge[id] ) { 
    367                                                 var c = 1; 
     367                                                if ( !merge[id] ) { 
     368                                                        var c = 1; 
    368369 
    369                                                 for ( var n = parentNode.firstChild; n; n = n.nextSibling ) 
    370                                                         if ( n.nodeType == 1 ) 
    371                                                                 n.nodeIndex = c++; 
     370                                                        for ( var n = parentNode.firstChild; n; n = n.nextSibling ) 
     371                                                                if ( n.nodeType == 1 ) 
     372                                                                        n.nodeIndex = c++; 
    372373 
    373                                                 merge[id] = true; 
    374                                         } 
     374                                                        merge[id] = true; 
     375                                                } 
    375376 
    376                                         var add = false; 
     377                                                var add = false; 
    377378 
    378                                         if ( first == 0 ) { 
    379                                                 if ( node.nodeIndex == last ) 
     379                                                if ( first == 0 ) { 
     380                                                        if ( node.nodeIndex == last ) 
     381                                                                add = true; 
     382                                                } else if ( (node.nodeIndex - last) % first == 0 && (node.nodeIndex - last) / first >= 0 ) 
    380383                                                        add = true; 
    381                                         } else if ( (node.nodeIndex - last) % first == 0 && (node.nodeIndex - last) / first >= 0 ) 
    382                                                 add = true; 
    383384 
    384                                         if ( add ^ not ) 
    385                                                 tmp.push( node ); 
     385                                                if ( add ^ not ) 
     386                                                        tmp.push( node ); 
     387                                        } 
     388 
     389                                        r = tmp; 
     390                                        continue; 
    386391                                } 
     392                        } else { 
     393                                if ( !match("other") ) break; 
    387394 
    388                                 r = tmp; 
     395                                // We can get a big speed boost by filtering by class here 
     396                                if ( m[0].charAt(0) == "." ){ 
     397                                        r = jQuery.classFilter(r, m[2], not); 
     398                                        continue; 
     399                                } 
    389400 
     401                        } 
     402                         
    390403                        // Otherwise, find the expression to execute 
    391                         } else { 
    392                                 var f = jQuery.expr[m[1]]; 
    393                                 if ( typeof f != "string" ) 
    394                                         f = jQuery.expr[m[1]][m[2]]; 
     404                        var k = m[1] 
    395405 
    396                                 // Build a custom macro to enclose it 
    397                                 f = eval("false||function(a,i){return " + f + "}"); 
     406                        if( k == ':' ){ 
     407                                var exprs = jQuery.expr[':']; 
     408                                k = m[2]; f = exprs[k]; 
    398409 
    399                                 // Execute it against the current filter 
    400                                 r = jQuery.grep( r, f, not ); 
    401                         } 
     410                                if( typeof f == "string" ){ 
     411                                  eval("f=function(a,i){return " + f + "}"); 
     412                                  exprs[k] = f; 
     413                                } 
     414                                // Build a custom function to enclose it 
     415                        } else f = jQuery.expr[k]; 
     416 
     417                        // Execute it against the current filter 
     418                        r = jQuery.grep( r, f, not ); 
    402419                } 
    403420 
    404421                // Return an array of filtered elements (r)