Skip to content

Commit e2c046a

Browse files
committed
Added matchmedia.js (https://github.com/paulirish/matchMedia.js/) to allows support for IE9.
1 parent a7d10fb commit e2c046a

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

js/matchmedia.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*! 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 */
2+
3+
window.matchMedia || (window.matchMedia = function() {
4+
"use strict";
5+
6+
// For browsers that support matchMedium api such as IE 9 and webkit
7+
var styleMedia = (window.styleMedia || window.media);
8+
9+
// For those that don't support matchMedium
10+
if (!styleMedia) {
11+
var style = document.createElement('style'),
12+
script = document.getElementsByTagName('script')[0],
13+
info = null;
14+
15+
style.type = 'text/css';
16+
style.id = 'matchmediajs-test';
17+
18+
script.parentNode.insertBefore(style, script);
19+
20+
// 'style.currentStyle' is used by IE <= 8 and 'window.getComputedStyle' for all other browsers
21+
info = ('getComputedStyle' in window) && window.getComputedStyle(style, null) || style.currentStyle;
22+
23+
styleMedia = {
24+
matchMedium: function(media) {
25+
var text = '@media ' + media + '{ #matchmediajs-test { width: 1px; } }';
26+
27+
// 'style.styleSheet' is used by IE <= 8 and 'style.textContent' for all other browsers
28+
if (style.styleSheet) {
29+
style.styleSheet.cssText = text;
30+
} else {
31+
style.textContent = text;
32+
}
33+
34+
// Test if media query is true or false
35+
return info.width === '1px';
36+
}
37+
};
38+
}
39+
40+
return function(media) {
41+
return {
42+
matches: styleMedia.matchMedium(media || 'all'),
43+
media: media || 'all'
44+
};
45+
};
46+
}());

wp-tevko-responsive-images.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
// First we queue the polyfill
1515
function tevkori_get_picturefill() {
1616
wp_enqueue_script( 'picturefill', plugins_url( '/js/picturefill.js', __FILE__ ) );
17+
wp_enqueue_script( 'matchmedia', plugins_url( '/js/matchmedia.js', __FILE__ ) );
1718
}
1819
add_action( 'wp_enqueue_scripts', 'tevkori_get_picturefill' );
1920

0 commit comments

Comments
 (0)