sizzle分析記錄: 自定義僞類選擇器

可見性

隱藏對象沒有寬高,前提是用display:none處理的html

jQuery.expr.filters.hidden = function( elem ) {
    // Support: Opera <= 12.12
    // Opera reports offsetWidths and offsetHeights less than zero on some elements
    return elem.offsetWidth <= 0 && elem.offsetHeight <= 0;
};
jQuery.expr.filters.visible = function( elem ) {
    return !jQuery.expr.filters.hidden( elem );
};

 

內容

獲取文本內容經過indexOf匹配node

"contains": markFunction(function( text ) {
    return function( elem ) {
        return ( elem.textContent || elem.innerText || getText( elem ) ).indexOf( text ) > -1;
    };
}),

 

取空jquery

遞歸這個節點,排除nodeType大於6的節點app

// Contents
"empty": function( elem ) {
    // http://www.w3.org/TR/selectors/#empty-pseudo
    // :empty is negated by element (1) or content nodes (text: 3; cdata: 4; entity ref: 5),
    //   but not by others (comment: 8; processing instruction: 7; etc.)
    // nodeType < 6 works because attributes (2) do not appear as children
    for ( elem = elem.firstChild; elem; elem = elem.nextSibling ) {
        if ( elem.nodeType < 6 ) {
            return false;
        }
    }
    return true;
},

 

查看包含less

遞歸sizzle經過傳遞上下文對象,實現包含查找ui

"has": markFunction(function( selector ) {
    return function( elem ) {
        return Sizzle( selector, elem ).length > 0;
    };
}),

 

匹配含有子元素或者文本的元素spa

"parent": function( elem ) {
    return !Expr.pseudos["empty"]( elem );
},
相關文章
相關標籤/搜索