File tree Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Original file line number Diff line number Diff line change 177
177
if ( typeof ( allQueries [ mode ] ) == 'undefined' ) allQueries [ mode ] = { } ;
178
178
if ( typeof ( allQueries [ mode ] [ property ] ) == 'undefined' ) allQueries [ mode ] [ property ] = { } ;
179
179
if ( typeof ( allQueries [ mode ] [ property ] [ value ] ) == 'undefined' ) allQueries [ mode ] [ property ] [ value ] = selector ;
180
- else allQueries [ mode ] [ property ] [ value ] += ',' + selector ;
180
+ else if ( typeof selector === 'string' ) {
181
+ // To build a regex from the selector we need to escape it first. The following function
182
+ // is given on MDN: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions
183
+ var escapedSelector = selector . replace ( / [ . * + ? ^ $ { } ( ) | [ \] \\ ] / g, '\\$&' ) ;
184
+
185
+ // MATCHES full selector at the beginning, at the end, or somewhere inside the string.
186
+ // DOES NOT MATCH if it acts as a subselector or super selector.
187
+ var hasSelectorRegex = new RegExp (
188
+ '(^' + escapedSelector + ',)|' +
189
+ '(,' + escapedSelector + ',)|' +
190
+ '(,' + escapedSelector + '$)|' +
191
+ '(^' + escapedSelector + '$)'
192
+ ) ;
193
+
194
+ // Add the selector only if it is not already present
195
+ if ( ! hasSelectorRegex . test ( allQueries [ mode ] [ property ] [ value ] ) ) {
196
+ allQueries [ mode ] [ property ] [ value ] += ',' + selector ;
197
+ }
198
+ }
181
199
}
182
200
183
201
function getQuery ( ) {
You can’t perform that action at this time.
0 commit comments