|
| 1 | +(function () { |
| 2 | + // Add JavaScript feature as class to the <html> element, just like |
| 3 | + // Modernizr does. This is needed for accessibility reasons, to support |
| 4 | + // browsers and situations where JavaScript is not available or disabled. |
| 5 | + // The HTML root tag needs to have the `no-js` class set which is then |
| 6 | + // replaced by `js`. |
| 7 | + const html = document.getElementsByTagName("html")[0]; |
| 8 | + if (html.classList.contains("no-js")) { |
| 9 | + html.classList.remove("no-js"); |
| 10 | + html.classList.add("js"); |
| 11 | + } |
| 12 | + |
| 13 | + // Do not load modernizr if disabled. It's enabled by default. |
| 14 | + // You might want to disable it for your project by setting: |
| 15 | + // window.__patternslib_disable_modernizr = true; |
| 16 | + if (window.__patternslib_disable_modernizr) { |
| 17 | + return; |
| 18 | + } |
| 19 | + |
| 20 | + // Get the current script tag's URL. |
| 21 | + // See: https://stackoverflow.com/a/984656/1337474 |
| 22 | + const scripts = document.getElementsByTagName("script"); |
| 23 | + const script = scripts[scripts.length - 1]; |
| 24 | + let script_url = script.src; |
| 25 | + // Get the base URL of the current script tag's URL. |
| 26 | + script_url = script_url.substring(0, script_url.lastIndexOf("/")) + "/"; |
| 27 | + |
| 28 | + // Inject a new one with the modernizr bundle. |
| 29 | + const script_tag = document.createElement("script"); |
| 30 | + script_tag.src = script_url + "modernizr.min.js"; |
| 31 | + document.getElementsByTagName("head")[0].appendChild(script_tag); |
| 32 | +})(); |
0 commit comments