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

Commit

Permalink
Merge pull request #1610 from matrix-org/rxl881/lintingErrors
Browse files Browse the repository at this point in the history
Fix linting errors.
  • Loading branch information
ara4n committed Nov 15, 2017
2 parents 96a3eff + 06b3199 commit ec33806
Showing 1 changed file with 40 additions and 34 deletions.
74 changes: 40 additions & 34 deletions src/Tinter.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,17 @@ function colorToRgb(color) {
const g = (val >> 8) & 255;
const b = val & 255;
return [r, g, b];
}
else {
let match = color.match(/rgb\((.*?),(.*?),(.*?)\)/);
} else {
const match = color.match(/rgb\((.*?),(.*?),(.*?)\)/);
if (match) {
return [ parseInt(match[1]),
parseInt(match[2]),
parseInt(match[3]) ];
return [
parseInt(match[1]),
parseInt(match[2]),
parseInt(match[3]),
];
}
}
return [0,0,0];
return [0, 0, 0];
}

// utility to turn [red,green,blue] into #rrggbb
Expand Down Expand Up @@ -152,9 +153,11 @@ class Tinter {

this.calcCssFixups();

if (DEBUG) console.log("Tinter.tint(" + primaryColor + ", " +
secondaryColor + ", " +
tertiaryColor + ")");
if (DEBUG) {
console.log("Tinter.tint(" + primaryColor + ", " +
secondaryColor + ", " +
tertiaryColor + ")");
}

if (!primaryColor) {
primaryColor = this.keyRgb[0];
Expand Down Expand Up @@ -194,9 +197,11 @@ class Tinter {
this.colors[1] = secondaryColor;
this.colors[2] = tertiaryColor;

if (DEBUG) console.log("Tinter.tint final: (" + primaryColor + ", " +
secondaryColor + ", " +
tertiaryColor + ")");
if (DEBUG) {
console.log("Tinter.tint final: (" + primaryColor + ", " +
secondaryColor + ", " +
tertiaryColor + ")");
}

// go through manually fixing up the stylesheets.
this.applyCssFixups();
Expand Down Expand Up @@ -230,18 +235,15 @@ class Tinter {
// update keyRgb from the current theme CSS itself, if it defines it
if (document.getElementById('mx_theme_accentColor')) {
this.keyRgb[0] = window.getComputedStyle(
document.getElementById('mx_theme_accentColor')
).color;
document.getElementById('mx_theme_accentColor')).color;
}
if (document.getElementById('mx_theme_secondaryAccentColor')) {
this.keyRgb[1] = window.getComputedStyle(
document.getElementById('mx_theme_secondaryAccentColor')
).color;
document.getElementById('mx_theme_secondaryAccentColor')).color;
}
if (document.getElementById('mx_theme_tertiaryAccentColor')) {
this.keyRgb[2] = window.getComputedStyle(
document.getElementById('mx_theme_tertiaryAccentColor')
).color;
document.getElementById('mx_theme_tertiaryAccentColor')).color;
}

this.calcCssFixups();
Expand All @@ -262,9 +264,11 @@ class Tinter {
// cache our fixups
if (this.cssFixups[this.theme]) return;

if (DEBUG) console.debug("calcCssFixups start for " + this.theme + " (checking " +
document.styleSheets.length +
" stylesheets)");
if (DEBUG) {
console.debug("calcCssFixups start for " + this.theme + " (checking " +
document.styleSheets.length +
" stylesheets)");
}

this.cssFixups[this.theme] = [];

Expand Down Expand Up @@ -322,21 +326,24 @@ class Tinter {
}
}
}
if (DEBUG) console.log("calcCssFixups end (" +
this.cssFixups[this.theme].length +
" fixups)");
if (DEBUG) {
console.log("calcCssFixups end (" +
this.cssFixups[this.theme].length +
" fixups)");
}
}

applyCssFixups() {
if (DEBUG) console.log("applyCssFixups start (" +
this.cssFixups[this.theme].length +
" fixups)");
if (DEBUG) {
console.log("applyCssFixups start (" +
this.cssFixups[this.theme].length +
" fixups)");
}
for (let i = 0; i < this.cssFixups[this.theme].length; i++) {
const cssFixup = this.cssFixups[this.theme][i];
try {
cssFixup.style[cssFixup.attr] = this.colors[cssFixup.index];
}
catch (e) {
} catch (e) {
// Firefox Quantum explodes if you manually edit the CSS in the
// inspector and then try to do a tint, as apparently all the
// fixups are then stale.
Expand All @@ -358,7 +365,7 @@ class Tinter {
if (DEBUG) console.log("calcSvgFixups start for " + svgs);
const fixups = [];
for (let i = 0; i < svgs.length; i++) {
var svgDoc;
let svgDoc;
try {
svgDoc = svgs[i].contentDocument;
} catch(e) {
Expand All @@ -369,7 +376,7 @@ class Tinter {
if (e.stack) {
msg += ' | stack: ' + e.stack;
}
console.error(e);
console.error(msg);
}
if (!svgDoc) continue;
const tags = svgDoc.getElementsByTagName("*");
Expand All @@ -379,8 +386,7 @@ class Tinter {
const attr = this.svgAttrs[k];
for (let l = 0; l < this.keyHex.length; l++) {
if (tag.getAttribute(attr) &&
tag.getAttribute(attr).toUpperCase() === this.keyHex[l])
{
tag.getAttribute(attr).toUpperCase() === this.keyHex[l]) {
fixups.push({
node: tag,
attr: attr,
Expand Down

0 comments on commit ec33806

Please sign in to comment.