Skip to content

Commit

Permalink
chore: update MatchMedia polyfill to v0.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ncoden committed Jul 11, 2018
1 parent e7554d6 commit 1a36a44
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions js/foundation.util.mediaQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ const defaultQueries = {


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

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

script && script.parentNode && script.parentNode.insertBefore(style, script);
if (!script) {
document.head.appendChild(style);
} else {
script.parentNode.insertBefore(style, script);
}

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

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

// 'style.styleSheet' is used by IE <= 8 and 'style.textContent' for all other browsers
if (style.styleSheet) {
Expand All @@ -52,16 +57,17 @@ window.matchMedia = window.matchMedia || (function() {
// Test if media query is true or false
return info.width === '1px';
}
}
};
}

return function(media) {
return {
matches: styleMedia.matchMedium(media || 'all'),
media: media || 'all'
};
}
})();
};
})());
/* eslint-enable */

var MediaQuery = {
queries: [],
Expand Down

0 comments on commit 1a36a44

Please sign in to comment.