forked from IET-OU/our-journey
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug IET-OU#7, add
./compat
Javascript checker [iet:10364720]
* Executed on JS include, not in `require().app.run()`
- Loading branch information
Showing
3 changed files
with
66 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* Browser compatibility | ©The Open University. | ||
*/ | ||
|
||
module.exports.check = checkAndHandle; | ||
|
||
const UA = window.navigator.userAgent; | ||
const DOC = window.document; | ||
const LOC = window.location; | ||
const NO_COMPAT_MSG = [ | ||
// '<style> .ojs-error { color: #a00; } </style>', | ||
'<div class="X-ojs-error alert alert-danger" role="alert">', | ||
' <p>Sorry! <i>our-journey</i> does not work on Internet Explorer.</p>', | ||
' <p><a href="https://browsehappy.com">Try a different browser — Browse Happy</a></p>', | ||
'</div>' | ||
]; | ||
const COMPAT_REGEX = /(MSIE|Trident\/)/; // Live! | ||
// const COMPAT_REGEX = /(MSIE|Trident\/|Chrome)/; // Test! | ||
|
||
function checkAndHandle () { | ||
const IS_COMPAT = (!COMPAT_REGEX.test(UA) || /compatCheck=false/.test(LOC.href)); | ||
|
||
if (IS_COMPAT) { | ||
console.warn('our-journey. Browser is compatible'); | ||
} else { | ||
// console.error('our-journey. Browser NOT compatible (MSIE ?)'); | ||
|
||
notCompatibleMessage(); | ||
|
||
tryHideContainer(); | ||
|
||
let err = new Error('our-journey. Browser NOT compatible (MSIE ?)'); | ||
err.name = 'CompatError'; | ||
throw err; | ||
} | ||
|
||
return IS_COMPAT; | ||
} | ||
|
||
function notCompatibleMessage () { | ||
// const CTR = UTIL.config('container'); | ||
const DIV = DOC.createElement('div'); | ||
|
||
DIV.innerHTML = NO_COMPAT_MSG.join('\n'); | ||
DIV.className = 'our-journey-js ojs-error ojs-no-compat ojs-msie'; | ||
|
||
DOC.body.insertBefore(DIV, DOC.body.firstChild); // Was: DOC.body.appendChild(CTR); | ||
} | ||
|
||
function tryHideContainer () { | ||
// We can't use UTIL.config('container') here, so guess! | ||
const TRY_CTR = DOC.querySelector('#our-journey-tool'); | ||
|
||
if (TRY_CTR) { | ||
TRY_CTR.style.display = 'none'; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -207,3 +207,7 @@ img[ src $= 'assets/iet-logo.svg' ] { | |
margin-right: 16px; | ||
padding: 5px; | ||
} | ||
|
||
.ojs-error { | ||
colour: #a00; | ||
} |