|
141 | 141 | * @param {String} value
|
142 | 142 | */
|
143 | 143 | function queueQuery(selector, mode, property, value) {
|
144 |
| - var elements = document.querySelectorAll(selector); |
| 144 | + var query = document.querySelectorAll; |
| 145 | + if ('undefined' !== typeof $$) query = $$; |
| 146 | + if ('undefined' !== typeof jQuery) query = jQuery; |
| 147 | + |
| 148 | + if (!query) { |
| 149 | + throw 'No document.querySelectorAll, jQuery or Mootools\'s $$ found.'; |
| 150 | + } |
| 151 | + |
| 152 | + var elements = query(selector); |
145 | 153 | for (var i = 0, j = elements.length; i < j; i++) {
|
146 | 154 | setupElement(elements[i], {
|
147 | 155 | mode: mode,
|
|
151 | 159 | }
|
152 | 160 | }
|
153 | 161 |
|
154 |
| - var regex = /,*([^,]*)\[[\s\t]*(min|max)-(width|height)[\s\t]*[~$\^]?=[\s\t]*"([^"]*)"[\s\t]*]/; |
| 162 | + var regex = /,?([^,\n]*)\[[\s\t]*(min|max)-(width|height)[\s\t]*[~$\^]?=[\s\t]*"([^"]*)"[\s\t]*]([^\n\s\{]*)/mgi; |
155 | 163 |
|
156 | 164 | /**
|
157 |
| - * @param {CssRule} rule |
| 165 | + * @param {String} css |
158 | 166 | */
|
159 |
| - function extractQuery(rule) { |
160 |
| - var matches = regex.exec(rule.selectorText); |
161 |
| - if (matches && 5 === matches.length) { |
162 |
| - queueQuery(matches[1], matches[2], matches[3], matches[4]); |
| 167 | + function extractQuery(css) { |
| 168 | + var match; |
| 169 | + css = css.replace(/'/g, '"'); |
| 170 | + while (null !== (match = regex.exec(css))) { |
| 171 | + if (5 < match.length) { |
| 172 | + queueQuery(match[1] || match[5], match[2], match[3], match[4]); |
| 173 | + } |
163 | 174 | }
|
164 | 175 | }
|
165 | 176 |
|
166 | 177 | /**
|
167 |
| - * @param {CssRule[]} rules |
| 178 | + * @param {CssRule[]|String} rules |
168 | 179 | */
|
169 | 180 | function readRules(rules) {
|
170 | 181 | var selector = '';
|
171 | 182 | if (!rules) {
|
172 | 183 | return;
|
173 | 184 | }
|
174 |
| - for (var i = 0, j = rules.length; i < j; i++) { |
175 |
| - if (1 === rules[i].type) { |
176 |
| - selector = rules[i].selectorText; |
177 |
| - if (-1 !== selector.indexOf('min-width') || -1 !== selector.indexOf('max-width')) { |
178 |
| - extractQuery(rules[i]); |
179 |
| - //todo, ie7-8 includes @imports in a rule, so extract it |
| 185 | + if ('string' === typeof rules) { |
| 186 | + rules = rules.toLowerCase(); |
| 187 | + if (-1 !== rules.indexOf('min-width') || -1 !== rules.indexOf('max-width')) { |
| 188 | + extractQuery(rules); |
| 189 | + } |
| 190 | + } else { |
| 191 | + for (var i = 0, j = rules.length; i < j; i++) { |
| 192 | + if (1 === rules[i].type) { |
| 193 | + selector = rules[i].selectorText || rules[i].cssText; |
| 194 | + if (-1 !== selector.indexOf('min-width') || -1 !== selector.indexOf('max-width')) { |
| 195 | + extractQuery(selector); |
| 196 | + } |
| 197 | + } else if (4 === rules[i].type) { |
| 198 | + readRules(rules[i].cssRules || rules[i].rules); |
180 | 199 | }
|
181 | 200 | }
|
182 | 201 | }
|
|
187 | 206 | */
|
188 | 207 | this.init = function() {
|
189 | 208 | for (var i = 0, j = document.styleSheets.length; i < j; i++) {
|
190 |
| - readRules(document.styleSheets[i].cssRules || document.styleSheets[i].rules); |
| 209 | + readRules(document.styleSheets[i].cssText || document.styleSheets[i].cssRules || document.styleSheets[i].rules); |
191 | 210 | }
|
192 | 211 | }
|
193 | 212 | }
|
|
0 commit comments