diff --git a/src/ElementQueries.js b/src/ElementQueries.js index 6e7c357..fccd4b6 100755 --- a/src/ElementQueries.js +++ b/src/ElementQueries.js @@ -179,8 +179,8 @@ } } - var regex = /,?([^,\n]*?)\[[\s\t]*?(min|max)-(width|height)[\s\t]*?[~$\^]?=[\s\t]*?"([^"]*?)"[\s\t]*?]([^\n\s\{]*?)/mgi; - + var regex = /,?[\s\t]*([^,\n]*?)((?:\[[\s\t]*?(?:min|max)-(?:width|height)[\s\t]*?[~$\^]?=[\s\t]*?"[^"]*?"[\s\t]*?])+)([^,\n\s\{]*)/mgi; + var attrRegex = /\[[\s\t]*?(min|max)-(width|height)[\s\t]*?[~$\^]?=[\s\t]*?"([^"]*?)"[\s\t]*?]/mgi; /** * @param {String} css */ @@ -189,9 +189,11 @@ var smatch; css = css.replace(/'/g, '"'); while (null !== (match = regex.exec(css))) { - if (5 < match.length) { - smatch = match[1] || match[5] || smatch; - queueQuery(smatch, match[2], match[3], match[4]); + smatch = match[1] + match[3]; + attrs = match[2]; + + while (null !== (attrMatch = attrRegex.exec(attrs))) { + queueQuery(smatch, attrMatch[1], attrMatch[2], attrMatch[3]); } } } @@ -235,7 +237,7 @@ this.withTracking = withTracking; for (var i = 0, j = document.styleSheets.length; i < j; i++) { try { - readRules(document.styleSheets[i].cssText || document.styleSheets[i].cssRules || document.styleSheets[i].rules); + readRules(document.styleSheets[i].cssRules || document.styleSheets[i].rules || document.styleSheets[i].cssText); } catch(e) { if (e.name !== 'SecurityError') { throw e;