Skip to content

Commit

Permalink
Fixes #25, regards issue #22:
Browse files Browse the repository at this point in the history
* Now making sure to add stylesheet link elements to the `<head>` element, not the root `<html>` element, of a message.
* Now using an attribute on the HTML element instead of a class

but the warning persists...
  • Loading branch information
Eyal Rozenberg committed Sep 5, 2020
1 parent 10e18e1 commit 703eec3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 50 deletions.
70 changes: 24 additions & 46 deletions src/chrome/content/bidimailui-display-logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ BiDiMailUI.Display = {


appendStyleSheet : function(domDocument, sheetFileName) {
let ns = domDocument.documentElement.lookupNamespaceURI("html");
let element = window.document.createElementNS(ns, "link");
let ns = domDocument.lookupNamespaceURI("html");
let element = domDocument.createElementNS(ns, "link");
element.setAttribute("rel", "stylesheet");
element.setAttribute("href", 'chrome://bidimailui/content/' + sheetFileName);
return domDocument.documentElement.appendChild(element);
return domDocument.head.appendChild(element);

/*
var head = domDocument.getElementsByTagName("head")[0];
Expand Down Expand Up @@ -429,52 +429,30 @@ BiDiMailUI.Display = {

#ifdef DEBUG_setDirections
console.log(
'settings directions to ' +
(forcedDirection ? forcedDirection :
'detected/original directions'));
'settings directions to ' + (forcedDirection ? forcedDirection : 'detected/original directions'));
#endif

let htmlNode = body.parentNode;
switch(forcedDirection) {
case 'ltr':
case 'rtl':
try {
body.parentNode.classList.remove('bidimailui-use-detected-directions');
} catch(ex) {
// this is an old build, no classList... bummer;
// let's remove manually from the list of class names
var re = / *bidimailui-use-detected-directions */;
if (re.test(body.parentNode.className)) {
body.parentNode.className = RegExp.leftContext +
((re.rightContext == '') ? ' ' : '') + RegExp.rightContext;
}
}
if (!body.hasAttribute('bidimailui-original-direction')) {
body.setAttribute('bidimailui-original-direction',
body.style.direction);
}
body.style.direction = forcedDirection;
break;
default:
var originalBodyCSSDirectionProperty =
body.getAttribute('bidimailui-original-direction');
if (originalBodyCSSDirectionProperty &&
(originalBodyCSSDirectionProperty != "") ) {
body.style.direction = originalBodyCSSDirectionProperty;
}
else {
body.style.removeProperty('direction');
}
try {
body.parentNode.classList.add('bidimailui-use-detected-directions');
} catch(ex) {
// this is an old build, no classList... bummer;
// let's add manually to the list of class names
if (body.parentNode.className.indexOf('bidimailui-use-detected-directions') == -1) {
body.parentNode.className +=
((body.parentNode.className != "") ? ' ' : '') +
'bidimailui-use-detected-directions';
}
}
case 'ltr':
case 'rtl':
htmlNode.removeAttribute('bidimailui-use-detected-directions');
if (!body.hasAttribute('bidimailui-original-direction')) {
body.setAttribute('bidimailui-original-direction', body.style.direction);
}
body.style.direction = forcedDirection;
break;
default:
var originalBodyCSSDirectionProperty =
body.getAttribute('bidimailui-original-direction');
if (originalBodyCSSDirectionProperty &&
(originalBodyCSSDirectionProperty != "") ) {
body.style.direction = originalBodyCSSDirectionProperty;
}
else {
body.style.removeProperty('direction');
}
htmlNode.setAttribute('bidimailui-use-detected-directions', true);
}
},

Expand Down
8 changes: 4 additions & 4 deletions src/chrome/content/direction-autodetection.css
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

.bidimailui-use-detected-directions [bidimailui-direction-uniformity="rtl"] {
[bidimailui-use-detected-directions="true"] [bidimailui-direction-uniformity="rtl"] {
direction: rtl;
}

.bidimailui-use-detected-directions [bidimailui-direction-uniformity="ltr"] {
[bidimailui-use-detected-directions="true"] [bidimailui-direction-uniformity="ltr"] {
direction: ltr;
}

.bidimailui-use-detected-directions [bidimailui-direction-uniformity="mixed"] {
[bidimailui-use-detected-directions="true"] [bidimailui-direction-uniformity="mixed"] {
/* We choose to direct mixed content as RTL - usually the safe choice. */
direction: rtl;
}
Expand All @@ -16,7 +16,7 @@
There is no rule for neutral elements, as we do not wish to specify their
behavior - they should inherit their direction or obey document-specific
style rules.
.bidimailui-use-detected-directions [bidimailui-direction-uniformity="neutral"] {
[bidimailui-use-detected-directions="true"] [bidimailui-direction-uniformity="neutral"] {
}
*/

0 comments on commit 703eec3

Please sign in to comment.