-
Notifications
You must be signed in to change notification settings - Fork 324
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into dependabot/npm_and_yarn/www/uglifyjs-webpa…
…ck-plugin-1.2.0
- Loading branch information
Showing
11 changed files
with
206 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// @flow | ||
|
||
// This script checks for browser compatibility and is executed outside React's scope. If a browser | ||
// is incompatible or not optimal for using the app, a pop-up dialog is appended into the DOM body. | ||
// This is so that in cases where the React app completely fails to render anything at all, the | ||
// user will at least be able to see the dialog warning them of the browser incompatibility. | ||
|
||
import bowser from 'bowser'; | ||
import { canUseBrowserLocalStorage } from 'storage/localStorage'; | ||
import styles from './browser.scss'; | ||
|
||
const LOCAL_STORAGE_KEY = 'dismissedBrowserWarning'; | ||
const composeAnchorText = (innerHTML, href) => | ||
`<a href=${href} target="_blank" rel="noopener noreferrer">${innerHTML}</a>`; | ||
const linkForChrome = composeAnchorText('Google Chrome', 'https://www.google.com/chrome/'); | ||
const linkForFirefox = composeAnchorText('Mozilla Firefox', 'https://www.mozilla.org/en-US/'); | ||
const linkForChromePlayStore = composeAnchorText( | ||
'updating your web browser', | ||
'http://play.google.com/store/apps/details?id=com.android.chrome', | ||
); | ||
|
||
const browserCanUseLocalStorage = canUseBrowserLocalStorage(); | ||
|
||
if ( | ||
!bowser.check( | ||
{ | ||
edge: '14', | ||
chrome: '56', | ||
firefox: '52', | ||
safari: '9', | ||
}, | ||
true, | ||
) | ||
) { | ||
if ( | ||
(browserCanUseLocalStorage && !localStorage.getItem(LOCAL_STORAGE_KEY)) || | ||
!browserCanUseLocalStorage | ||
) { | ||
const promptText = (() => { | ||
// Users can only update Safari by updating the OS in iOS | ||
if (bowser.ios) | ||
return `NUSMods may not work properly. Please consider updating your device to iOS 11 or higher.`; | ||
if (bowser.android && bowser.chrome) | ||
return `NUSMods may not work properly. Please consider ${linkForChromePlayStore}.`; | ||
return `NUSMods may not work properly. Please consider updating your web browser or switching to the latest version of ${linkForChrome} or ${linkForFirefox}.`; | ||
})(); | ||
const template = ` | ||
<div class="${styles.modal}"> | ||
<h3>Your web browser is outdated or unsupported</h3> | ||
<p>${promptText}</p> | ||
<div class="form-row align-items-center"> | ||
<div class="col-auto"> | ||
<button class="btn btn-primary" id="browserWarning-continue" type="button">Continue to NUSMods</button> | ||
</div> | ||
${ | ||
// Show "don't show again" only if the browser supports localStorage | ||
browserCanUseLocalStorage | ||
? ` | ||
<div class="col-auto ${styles.checkboxContainer}"> | ||
<div class="form-check form-check-inline"> | ||
<input class="form-check-input" id="browserWarning-ignore" type="checkbox"> | ||
<label class="form-check-label" for="browserWarning-ignore">Don't show this message again</label> | ||
</div> | ||
</div> | ||
` | ||
: '' | ||
} | ||
</div> | ||
</div> | ||
`; | ||
const container = document.createElement('div'); | ||
container.className = styles.browserWarning; | ||
container.innerHTML = template; | ||
const body = document.body; | ||
if (body) body.appendChild(container); | ||
|
||
const element = document.getElementById('browserWarning-continue'); | ||
if (element) { | ||
element.addEventListener('click', () => { | ||
const checkbox = document.getElementById('browserWarning-ignore'); | ||
if (browserCanUseLocalStorage && checkbox && checkbox.checked) | ||
localStorage.setItem(LOCAL_STORAGE_KEY, navigator.userAgent); | ||
if (body) body.removeChild(container); | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
@import '~styles/utils/modules-entry'; | ||
|
||
.browserWarning { | ||
position: fixed; | ||
top: 0; | ||
right: 0; | ||
bottom: 0; | ||
left: 0; | ||
z-index: $browser-warning-z-index; | ||
overflow: hidden; | ||
background: rgba(0, 0, 0, 0.5); | ||
|
||
.modal { | ||
max-width: 48em; | ||
padding: 2em; | ||
margin-right: auto; | ||
margin-left: auto; | ||
background: #fff; | ||
|
||
.checkboxContainer { | ||
padding-top: 0.5em; | ||
padding-bottom: 0.5em; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1341,6 +1341,10 @@ [email protected]: | |
version "4.0.0" | ||
resolved "https://registry.yarnpkg.com/bootstrap/-/bootstrap-4.0.0.tgz#ceb03842c145fcc1b9b4e15da2a05656ba68469a" | ||
|
||
bowser@^1.9.2: | ||
version "1.9.2" | ||
resolved "https://registry.yarnpkg.com/bowser/-/bowser-1.9.2.tgz#d66fc868ca5f4ba895bee1363c343fe7b37d3394" | ||
|
||
brace-expansion@^1.0.0, brace-expansion@^1.1.7: | ||
version "1.1.8" | ||
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.8.tgz#c07b211c7c952ec1f8efd51a77ef0d1d3990a292" | ||
|
@@ -2940,9 +2944,9 @@ eslint-visitor-keys@^1.0.0: | |
version "1.0.0" | ||
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz#3f3180fb2e291017716acb4c9d6d5b5c34a6a81d" | ||
|
||
eslint@^4.17.0: | ||
version "4.17.0" | ||
resolved "https://registry.yarnpkg.com/eslint/-/eslint-4.17.0.tgz#dc24bb51ede48df629be7031c71d9dc0ee4f3ddf" | ||
eslint@^4.18.0: | ||
version "4.18.0" | ||
resolved "https://registry.yarnpkg.com/eslint/-/eslint-4.18.0.tgz#ebd0ba795af6dc59aa5cee17938160af5950e051" | ||
dependencies: | ||
ajv "^5.3.0" | ||
babel-code-frame "^6.22.0" | ||
|
@@ -6409,12 +6413,12 @@ postcss-convert-values@^2.3.4: | |
postcss "^5.0.11" | ||
postcss-value-parser "^3.1.2" | ||
|
||
postcss-custom-properties@^6.2.0: | ||
version "6.2.0" | ||
resolved "https://registry.yarnpkg.com/postcss-custom-properties/-/postcss-custom-properties-6.2.0.tgz#5d929a7f06e9b84e0f11334194c0ba9a30acfbe9" | ||
postcss-custom-properties@^7.0.0: | ||
version "7.0.0" | ||
resolved "https://registry.yarnpkg.com/postcss-custom-properties/-/postcss-custom-properties-7.0.0.tgz#24dc4fbe6d6ed550ea4fd3b11204660e9ffa3b33" | ||
dependencies: | ||
balanced-match "^1.0.0" | ||
postcss "^6.0.13" | ||
postcss "^6.0.18" | ||
|
||
postcss-discard-comments@^2.0.4: | ||
version "2.0.4" | ||
|
@@ -6744,6 +6748,14 @@ postcss@^6.0.17: | |
source-map "^0.6.1" | ||
supports-color "^5.1.0" | ||
|
||
postcss@^6.0.18: | ||
version "6.0.19" | ||
resolved "https://registry.yarnpkg.com/postcss/-/postcss-6.0.19.tgz#76a78386f670b9d9494a655bf23ac012effd1555" | ||
dependencies: | ||
chalk "^2.3.1" | ||
source-map "^0.6.1" | ||
supports-color "^5.2.0" | ||
|
||
prelude-ls@~1.1.2: | ||
version "1.1.2" | ||
resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54" | ||
|