Skip to content

Commit

Permalink
Fixed theme loading. Mitigates Firefox bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
jenssogaard committed Nov 20, 2019
1 parent a79324c commit d64f4fa
Show file tree
Hide file tree
Showing 3 changed files with 1,332 additions and 1,265 deletions.
52 changes: 27 additions & 25 deletions landingpage/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,36 +24,14 @@ function preloadFormImages() {
images.map(el => (new Image()).src = el.getAttribute('cf-image'));
}

function loadThemes() {
console.log('loadThemes');

loadcss(themes.map(t => `./${t}`), (links) => {
links.forEach(link => console.log(link));

const stylesheets = [].slice.call(document.styleSheets);
stylesheets.map((s, i) => {
console.log(i, s.href);
const filename = s.href.substring(s.href.lastIndexOf('/') + 1);
if (
filename.indexOf('conversational-form') > -1
&& filename.indexOf(themes[0]) === -1
&& filename.indexOf('main.') === -1
) {
document.styleSheets[i].disabled = true;
}
return s;
});
});
}

function changeTheme(themeName) {
if (currentTheme === themeName) return;

console.log('changeTheme', currentTheme, themeName);
const stylesheets = [].slice.call(document.styleSheets);
stylesheets.map((s, i) => {
const filename = s.href.substring(s.href.lastIndexOf('/') + 1);
console.log('t', filename);
// console.log('t', filename);
if (
document.styleSheets[i].disabled === false
&& filename.indexOf('conversational-form') > -1
Expand All @@ -70,6 +48,32 @@ function changeTheme(themeName) {
});
}

function loadThemes() {
console.log('loadThemes');

const totalThemes = themes.length;

loadcss(themes.map(t => `./${t}`), () => {
const stylesheets = [].slice.call(document.styleSheets);
stylesheets.map((s, i) => {
// console.log(i, s.href);
const filename = s.href.substring(s.href.lastIndexOf('/') + 1);
if (
filename.indexOf('conversational-form') > -1
&& filename.indexOf(themes[0]) === -1
&& filename.indexOf('main.') === -1
) {
document.styleSheets[i].disabled = true;
}

console.log('loaded', i);
if (totalThemes === i) changeTheme(themes[0]);

return s;
});
});
}

function animateIn() {
const headerEl = document.querySelector('header');
const headlineEl = document.querySelector('h1');
Expand Down Expand Up @@ -143,8 +147,6 @@ function animateIn() {

function init() {
loadThemes();
changeTheme(themes[1]);
preloadFormImages();
Tracking.registerAllExternalLinks();

const wrapperEl = document.querySelector('.wrapper');
Expand Down
Loading

0 comments on commit d64f4fa

Please sign in to comment.