From 4332d0edb0ab28e27ae9793d9aa217b6c7e02659 Mon Sep 17 00:00:00 2001 From: El RIDO Date: Wed, 18 Sep 2019 07:31:32 +0200 Subject: [PATCH] making legacy.js work even on IE 6 by avoiding jQuery --- js/common.js | 2 +- js/legacy.js | 75 ++++++++++++++++++++++++++++------------------- js/privatebin.js | 4 +-- js/test/Check.js | 64 +++++++++++++++++++--------------------- tpl/bootstrap.php | 4 +-- tpl/page.php | 4 +-- 6 files changed, 82 insertions(+), 71 deletions(-) diff --git a/js/common.js b/js/common.js index ea975e03..47f83ef4 100644 --- a/js/common.js +++ b/js/common.js @@ -19,8 +19,8 @@ global.prettyPrintOne = window.PR.prettyPrintOne; global.showdown = require('./showdown-1.9.1'); global.DOMPurify = require('./purify-1.0.11'); global.baseX = require('./base-x-3.0.5.1').baseX; +global.Legacy = require('./legacy').Legacy; require('./bootstrap-3.3.7'); -require('./legacy'); require('./privatebin'); // internal variables diff --git a/js/legacy.js b/js/legacy.js index acfb595f..e50a64d9 100644 --- a/js/legacy.js +++ b/js/legacy.js @@ -12,26 +12,19 @@ * * IMPORTANT NOTICE FOR DEVELOPERS: * The logic in this file is intended to run in legacy browsers. Avoid any use of: - * - ES6 or newer in general + * - jQuery (doesn't work in older browsers) + * - ES5 or newer in general * - const/let, use the traditional var declarations instead * - async/await or Promises, use traditional callbacks * - shorthand function notation "() => output", use the full "function() {return output;}" style * - IE doesn't support: * - URL(), use the traditional window.location object * - endsWith(), use indexof() - * - yes, this logic needs to support IE 5 or 6, to at least display the error message + * - yes, this logic needs to support IE 6, to at least display the error message */ -// main application start, called when DOM is fully loaded -jQuery(document).ready(function() { - 'use strict'; - // run main controller - $.Legacy.Check.init(); -}); - -jQuery.Legacy = (function($) { - 'use strict'; - +'use strict'; +(function() { /** * compatibility check * @@ -198,23 +191,29 @@ jQuery.Legacy = (function($) { */ function showError(message) { - var $error = $('#errormessage'), - $glyphIcon = $error.find(':first'), - $element; - if ($glyphIcon.length) { - // if there is an icon, we need to provide an inner element - // to translate the message into, instead of the parent - $element = $(''); - $error.html(' ').prepend($glyphIcon).append($element); - } else { - $element = $error; - } + var element = document.getElementById('errormessage'); if (message.indexOf('' + - '' + '', { + 'userAgent': prefix + botBit + suffix + } ); - $.PrivateBin.Alert.init(); - $.Legacy.Check.init(); - const result1 = $.Legacy.Check.getInit() && !$.Legacy.Check.getStatus(), - result2 = !$('#errormessage').hasClass('hidden'); + Legacy.Check.init(); + const result1 = Legacy.Check.getInit() && !Legacy.Check.getStatus(), + result2 = (document.getElementById('errormessage').className !== 'hidden'); clean(); return result1 && result2; } @@ -42,19 +40,18 @@ describe('Check', function () { function (secureProtocol, localhost, domain, tld) { const isDomain = localhost === '', isSecureContext = secureProtocol || !isDomain || tld.length > 0, - clean = jsdom('', { - 'url': (secureProtocol ? 'https' : 'http' ) + '://' + - (isDomain ? domain.join('') + tld : localhost) + '/' - }); - $('body').html( - ''+ - '' - ); - $.PrivateBin.Alert.init(); - $.Legacy.Check.init(); - const result1 = $.Legacy.Check.getInit() && !$.Legacy.Check.getStatus(), - result2 = isSecureContext === $('#errormessage').hasClass('hidden'), - result3 = !$('#oldnotice').hasClass('hidden'); + clean = jsdom( + '' + + '', + { + 'url': (secureProtocol ? 'https' : 'http' ) + '://' + + (isDomain ? domain.join('') + tld : localhost) + '/' + } + ); + Legacy.Check.init(); + const result1 = Legacy.Check.getInit() && !Legacy.Check.getStatus(), + result2 = isSecureContext === (document.getElementById('errormessage').className === 'hidden'), + result3 = (document.getElementById('oldnotice').className !== 'hidden'); clean(); return result1 && result2 && result3; } @@ -65,18 +62,17 @@ describe('Check', function () { 'bool', jsc.nearray(common.jscA2zString()), function (secureProtocol, domain) { - const clean = jsdom('', { - 'url': (secureProtocol ? 'https' : 'http' ) + '://' + domain.join('') + '/' - }); - $('body').html( - ''+ - '' - ); + const clean = jsdom( + '' + + '', + { + 'url': (secureProtocol ? 'https' : 'http' ) + '://' + domain.join('') + '/' + } + ); window.crypto = new WebCrypto(); - $.PrivateBin.Alert.init(); - $.Legacy.Check.init(); - const result1 = $.Legacy.Check.getInit() && $.Legacy.Check.getStatus(), - result2 = secureProtocol === $('#httpnotice').hasClass('hidden'); + Legacy.Check.init(); + const result1 = Legacy.Check.getInit() && Legacy.Check.getStatus(), + result2 = secureProtocol === (document.getElementById('httpnotice').className === 'hidden'); clean(); return result1 && result2; } diff --git a/tpl/bootstrap.php b/tpl/bootstrap.php index f0ab0b58..c8ffa8b7 100644 --- a/tpl/bootstrap.php +++ b/tpl/bootstrap.php @@ -71,8 +71,8 @@ if ($MARKDOWN): endif; ?> - - + + diff --git a/tpl/page.php b/tpl/page.php index 0d6bd3a7..a373f85a 100644 --- a/tpl/page.php +++ b/tpl/page.php @@ -49,8 +49,8 @@ if ($MARKDOWN): endif; ?> - - + +