FEATURE: Show noscript view to unsupported browsers (#9373)

This commit is contained in:
Dan Ungureanu 2020-04-08 20:24:18 +03:00 committed by GitHub
parent e1f8014acd
commit 73d71e3fee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 26 additions and 12 deletions

View File

@ -0,0 +1,3 @@
if (!window.WeakMap || !window.Promise) {
window.unsupportedBrowser = true;
}

View File

@ -6,6 +6,10 @@ import discourseComputed, { observes } from "discourse-common/utils/decorators";
import FocusEvent from "discourse-common/mixins/focus-event";
import deprecated from "discourse-common/lib/deprecated";
if (window.unsupportedBrowser) {
throw "Unsupported browser detected";
}
const _pluginCallbacks = [];
const Discourse = Application.extend(FocusEvent, {

View File

@ -19,6 +19,8 @@
<%= build_plugin_html 'server:before-script-load' %>
<%= preload_script 'browser-detect' %>
<%= preload_script "locales/#{I18n.locale}" %>
<%- if ExtraLocalesController.client_overrides_exist? %>
<%= preload_script_url ExtraLocalesController.url('overrides') %>

View File

@ -135,6 +135,7 @@ module Discourse
vendor.js
admin.js
preload-store.js
browser-detect.js
browser-update.js
break_string.js
ember_jquery.js

View File

@ -1,4 +1,4 @@
en:
site_settings:
discourse_internet_explorer_enabled: "Internet Explorer support"
discourse_internet_explorer_enabled: "Enable temporary Internet Explorer support. This plugin is an effort to maintain compatibility with older browsers and will be completely removed in the near future."
discourse_internet_explorer_deprecation_warning: "Show an Internet Explorer deprecation warning"

View File

@ -972,6 +972,9 @@ if (!String.prototype.startsWith) {
/* eslint-enable */
// Polyfill Promise - used by popper.js
if (!window.Promise) {
window.Promise = true;
}
window.addEventListener(
"load",
function() {

View File

@ -4,24 +4,25 @@
(function() {
var $buo = function() {
var badAndroid = false, ua = null;
// Sometimes we have to resort to parsing the user agent string. :(
if (navigator && navigator.userAgent) {
ua = navigator.userAgent;
var ua = navigator.userAgent;
// we don't ask Googlebot to update their browser
if (ua.indexOf('Googlebot') >= 0 || ua.indexOf('Mediapartners') >= 0 || ua.indexOf('AdsBot') >= 0) {
return;
}
}
// sam: we require WeakMap, this allows us to easily feature detect IE10 that does not support it
// This also catches ancient android phones that never had that feature (2.2 and below)
if (window.WeakMap) {
if (!window.unsupportedBrowser) {
return;
}
// we don't ask Googlebot to update their browser
if (ua.indexOf('Googlebot') >= 0 || ua.indexOf('Mediapartners') >= 0 || ua.indexOf('AdsBot') >= 0) {
return;
}
var mainElement = document.getElementById("main");
var noscriptElements = document.getElementsByTagName("noscript");
// noscriptElements[0].innerHTML contains encoded HTML
var innerHTML = noscriptElements[0].childNodes[0].nodeValue;
mainElement.innerHTML = innerHTML;
// retrieve localized browser upgrade text
var t = <%= "'" + I18n.t('js.browser_update') + "'" %>;