Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
(hopefully) fix theming on Chrome
Browse files Browse the repository at this point in the history
Jump through some hoops to make Chrome behave sensibly on non-default themes.
  • Loading branch information
richvdh committed Jan 19, 2017
1 parent 128db1a commit a88f9fd
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/components/structures/MatrixChat.js
Original file line number Diff line number Diff line change
Expand Up @@ -598,20 +598,32 @@ module.exports = React.createClass({
theme = 'light';
}

// look for the stylesheet elements.
// styleElements is a map from style name to HTMLLinkElement.
var styleElements = Object.create(null);
var i, a;
for (i = 0; (a = document.getElementsByTagName("link")[i]); i++) {
var href = a.getAttribute("href");
// shouldn't we be using the 'title' tag rather than the href?
var match = href.match(/^bundles\/.*\/theme-(.*)\.css$/);
if (match) {
if (match[1] === theme) {
a.disabled = false;
}
else {
a.disabled = true;
}
styleElements[match[1]] = a;
}
}

if (!(theme in styleElements)) {
throw new Error("Unknown theme " + theme);
}

// disable all of them first, then enable the one we want. Chrome only
// bothers to do an update on a true->false transition, so this ensures
// that we get exactly one update, at the right time.

Object.values(styleElements).forEach((a) => {
a.disabled = true;
});
styleElements[theme].disabled = false;

if (theme === 'dark') {
// abuse the tinter to change all the SVG's #fff to #2d2d2d
// XXX: obviously this shouldn't be hardcoded here.
Expand Down

0 comments on commit a88f9fd

Please sign in to comment.