Skip to content
This repository was archived by the owner on Oct 29, 2020. It is now read-only.

Commit 02b0141

Browse files
committed
Conditionally load polyfill code based on feature detection.
1 parent a1a4382 commit 02b0141

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

lib/themes/dosomething/paraneue_dosomething/js/main.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,21 @@ define("main", function(require) {
4141
// let's get going
4242
var $ = window.jQuery;
4343
var Finder = require("finder/Finder");
44+
var Features = require("utils/features");
45+
4446

45-
require("neue/main");
4647

4748
// Load polyfills
48-
require("respond");
49-
require("rem-unit-polyfill");
49+
if(!Features.mediaQueries) {
50+
require("respond");
51+
}
52+
53+
if(!Features.remUnits) {
54+
require("rem-unit-polyfill");
55+
}
5056

5157
// Initialize modules on load
58+
require("neue/main");
5259
require("campaign/sources");
5360
require("campaign/tips");
5461
require("campaign/ImageUploader");
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* @module utils/Features
3+
* Methods to test browser support.
4+
*/
5+
define(function() {
6+
"use strict";
7+
8+
/**
9+
* Checks if media queries are supported by the browser.
10+
* @see https://github.com/scottjehl/Respond/blob/master/src/respond.js#L68
11+
*
12+
* @returns {Boolean} Browser support for media queries.
13+
*/
14+
var mediaQueries = function() {
15+
return window.matchMedia && window.matchMedia("only all") !== null && window.matchMedia("only all").matches;
16+
};
17+
18+
/**
19+
* Checks if REM units are supported by the browser.
20+
* @see https://github.com/chuckcarpenter/REM-unit-polyfill/blob/master/js/rem.js#L4-L9
21+
*
22+
* @returns {Boolean} Browser support for REM units.
23+
*/
24+
var remUnits = function() {
25+
var div = document.createElement("div");
26+
div.style.cssText = "font-size: 1rem;";
27+
28+
return (/rem/).test(div.style.fontSize);
29+
};
30+
31+
32+
// Export API
33+
return {
34+
mediaQueries: mediaQueries,
35+
remUnits: remUnits
36+
};
37+
});

0 commit comments

Comments
 (0)