Skip to content

Commit b77f62a

Browse files
DanielRufncoden
andcommitted
Use pull request #11393 from DanielRuf/fix/matchmedia-polyfill-window-fix-ie11 for v6.5.0
e7554d6 fix: set matchMedia on window to fix issue on IE11, fixes #11358 1a36a44 chore: update MatchMedia polyfill to v0.3.1 Co-Authored-By: Nicolas Coden <[email protected]> Signed-off-by: Nicolas Coden <[email protected]>
1 parent 94c75e7 commit b77f62a

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

js/foundation.util.mediaQuery.js

+17-11
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ const defaultQueries = {
1717

1818

1919
// matchMedia() polyfill - Test a CSS media type/query in JS.
20-
// Authors & copyright (c) 2012: Scott Jehl, Paul Irish, Nicholas Zakas, David Knight. Dual MIT/BSD license
21-
let matchMedia = window.matchMedia || (function() {
22-
'use strict';
20+
// Authors & copyright(c) 2012: Scott Jehl, Paul Irish, Nicholas Zakas, David Knight. MIT license
21+
/* eslint-disable */
22+
window.matchMedia || (window.matchMedia = (function () {
23+
"use strict";
2324

2425
// For browsers that support matchMedium api such as IE 9 and webkit
2526
var styleMedia = (window.styleMedia || window.media);
@@ -33,14 +34,18 @@ let matchMedia = window.matchMedia || (function() {
3334
style.type = 'text/css';
3435
style.id = 'matchmediajs-test';
3536

36-
script && script.parentNode && script.parentNode.insertBefore(style, script);
37+
if (!script) {
38+
document.head.appendChild(style);
39+
} else {
40+
script.parentNode.insertBefore(style, script);
41+
}
3742

3843
// 'style.currentStyle' is used by IE <= 8 and 'window.getComputedStyle' for all other browsers
3944
info = ('getComputedStyle' in window) && window.getComputedStyle(style, null) || style.currentStyle;
4045

4146
styleMedia = {
42-
matchMedium(media) {
43-
var text = `@media ${media}{ #matchmediajs-test { width: 1px; } }`;
47+
matchMedium: function (media) {
48+
var text = '@media ' + media + '{ #matchmediajs-test { width: 1px; } }';
4449

4550
// 'style.styleSheet' is used by IE <= 8 and 'style.textContent' for all other browsers
4651
if (style.styleSheet) {
@@ -52,16 +57,17 @@ let matchMedia = window.matchMedia || (function() {
5257
// Test if media query is true or false
5358
return info.width === '1px';
5459
}
55-
}
60+
};
5661
}
5762

5863
return function(media) {
5964
return {
6065
matches: styleMedia.matchMedium(media || 'all'),
6166
media: media || 'all'
6267
};
63-
}
64-
})();
68+
};
69+
})());
70+
/* eslint-enable */
6571

6672
var MediaQuery = {
6773
queries: [],
@@ -109,7 +115,7 @@ var MediaQuery = {
109115
var query = this.get(size);
110116

111117
if (query) {
112-
return matchMedia(query).matches;
118+
return window.matchMedia(query).matches;
113119
}
114120

115121
return false;
@@ -160,7 +166,7 @@ var MediaQuery = {
160166
for (var i = 0; i < this.queries.length; i++) {
161167
var query = this.queries[i];
162168

163-
if (matchMedia(query.value).matches) {
169+
if (window.matchMedia(query.value).matches) {
164170
matched = query;
165171
}
166172
}

0 commit comments

Comments
 (0)