@@ -125,11 +125,23 @@ axs.AuditRule.prototype.addElement = function(elements, element) {
125125 * @param {Node } scope
126126 * @param {function(Element): boolean } matcher
127127 * @param {Array.<Element> } collection
128+ * @param {Array.<string>= } opt_ignoreSelectors
128129 */
129- axs . AuditRule . collectMatchingElements = function ( scope , matcher , collection ) {
130+ axs . AuditRule . collectMatchingElements = function ( scope , matcher , collection , opt_ignoreSelectors ) {
131+ /**
132+ * @param {!Element } element
133+ * @return boolean
134+ */
130135 function relevantElementCollector ( element ) {
136+ if ( opt_ignoreSelectors ) {
137+ for ( var i = 0 ; i < opt_ignoreSelectors . length ; i ++ ) {
138+ if ( axs . browserUtils . matchSelector ( element , opt_ignoreSelectors [ i ] ) )
139+ return false ;
140+ }
141+ }
131142 if ( matcher ( element ) )
132143 collection . push ( element ) ;
144+ return true ;
133145 }
134146 axs . dom . composedTreeSearch ( scope , null , { preorder : relevantElementCollector } ) ;
135147} ;
@@ -149,30 +161,21 @@ axs.AuditRule.collectMatchingElements = function(scope, matcher, collection) {
149161 */
150162axs . AuditRule . prototype . run = function ( options ) {
151163 options = options || { } ;
152- var ignoreSelectors = 'ignoreSelectors' in options ? options [ 'ignoreSelectors' ] : [ ] ;
153164 var scope = 'scope' in options ? options [ 'scope' ] : document ;
154165 var maxResults = 'maxResults' in options ? options [ 'maxResults' ] : null ;
155166
156167 var relevantElements = [ ] ;
157- axs . AuditRule . collectMatchingElements ( scope , this . relevantElementMatcher_ , relevantElements ) ;
168+ axs . AuditRule . collectMatchingElements ( scope , this . relevantElementMatcher_ , relevantElements , options [ 'ignoreSelectors' ] ) ;
158169
159170 var failingElements = [ ] ;
160171
161- function ignored ( element ) {
162- for ( var i = 0 ; i < ignoreSelectors . length ; i ++ ) {
163- if ( axs . browserUtils . matchSelector ( element , ignoreSelectors [ i ] ) )
164- return true ;
165- }
166- return false ;
167- }
168-
169172 if ( ! relevantElements . length )
170173 return { result : axs . constants . AuditResult . NA } ;
171174 for ( var i = 0 ; i < relevantElements . length ; i ++ ) {
172175 if ( maxResults != null && failingElements . length >= maxResults )
173176 break ;
174177 var element = relevantElements [ i ] ;
175- if ( ! ignored ( element ) && this . test_ ( element , options . config ) )
178+ if ( this . test_ ( element , options . config ) )
176179 this . addElement ( failingElements , element ) ;
177180 }
178181 var result = failingElements . length ? axs . constants . AuditResult . FAIL : axs . constants . AuditResult . PASS ;
0 commit comments