diff options
| author | meow <woem> | 2022-05-16 13:13:00 +0300 |
|---|---|---|
| committer | meow <woem> | 2022-05-16 13:13:00 +0300 |
| commit | e18b10297b259460a3219edfeb9ccd0fabc34270 (patch) | |
| tree | c48de0cc79b11bbbc5ea6a4d10385ac61ef9434f /assets/js/_helpers.js | |
| parent | fd66084388399319993e9aaa0a15ba3ed5498404 (diff) | |
| download | invidious-e18b10297b259460a3219edfeb9ccd0fabc34270.tar.gz invidious-e18b10297b259460a3219edfeb9ccd0fabc34270.tar.bz2 invidious-e18b10297b259460a3219edfeb9ccd0fabc34270.zip | |
JS fixes: recursion in themes, keys for frame walking, JSON XHR and details-summary in IE11
Diffstat (limited to 'assets/js/_helpers.js')
| -rw-r--r-- | assets/js/_helpers.js | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/assets/js/_helpers.js b/assets/js/_helpers.js index 3f79bf54..448e95d1 100644 --- a/assets/js/_helpers.js +++ b/assets/js/_helpers.js @@ -23,6 +23,20 @@ Math.sign = Math.sign || function(x) { if (!x) return x; // 0 and NaN return x > 0 ? 1 : -1; }; +if (!window.hasOwnProperty('HTMLDetailsElement') && !window.hasOwnProperty('mockHTMLDetailsElement')) { + window.mockHTMLDetailsElement = true; + const style = 'details:not([open]) > :not(summary) {display: none}'; + document.head.appendChild(document.createElement('style')).textContent = style; + + addEventListener('click', function (e) { + if (e.target.nodeName !== 'SUMMARY') return; + const details = e.target.parentElement; + if (details.hasAttribute('open')) + details.removeAttribute('open'); + else + details.setAttribute('open', ''); + }); +} // Monstrous global variable for handy code window.helpers = window.helpers || { @@ -65,8 +79,13 @@ window.helpers = window.helpers || { // better than onreadystatechange because of 404 codes https://stackoverflow.com/a/36182963 xhr.onloadend = function () { if (xhr.status === 200) { - if (callbacks.on200) - callbacks.on200(xhr.response); + if (callbacks.on200) { + // fix for IE11. It doesn't convert response to JSON + if (xhr.responseType === '' && typeof(xhr.response) === 'string') + callbacks.on200(JSON.parse(xhr.response)); + else + callbacks.on200(xhr.response); + } } else { // handled by onerror if (xhr.status === 0) return; |
