lib/SelectorMatchers.js
function(attributeRules, element){
        for(var i = 0; i < attributeRules.length; i++){
            var attributeName = attributeRules[i].name,
                objectToCheck = element;
            if(typeof element.context === 'undefined'){
                //Native DOM node
                if(_.startsWith(attributeName, 'data-')){
                    objectToCheck = element.dataset;
                    attributeName = attributeName.split('-')[1];
                }
            }
            else{
                //React component instance
                objectToCheck = element.props;
            }


            var elementProperty = objectToCheck[attributeName],
                operator = attributeRules[i].operator,
                value = attributeRules[i].value;

            //Only checking for existance, don't care about the value
            if(!operator && elementProperty === undefined){
                return false;
            }

            var doesValueMatch = this.compareElementProperty(elementProperty, operator, value);
            if(!doesValueMatch){
                return false;
            }
        }
        return true;
    }
function(attributeRules, element){
        for(var i = 0; i < attributeRules.length; i++){
            var attributeName = attributeRules[i].name,
                objectToCheck = element;
            if(typeof element.context === 'undefined'){
                //Native DOM node
                if(_.startsWith(attributeName, 'data-')){
                    objectToCheck = element.dataset;
                    attributeName = attributeName.split('-')[1];
                }
            }
            else{
                //React component instance
                objectToCheck = element.props;
            }


            var elementProperty = objectToCheck[attributeName],
                operator = attributeRules[i].operator,
                value = attributeRules[i].value;

            //Only checking for existance, don't care about the value
            if(!operator && elementProperty === undefined){
                return false;
            }

            var doesValueMatch = this.compareElementProperty(elementProperty, operator, value);
            if(!doesValueMatch){
                return false;
            }
        }
        return true;
    }
function ( attributeRules , element ) { for ( var i = 0 ; i < attributeRules . length ; i ++ ) { var attributeName = attributeRules [ i ] . name , objectToCheck = element ; if ( typeof element . context === 'undefined' ) { //Native DOM node if ( _ . startsWith ( attributeName , 'data-' ) ) { objectToCheck = element . dataset ; attributeName = attributeName . split ( '-' ) [ 1 ] ; } } else { //React component instance objectToCheck = element . props ; } var elementProperty = objectToCheck [ attributeName ] , operator = attributeRules [ i ] . operator , value = attributeRules [ i ] . value ; //Only checking for existance, don't care about the value if ( ! operator && elementProperty === undefined ) { return false ; } var doesValueMatch = this . compareElementProperty ( elementProperty , operator , value ) ; if ( ! doesValueMatch ) { return false ; } } return true ; }
Validates if the provided element matches the provided array of
attribute CSS selectors.
@param  {Array} attributeRules Array of attribute rules to check
@param  {Object} element       Element to check
@return {Bool}                 Whether element matches all attribute rules
Validates if the provided element matches the provided array of attribute CSS selectors .