Skip to content

Commit

Permalink
Merge css-build-dir changes into 2.x
Browse files Browse the repository at this point in the history
* Don't set up observer in ShadyDOM
* Move __activateDir into check instead of replace
* skip some tests that never really worked in ShadyDOM
  • Loading branch information
kevinpschaaf committed Nov 14, 2018
1 parent d74aa82 commit cc1402d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
22 changes: 14 additions & 8 deletions lib/mixins/dir-mixin.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
const EL_DIR = /([\s\w-#\.\[\]\*]*):dir\((ltr|rtl)\)/g;
const EL_DIR_REPLACMENT = ':host([dir="$2"]) $1';

const DIR_CHECK = /:dir\((?:ltr|rtl)\)/;

const SHIM_SHADOW = Boolean(window['ShadyDOM'] && window['ShadyDOM']['inUse']);

/**
* @type {!Array<!Polymer_DirMixin>}
*/
Expand Down Expand Up @@ -80,10 +84,12 @@
*/
Polymer.DirMixin = Polymer.dedupingMixin((base) => {

if (!observer) {
getRTL();
observer = new MutationObserver(updateDirection);
observer.observe(document.documentElement, {attributes: true, attributeFilter: ['dir']});
if (!SHIM_SHADOW) {
if (!observer) {
getRTL();
observer = new MutationObserver(updateDirection);
observer.observe(document.documentElement, {attributes: true, attributeFilter: ['dir']});
}
}

/**
Expand All @@ -107,7 +113,10 @@
*/
static _processStyleText(cssText, baseURI) {
cssText = super._processStyleText(cssText, baseURI);
cssText = this._replaceDirInCssText(cssText);
if (!SHIM_SHADOW && DIR_CHECK.test(cssText)) {
cssText = this._replaceDirInCssText(cssText);
this.__activateDir = true;
}
return cssText;
}

Expand All @@ -121,9 +130,6 @@
let replacedText = text;
replacedText = replacedText.replace(HOST_DIR, HOST_DIR_REPLACMENT);
replacedText = replacedText.replace(EL_DIR, EL_DIR_REPLACMENT);
if (text !== replacedText) {
this.__activateDir = true;
}
return replacedText;
}

Expand Down
6 changes: 6 additions & 0 deletions test/unit/dir.html
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@
});

test('elements with dir attribute explicitly set will not change', function() {
if (window.ShadyDOM && window.ShadyDOM.inUse) {
this.skip();
}
let inner = fixture('preset');
assert.equal(document.documentElement.getAttribute('dir'), 'rtl');
assertComputed(inner.shadowRoot.querySelector('.special > div'), 'rgb(255, 255, 255)', 'color');
Expand Down Expand Up @@ -245,6 +248,9 @@
});

test('complicated setup', function() {
if (window.ShadyDOM && window.ShadyDOM.inUse) {
this.skip();
}
let el = fixture('complicated');
assertComputed(el.$.direct, '10px');
assertComputed(el.$.indirect, '9px');
Expand Down

0 comments on commit cc1402d

Please sign in to comment.