From 9ecbccf167b8c463e18f9224ceeca040bbd1217d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=B4=9C=C9=B4=D0=B2=CA=8F=D1=82=E1=B4=87?= Date: Thu, 22 Oct 2020 21:58:42 +0800 Subject: [PATCH] ui: fix browser compatibility check (#776) - remove experimental API in checkBrowser.js - polyfill for Object.entries --- ui/gulpfile.esm.js | 2 +- ui/public/{checkBrowser.js => compat.js} | 19 ++++++++++++++++++- ui/public/diagnoseReport.html | 2 +- ui/public/index.html | 2 +- 4 files changed, 21 insertions(+), 4 deletions(-) rename ui/public/{checkBrowser.js => compat.js} (82%) diff --git a/ui/gulpfile.esm.js b/ui/gulpfile.esm.js index 8b0b3ab89d..6af6beb95c 100644 --- a/ui/gulpfile.esm.js +++ b/ui/gulpfile.esm.js @@ -59,7 +59,7 @@ function updateBrowserList() { } task('gen:browserlist', () => { - return src('public/checkBrowser.js') + return src('public/compat.js') .pipe(updateBrowserList()) .pipe(dest('public', { overwrite: true })) }) diff --git a/ui/public/checkBrowser.js b/ui/public/compat.js similarity index 82% rename from ui/public/checkBrowser.js rename to ui/public/compat.js index 786e2c6604..ba54664c7a 100644 --- a/ui/public/checkBrowser.js +++ b/ui/public/compat.js @@ -40,8 +40,25 @@ function checkBrowser() { d.getElementsByTagName('a')[0].onclick = function () { d.getElementsByTagName('div')[0].style.top = '-60px' } - document.body.prepend(d) + document.body.insertBefore(d, document.body.firstChild) } } checkBrowser() + +// Dealing with compatibility issues manually for special cases + +// Object.entries +// see https://github.com/pingcap-incubator/tidb-dashboard/issues/770 +// polyfill from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries +if (!Object.entries) { + Object.entries = function( obj ){ + var ownProps = Object.keys( obj ), + i = ownProps.length, + resArray = new Array(i); // preallocate the Array + while (i--) + resArray[i] = [ownProps[i], obj[ownProps[i]]]; + + return resArray; + }; +} diff --git a/ui/public/diagnoseReport.html b/ui/public/diagnoseReport.html index 6114d4ae8a..aed243ffda 100644 --- a/ui/public/diagnoseReport.html +++ b/ui/public/diagnoseReport.html @@ -10,7 +10,7 @@ - +
diff --git a/ui/public/index.html b/ui/public/index.html index 08a29e991d..750c0f265c 100644 --- a/ui/public/index.html +++ b/ui/public/index.html @@ -91,7 +91,7 @@ - +