jQuery: The Write Less, Do More JavaScript Library

Changeset 5500

Show
Ignore:
Timestamp:
05/08/08 16:14:49 (4 days ago)
Author:
aflesler
Message:

jquery core: closes #2771
$.inArray now makes a === check because of IE.
$.inArray is used in $.fn.index, this is shorter, and breaks the loop when possible.
$.fn.index can receive a jquery object, and the first element is used

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/jquery/src/core.js

    r5481 r5500  
    141141 
    142142        // Locate the position of the desired element 
    143         this.each(function(i){ 
    144             if ( this == elem ) 
    145                 ret = i; 
    146         }); 
    147  
    148         return ret; 
     143        return jQuery.inArray(  
     144            // If it receives a jQuery object, the first element is used 
     145            elem && elem.jquery ? elem[0] : elem 
     146        , this ); 
    149147    }, 
    150148 
     
    11251123    inArray: function( elem, array ) { 
    11261124        for ( var i = 0, length = array.length; i < length; i++ ) 
    1127             if ( array[ i ] == elem ) 
     1125        // Use === because on IE, window == document 
     1126            if ( array[ i ] === elem ) 
    11281127                return i; 
    11291128