Skip to content

Commit c7f8eed

Browse files
author
marcj
committed
Fix for internet explorer
1 parent 9e9efb1 commit c7f8eed

File tree

3 files changed

+43
-20
lines changed

3 files changed

+43
-20
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ This means:
99
- No interval/timeout detection. It's truly event-based.
1010
- No CSS modifications. Valid CSS Syntax.
1111
- All CSS selectors available. It uses the normal attribute selector.
12-
- Support for webkit/gecko/internet explorer.
12+
- Support and tested in webkit, gecko and internet explorer(8/9/10).
1313
- `min-width`, `min-height`, `max-width` and `max-height` are yet supported.
1414
- It works for actual all layout modifications: HTML (innerHTML etc), inline styles, DOM mutation, CSS3 transitions, fluid layout changes (parent changes too), pseudo classes (:hover etc), window resizes, etc.
1515
- No Javascript-Framework dependency, so works with jQuery, Mootools, etc.

src/ElementQueries.js

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,15 @@
141141
* @param {String} value
142142
*/
143143
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);
145153
for (var i = 0, j = elements.length; i < j; i++) {
146154
setupElement(elements[i], {
147155
mode: mode,
@@ -151,32 +159,43 @@
151159
}
152160
}
153161

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;
155163

156164
/**
157-
* @param {CssRule} rule
165+
* @param {String} css
158166
*/
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+
}
163174
}
164175
}
165176

166177
/**
167-
* @param {CssRule[]} rules
178+
* @param {CssRule[]|String} rules
168179
*/
169180
function readRules(rules) {
170181
var selector = '';
171182
if (!rules) {
172183
return;
173184
}
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);
180199
}
181200
}
182201
}
@@ -187,7 +206,7 @@
187206
*/
188207
this.init = function() {
189208
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);
191210
}
192211
}
193212
}

src/ResizeSensor.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
*/
5858
function getComputedStyle(element, prop) {
5959
if (element.currentStyle) {
60-
return element.currentStyle(prop);
60+
return element.currentStyle[prop];
6161
} else if (window.getComputedStyle) {
6262
return window.getComputedStyle(element, null).getPropertyValue(prop);
6363
} else {
@@ -79,12 +79,16 @@
7979
return;
8080
}
8181

82-
if (element.onresize) {
82+
if ('onresize' in element) {
8383
//internet explorer
8484
if (element.attachEvent) {
85-
element.attachEvent('onresize', element.resizedAttached.call);
85+
element.attachEvent('onresize', function() {
86+
element.resizedAttached.call();
87+
});
8688
} else if (element.addEventListener) {
87-
element.addEventListener('resize', element.resizedAttached.call);
89+
element.addEventListener('resize', function(){
90+
element.resizedAttached.call();
91+
});
8892
}
8993
} else {
9094
var myResized = function() {

0 commit comments

Comments
 (0)