diff --git a/src/chrome/content/bidimailui-display-logic.js b/src/chrome/content/bidimailui-display-logic.js index 71168ee7..aa94122e 100644 --- a/src/chrome/content/bidimailui-display-logic.js +++ b/src/chrome/content/bidimailui-display-logic.js @@ -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]; @@ -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); } }, diff --git a/src/chrome/content/direction-autodetection.css b/src/chrome/content/direction-autodetection.css index 72ea311f..5d2833b3 100644 --- a/src/chrome/content/direction-autodetection.css +++ b/src/chrome/content/direction-autodetection.css @@ -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; } @@ -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"] { } */