From 279fc9fbc208c3fed3c4232fce89b852f864f0a6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C5=81ukasz?=
Date: Tue, 6 Oct 2015 15:03:12 +0200
Subject: [PATCH 1/4] Fix for IE11 not finding elements
---
src/ElementQueries.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/ElementQueries.js b/src/ElementQueries.js
index 6e7c357..1ca0218 100755
--- a/src/ElementQueries.js
+++ b/src/ElementQueries.js
@@ -179,7 +179,7 @@
}
}
- var regex = /,?([^,\n]*?)\[[\s\t]*?(min|max)-(width|height)[\s\t]*?[~$\^]?=[\s\t]*?"([^"]*?)"[\s\t]*?]([^\n\s\{]*?)/mgi;
+ var regex = /,?([^,\n]+?)\[[\s\t]*?(min|max)-(width|height)[\s\t]*?[~$\^]?=[\s\t]*?"([^"]*?)"[\s\t]*?]([^\n\s\{]*?)/mgi;
/**
* @param {String} css
From b3d344d26830eb6fb05a867bac3f2a9f81411c52 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C2=A3ukasz=20Zdanikowski?=
Date: Wed, 7 Oct 2015 14:36:40 +0200
Subject: [PATCH 2/4] separate selector regex from query regex
---
src/ElementQueries.js | 25 ++++++++++++++++++-------
1 file changed, 18 insertions(+), 7 deletions(-)
diff --git a/src/ElementQueries.js b/src/ElementQueries.js
index 1ca0218..1b26211 100755
--- a/src/ElementQueries.js
+++ b/src/ElementQueries.js
@@ -179,19 +179,30 @@
}
}
- var regex = /,?([^,\n]+?)\[[\s\t]*?(min|max)-(width|height)[\s\t]*?[~$\^]?=[\s\t]*?"([^"]*?)"[\s\t]*?]([^\n\s\{]*?)/mgi;
+ var queryRegex = /\[(min|max)\-(width|height)[\b\~\|\^\$\*]=\"(\w*)\"/mgi;
+ /**
+ * @param {String} css
+ */
+ function extractQuery(selector, css) {
+ var match;
+ while (null !== (match = queryRegex.exec(css))) {
+ if (3 < match.length) {
+ queueQuery(selector, match[1], match[2], match[3]);
+ }
+ }
+ }
+
+ var selectorRegex = /(?:^|)([\.\#\[\]\-\w]*)\[(?:min|max)\-(?:width|height)[\~\|\^\$\*]?=\"\w*\"\](?:[\s,]|[^\]]+\]?([\.\#\-\w\~\|\^\$\*\=\"]+))/mgi;
/**
* @param {String} css
*/
- function extractQuery(css) {
+ function extractSelector(css) {
var match;
- 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]);
+ while (null !== (match = selectorRegex.exec(css))) {
+ if (1 < match.length) {
+ extractQuery(match[1] || match[2], match[0]);
}
}
}
From 41c675425ec7c4b5d044eb88b9ec8ac50450f7ee Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C2=A3ukasz=20Zdanikowski?=
Date: Wed, 7 Oct 2015 15:02:05 +0200
Subject: [PATCH 3/4] Add missing methods invocation
---
src/ElementQueries.js | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/ElementQueries.js b/src/ElementQueries.js
index 1b26211..345e70f 100755
--- a/src/ElementQueries.js
+++ b/src/ElementQueries.js
@@ -218,16 +218,16 @@
if ('string' === typeof rules) {
rules = rules.toLowerCase();
if (-1 !== rules.indexOf('min-width') || -1 !== rules.indexOf('max-width')) {
- extractQuery(rules);
+ extractSelector(rules);
}
} else {
for (var i = 0, j = rules.length; i < j; i++) {
if (1 === rules[i].type) {
selector = rules[i].selectorText || rules[i].cssText;
if (-1 !== selector.indexOf('min-height') || -1 !== selector.indexOf('max-height')) {
- extractQuery(selector);
+ extractSelector(selector);
}else if(-1 !== selector.indexOf('min-width') || -1 !== selector.indexOf('max-width')) {
- extractQuery(selector);
+ extractSelector(selector);
}
} else if (4 === rules[i].type) {
readRules(rules[i].cssRules || rules[i].rules);
From 672313755ae2f13796d9bcdc4c57ac101fad4843 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C2=A3ukasz=20Zdanikowski?=
Date: Thu, 22 Oct 2015 14:19:54 +0200
Subject: [PATCH 4/4] Remove auto initializaton
---
src/ElementQueries.js | 37 +------------------------------------
1 file changed, 1 insertion(+), 36 deletions(-)
diff --git a/src/ElementQueries.js b/src/ElementQueries.js
index 345e70f..69cfa23 100755
--- a/src/ElementQueries.js
+++ b/src/ElementQueries.js
@@ -246,7 +246,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;
@@ -315,39 +315,4 @@
ElementQueries.instance.init(ElementQueries.withTracking);
};
- var domLoaded = function (callback) {
- /* Internet Explorer */
- /*@cc_on
- @if (@_win32 || @_win64)
- document.write('<\/script>');
- document.getElementById('ieScriptLoad').onreadystatechange = function() {
- if (this.readyState == 'complete') {
- callback();
- }
- };
- @end @*/
- /* Mozilla, Chrome, Opera */
- if (document.addEventListener) {
- document.addEventListener('DOMContentLoaded', callback, false);
- }
- /* Safari, iCab, Konqueror */
- if (/KHTML|WebKit|iCab/i.test(navigator.userAgent)) {
- var DOMLoadTimer = setInterval(function () {
- if (/loaded|complete/i.test(document.readyState)) {
- callback();
- clearInterval(DOMLoadTimer);
- }
- }, 10);
- }
- /* Other web browsers */
- window.onload = callback;
- };
-
- if (window.addEventListener) {
- window.addEventListener('load', ElementQueries.init, false);
- } else {
- window.attachEvent('onload', ElementQueries.init);
- }
- domLoaded(ElementQueries.init);
-
})();