Skip to content

Commit

Permalink
fix(errors): prevent JS errors and modernize selectors a bit to fix #236
Browse files Browse the repository at this point in the history
  • Loading branch information
ffoodd committed Jun 13, 2024
1 parent e26169f commit 80b97a6
Show file tree
Hide file tree
Showing 20 changed files with 95 additions and 93 deletions.
2 changes: 1 addition & 1 deletion dist/WebExtension/css/classic-toolbar.css

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/WebExtension/js/ToolbarStrings.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ function ToolbarStrings() {
* @return nothing
*/
this.setLocale = function () {
var htmlTag = document.getElementsByTagName("html")[0];
var htmlTag = document.documentElement;
/* HTML tag <html> of the page */
var bodyTag = document.getElementsByTagName("body")[0];
var bodyTag = document.body;
/* HTML tag <body> of the page */
this.locale = ((htmlTag.lang) ? htmlTag.lang : (htmlTag.getAttribute("xml:lang")) ? htmlTag.getAttribute("xml:lang") : (bodyTag.lang) ? bodyTag.lang : defaultLocale).substr(0, 2).toUpperCase();
if (!this.locale || !traduction[this.locale]) {
Expand Down
4 changes: 2 additions & 2 deletions dist/WebExtension/js/UciProfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ UciProfile = {
}
document.getElementById("uci_cdu_popin").appendChild(UciProfile.saveProfile());
document.getElementById("uci_cdu_popin").style.display = "block";
document.getElementById("uci_cdu_popin").style.height = document.getElementsByTagName("body")[0].clientHeight + "px";
document.getElementById("uci_cdu_popin").style.height = document.body.clientHeight + "px";
if (top) {
document.getElementById("uci_cdu_popin").style.top = "0";
} else {
Expand Down Expand Up @@ -557,7 +557,7 @@ UciProfile = {
document.getElementById("uci_cdu_popin").appendChild(UciProfile.formProfile(profilName));

document.getElementById("uci_cdu_popin").style.display = "block";
document.getElementById("uci_cdu_popin").style.height = document.getElementsByTagName("body")[0].clientHeight + "px";
document.getElementById("uci_cdu_popin").style.height = document.body.clientHeight + "px";
document.getElementById("uci_profile_name").focus();
accessibilitytoolbar.uciAttachEvent('submit', 'onsubmit', document.getElementById('uci_form_profil'), function (e) {
accessibilitytoolbar.stopEvt(e);
Expand Down
8 changes: 4 additions & 4 deletions dist/WebExtension/js/mask.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ UciMask = {
bottomMask = document.createElement("div");
bottomMask.className = "uci_mask bottomMask";
bottomMask.id = "bottomMask";
document.getElementsByTagName("body")[0].appendChild(topMask);
document.getElementsByTagName("body")[0].appendChild(bottomMask);
document.body.appendChild(topMask);
document.body.appendChild(bottomMask);
vMouse = document.createElement("div");
vMouse.className = "vMouse";
vMouse.id = "vMouse";
hMouse = document.createElement("div");
hMouse.className = "hMouse";
hMouse.id = "hMouse";
document.getElementsByTagName("body")[0].appendChild(vMouse);
document.getElementsByTagName("body")[0].appendChild(hMouse);
document.body.appendChild(vMouse);
document.body.appendChild(hMouse);
}
// remove tomask childs if exists
while (document.getElementById('topMask').hasChildNodes()) {
Expand Down
2 changes: 1 addition & 1 deletion dist/WebExtension/js/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
**/
function startCDU() {
let toolbarServer = document.querySelector("script[src*='crossdom/js']");
let head = document.querySelector("head");
let head = document.head;
let body = document.querySelector("body");
let toolbarDiv = document.querySelector("accessibilitytoolbarGraphic");
let toolbarOnOff = document.getElementById("uci-onoffswitch");
Expand Down
54 changes: 27 additions & 27 deletions dist/WebExtension/js/toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function LoopingMenu() {
menuContainer.appendChild(menuTitle);
menuContainer.appendChild(menuList);

document.getElementsByTagName("body")[0].appendChild(menuContainer);
document.body.appendChild(menuContainer);

// Define default rendering
that.setPosition(LoopingMenuPosition.CENTER);
Expand Down Expand Up @@ -1951,7 +1951,7 @@ function RemoteControlPad() {
i.height = imgHeight;
i.useMap = "#remotemap";
pad.appendChild(i);
document.getElementsByTagName("body")[0].appendChild(pad);
document.body.appendChild(pad);
};

// Publics methods
Expand Down Expand Up @@ -2569,7 +2569,7 @@ accessibilitytoolbar = {
newStyle.setAttribute("type", "text/css");
newStyle.id = "a11yCSSFontStyle";
newStyle.appendChild(document.createTextNode("@font-face{font-family: \"orangeconfortplus\";src: " + fontsPath['fonticone'] + ";font-style: normal;font-weight: normal;}"));
document.getElementsByTagName('head')[0].appendChild(newStyle);
document.head.appendChild(newStyle);
}
},

Expand Down Expand Up @@ -2598,7 +2598,7 @@ accessibilitytoolbar = {
newStyle.setAttribute("type", "text/css");
newStyle.appendChild(document.createTextNode(style));

var _head = document.getElementsByTagName('head')[0];
var _head = document.head;
// newStyle
_head.insertBefore(newStyle, _head.firstChild);

Expand Down Expand Up @@ -2996,7 +2996,7 @@ accessibilitytoolbar = {
});

i = 0;
theFrames = document.getElementsByTagName('frame');
theFrames = document.querySelectorAll('frame');
if (theFrames.length > 0) {
while (theFrame = theFrames[i]) {
try {
Expand Down Expand Up @@ -3510,7 +3510,7 @@ accessibilitytoolbar = {
// default mode, settings for the page
if (localUserPref.get("a11yToolbarEnable") !== "off") {
if (document.getElementById('cdu_close')) {
document.getElementById('cdu_close').style.display == 'none';
document.getElementById('cdu_close').style.display = 'none';
}
toolbarContent = document.getElementById("cdu_toolbar");
if (!toolbarContent || toolbarContent.className.match(/cdu_displayN/)) {
Expand All @@ -3519,13 +3519,13 @@ accessibilitytoolbar = {
}

indexIFrame = 0;
TheIFrames = document.getElementsByTagName("iframe");
TheIFrames = document.querySelectorAll("iframe");
if (TheIFrames.length > 0) {
while (theIFrame = TheIFrames[indexIFrame]) {
try {
theIFrameDocument = theIFrame.document || theIFrame.contentDocument;
if (theIFrameDocument.getElementsByTagName('head')[0]) {
theIFrameDocument.getElementsByTagName('head')[0].removeChild(theIFrameDocument.getElementById("a11yUserPrefStyle"));
if (theIFrameDocument.head && theIFrameDocument.getElementById("a11yUserPrefStyle")) {
theIFrameDocument.head.removeChild(theIFrameDocument.getElementById("a11yUserPrefStyle"));
}
} catch (e) {
}
Expand All @@ -3534,7 +3534,7 @@ accessibilitytoolbar = {
}
// Remove previous user style
if (document.getElementById("a11yUserPrefStyle")) {
document.getElementsByTagName("head")[0].removeChild(document.getElementById("a11yUserPrefStyle"));
document.head.removeChild(document.getElementById("a11yUserPrefStyle"));


/*
Expand All @@ -3548,8 +3548,8 @@ accessibilitytoolbar = {
while (theFrame = theFrames[indexFrame]) {
try {
theFrameDocument = theFrame.contentDocument || theFrame.document;
if (theFrameDocument.getElementsByTagName('head')[0]) {
theFrameDocument.getElementsByTagName('head')[0].removeChild(theFrameDocument.getElementById("a11yUserPrefStyle"));
if (theFrameDocument.head && theFrameDocument.getElementById("a11yUserPrefStyle")) {
theFrameDocument.head.removeChild(theFrameDocument.getElementById("a11yUserPrefStyle"));
}
} catch (e) {
console.error(e);
Expand All @@ -3570,11 +3570,11 @@ accessibilitytoolbar = {
// if the user remove the option, we need to put back the stylesheets and styles attributes

if (localUserPref.get("a11yLinearize") === "false"
|| localUserPref.get("a11ySiteWebEnabled") == "off") {
|| localUserPref.get("a11ySiteWebEnabled") === "off") {

if (accessibilitytoolbar.savesStylesheets.length > 0) {
for (i = accessibilitytoolbar.savesStylesheets.length - 1; i >= 0; i--) {
document.getElementsByTagName('head')[0].insertBefore(accessibilitytoolbar.savesStylesheets[i], document.getElementById('a11yCSS'));
document.head.insertBefore(accessibilitytoolbar.savesStylesheets[i], document.getElementById('a11yCSS'));
}
// then clean the array
accessibilitytoolbar.savesStylesheets = [];
Expand All @@ -3590,11 +3590,11 @@ accessibilitytoolbar = {
}
}

if (localUserPref.get("a11ySiteWebEnabled") != "off") {
if (localUserPref.get("a11ySiteWebEnabled") !== "off") {
// 1. linearize ? -- which is the same as: get rid of all CSS info first
if (localUserPref.get("a11yLinearize") !== "false") {
// delete all the CSS references
links = document.getElementsByTagName("link");
links = document.querySelectorAll("link");
for (i = links.length - 1; i >= 0; i--) {
if (links[i].rel.match(/stylesheet/i) && (!links[i].id || !links[i].id.match(/a11yCSS/))) {
accessibilitytoolbar.savesStylesheets.push(links[i]);
Expand All @@ -3621,9 +3621,9 @@ accessibilitytoolbar = {
fontSizeDef = fontSizeBody = '16px';
if (window.getComputedStyle) {
// get the font-size from html tag
fontSizeDef = window.getComputedStyle(document.getElementsByTagName('html')[0], null).getPropertyValue("font-size") || '16px';
fontSizeDef = window.getComputedStyle(document.documentElement, null).getPropertyValue("font-size") || '16px';
// get the font-size from the body
fontSizeBody = window.getComputedStyle(document.getElementsByTagName('body')[0], null).getPropertyValue("font-size") || '16px';
fontSizeBody = window.getComputedStyle(document.body, null).getPropertyValue("font-size") || '16px';
}
// s += "body { font-size:1rem !important; }\n";
s += "#accessibilitytoolbarGraphic { font-size:" + (16 / parseFloat(fontSizeBody)) + "em !important; }\n";
Expand Down Expand Up @@ -3745,7 +3745,7 @@ accessibilitytoolbar = {
}
}
}
} else if (localUserPref.get("a11ySupImageFirstPlan") == "false") {
} else if (localUserPref.get("a11ySupImageFirstPlan") === "false") {
accessibilitytoolbar.cleanImgDisabled();
}

Expand Down Expand Up @@ -3782,7 +3782,7 @@ accessibilitytoolbar = {
backGroundColor = accessibilitytoolbar.predifinedCombinaisons[localUserPref.get("a11yVisualPredefinedSettings")].backGroundColor;
}
/*defect 67 */
if (localUserPref.get("a11yVisualPredefinedSettings") == "whiteonblack") {
if (localUserPref.get("a11yVisualPredefinedSettings") === "whiteonblack") {
if (!init) {
document.getElementById('uci_reponses_bigger_quick_set').className = document.getElementById('uci_reponses_bigger_quick_set').className + " uci_black";
}
Expand Down Expand Up @@ -3850,15 +3850,15 @@ accessibilitytoolbar = {
newStyle.id = "a11yUserPrefStyle";
newStyle.appendChild(document.createTextNode(s));

document.getElementsByTagName('head')[0].appendChild(newStyle);
document.head.appendChild(newStyle);
indexFrame = 0;
theFrames = window.frames;
if (theFrames.length > 0) {
while (theFrame = theFrames[indexFrame]) {
try {
theFrameDocument = theFrame.contentDocument || theFrame.document;
if (theFrameDocument.getElementsByTagName('head')[0]) {
theFrameDocument.getElementsByTagName('head')[0].appendChild(newStyle.cloneNode(true));
if (theFrameDocument.head) {
theFrameDocument.head.appendChild(newStyle.cloneNode(true));
}
} catch (e) {
console.error(e);
Expand Down Expand Up @@ -4135,9 +4135,9 @@ accessibilitytoolbar = {
}
}
// this creates a few hooks to hold to
accessibilitytoolbar.head = document.getElementsByTagName('head')[0];
accessibilitytoolbar.body = document.getElementsByTagName('body')[0];
accessibilitytoolbar.html = document.getElementsByTagName('html')[0];
accessibilitytoolbar.head = document.head;
accessibilitytoolbar.body = document.body;
accessibilitytoolbar.html = document.documentElement;
if (document.getElementById('accessibilitytoolbarGraphic')) {
return false;
}
Expand All @@ -4157,7 +4157,7 @@ accessibilitytoolbar = {
newStyle.setAttribute("type", "text/css");
newStyle.appendChild(document.createTextNode(style));

var _head = document.getElementsByTagName('head')[0];
var _head = document.head;
// newStyle
_head.insertBefore(newStyle, _head.firstChild);
// And now we create the toolbar...
Expand Down
2 changes: 1 addition & 1 deletion dist/serveur/css/classic-toolbar.css

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/serveur/js/toolbar.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/serveur/js/toolbar.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/serveur/js/toolbar.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/serveur/js/toolbar.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/css/classic-toolbar.css

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/js/toolbar.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/js/toolbar.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/WebExtension/js/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
**/
function startCDU() {
let toolbarServer = document.querySelector("script[src*='crossdom/js']");
let head = document.querySelector("head");
let head = document.head;
let body = document.querySelector("body");
let toolbarDiv = document.querySelector("accessibilitytoolbarGraphic");
let toolbarOnOff = document.getElementById("uci-onoffswitch");
Expand Down
4 changes: 2 additions & 2 deletions src/js/ToolbarStrings.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ function ToolbarStrings() {
* @return nothing
*/
this.setLocale = function () {
var htmlTag = document.getElementsByTagName("html")[0];
var htmlTag = document.documentElement;
/* HTML tag <html> of the page */
var bodyTag = document.getElementsByTagName("body")[0];
var bodyTag = document.body;
/* HTML tag <body> of the page */
this.locale = ((htmlTag.lang) ? htmlTag.lang : (htmlTag.getAttribute("xml:lang")) ? htmlTag.getAttribute("xml:lang") : (bodyTag.lang) ? bodyTag.lang : defaultLocale).substr(0, 2).toUpperCase();
if (!this.locale || !traduction[this.locale]) {
Expand Down
4 changes: 2 additions & 2 deletions src/js/UciProfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ UciProfile = {
}
document.getElementById("uci_cdu_popin").appendChild(UciProfile.saveProfile());
document.getElementById("uci_cdu_popin").style.display = "block";
document.getElementById("uci_cdu_popin").style.height = document.getElementsByTagName("body")[0].clientHeight + "px";
document.getElementById("uci_cdu_popin").style.height = document.body.clientHeight + "px";
if (top) {
document.getElementById("uci_cdu_popin").style.top = "0";
} else {
Expand Down Expand Up @@ -557,7 +557,7 @@ UciProfile = {
document.getElementById("uci_cdu_popin").appendChild(UciProfile.formProfile(profilName));

document.getElementById("uci_cdu_popin").style.display = "block";
document.getElementById("uci_cdu_popin").style.height = document.getElementsByTagName("body")[0].clientHeight + "px";
document.getElementById("uci_cdu_popin").style.height = document.body.clientHeight + "px";
document.getElementById("uci_profile_name").focus();
accessibilitytoolbar.uciAttachEvent('submit', 'onsubmit', document.getElementById('uci_form_profil'), function (e) {
accessibilitytoolbar.stopEvt(e);
Expand Down
8 changes: 4 additions & 4 deletions src/js/mask.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ UciMask = {
bottomMask = document.createElement("div");
bottomMask.className = "uci_mask bottomMask";
bottomMask.id = "bottomMask";
document.getElementsByTagName("body")[0].appendChild(topMask);
document.getElementsByTagName("body")[0].appendChild(bottomMask);
document.body.appendChild(topMask);
document.body.appendChild(bottomMask);
vMouse = document.createElement("div");
vMouse.className = "vMouse";
vMouse.id = "vMouse";
hMouse = document.createElement("div");
hMouse.className = "hMouse";
hMouse.id = "hMouse";
document.getElementsByTagName("body")[0].appendChild(vMouse);
document.getElementsByTagName("body")[0].appendChild(hMouse);
document.body.appendChild(vMouse);
document.body.appendChild(hMouse);
}
// remove tomask childs if exists
while (document.getElementById('topMask').hasChildNodes()) {
Expand Down
Loading

0 comments on commit 80b97a6

Please sign in to comment.