|
74 | 74 | }
|
75 | 75 | }
|
76 | 76 |
|
| 77 | + var attributes = ['min-width', 'min-height', 'max-width', 'max-height']; |
| 78 | + |
77 | 79 | /**
|
78 | 80 | *
|
79 | 81 | * @param {HTMLElement} element
|
|
92 | 94 | this.options[idx] = option;
|
93 | 95 | };
|
94 | 96 |
|
95 |
| - var attributes = ['min-width', 'min-height', 'max-width', 'max-height']; |
96 | 97 |
|
97 | 98 | /**
|
98 | 99 | * Extracts the computed width/height and sets to min/max- attribute.
|
|
350 | 351 | }
|
351 | 352 | if ('string' === typeof rules) {
|
352 | 353 | rules = rules.toLowerCase();
|
353 |
| - if (-1 !== rules.indexOf('min-width') || -1 !== rules.indexOf('max-width')) { |
| 354 | + if (isElementQuery(rules)) { |
354 | 355 | extractQuery(rules);
|
355 | 356 | }
|
356 | 357 | } else {
|
357 |
| - for (var i = 0, j = rules.length; i < j; i++) { |
358 |
| - if (1 === rules[i].type) { |
359 |
| - selector = rules[i].selectorText || rules[i].cssText; |
360 |
| - if (-1 !== selector.indexOf('min-height') || -1 !== selector.indexOf('max-height')) { |
361 |
| - extractQuery(selector); |
362 |
| - }else if(-1 !== selector.indexOf('min-width') || -1 !== selector.indexOf('max-width')) { |
363 |
| - extractQuery(selector); |
364 |
| - } |
365 |
| - } else if (4 === rules[i].type) { |
366 |
| - readRules(rules[i].cssRules || rules[i].rules); |
367 |
| - } else if (3 === rules[i].type) { // CSSRule.IMPORT_RULE |
368 |
| - readRules(rules[i].styleSheet.cssRules); |
| 358 | + for (var i = 0, j = rules.length, r; i < j; i++) { |
| 359 | + r = rules[i]; |
| 360 | + switch (r.type) { |
| 361 | + case 1: // CSSRule.STYLE_RULE |
| 362 | + selector = r.selectorText || r.cssText; |
| 363 | + if (isElementQuery(selector)) { |
| 364 | + extractQuery(selector); |
| 365 | + } |
| 366 | + break; |
| 367 | + case 3: // CSSRule.IMPORT_RULE |
| 368 | + r = r.styleSheet; // then continue to next case statement |
| 369 | + case 4: // CSSRule.MEDIA_RULE |
| 370 | + readRules(r.cssRules || r.rules); |
| 371 | + break; |
369 | 372 | }
|
370 | 373 | }
|
371 | 374 | }
|
372 | 375 | }
|
373 | 376 |
|
| 377 | + |
| 378 | + function isElementQuery(s) { |
| 379 | + for (var i in attributes) { |
| 380 | + if (-1 !== s.indexOf(attributes[i])) return true; |
| 381 | + } |
| 382 | + } |
| 383 | + |
374 | 384 | var defaultCssInjected = false;
|
375 | 385 |
|
376 | 386 | /**
|
|
0 commit comments