@@ -24,36 +24,14 @@ function preloadFormImages() {
2424 images . map ( el => ( new Image ( ) ) . src = el . getAttribute ( 'cf-image' ) ) ;
2525}
2626
27- function loadThemes ( ) {
28- console . log ( 'loadThemes' ) ;
29-
30- loadcss ( themes . map ( t => `./${ t } ` ) , ( links ) => {
31- links . forEach ( link => console . log ( link ) ) ;
32-
33- const stylesheets = [ ] . slice . call ( document . styleSheets ) ;
34- stylesheets . map ( ( s , i ) => {
35- console . log ( i , s . href ) ;
36- const filename = s . href . substring ( s . href . lastIndexOf ( '/' ) + 1 ) ;
37- if (
38- filename . indexOf ( 'conversational-form' ) > - 1
39- && filename . indexOf ( themes [ 0 ] ) === - 1
40- && filename . indexOf ( 'main.' ) === - 1
41- ) {
42- document . styleSheets [ i ] . disabled = true ;
43- }
44- return s ;
45- } ) ;
46- } ) ;
47- }
48-
4927function changeTheme ( themeName ) {
5028 if ( currentTheme === themeName ) return ;
5129
5230 console . log ( 'changeTheme' , currentTheme , themeName ) ;
5331 const stylesheets = [ ] . slice . call ( document . styleSheets ) ;
5432 stylesheets . map ( ( s , i ) => {
5533 const filename = s . href . substring ( s . href . lastIndexOf ( '/' ) + 1 ) ;
56- console . log ( 't' , filename ) ;
34+ // console.log('t', filename);
5735 if (
5836 document . styleSheets [ i ] . disabled === false
5937 && filename . indexOf ( 'conversational-form' ) > - 1
@@ -70,6 +48,32 @@ function changeTheme(themeName) {
7048 } ) ;
7149}
7250
51+ function loadThemes ( ) {
52+ console . log ( 'loadThemes' ) ;
53+
54+ const totalThemes = themes . length ;
55+
56+ loadcss ( themes . map ( t => `./${ t } ` ) , ( ) => {
57+ const stylesheets = [ ] . slice . call ( document . styleSheets ) ;
58+ stylesheets . map ( ( s , i ) => {
59+ // console.log(i, s.href);
60+ const filename = s . href . substring ( s . href . lastIndexOf ( '/' ) + 1 ) ;
61+ if (
62+ filename . indexOf ( 'conversational-form' ) > - 1
63+ && filename . indexOf ( themes [ 0 ] ) === - 1
64+ && filename . indexOf ( 'main.' ) === - 1
65+ ) {
66+ document . styleSheets [ i ] . disabled = true ;
67+ }
68+
69+ console . log ( 'loaded' , i ) ;
70+ if ( totalThemes === i ) changeTheme ( themes [ 0 ] ) ;
71+
72+ return s ;
73+ } ) ;
74+ } ) ;
75+ }
76+
7377function animateIn ( ) {
7478 const headerEl = document . querySelector ( 'header' ) ;
7579 const headlineEl = document . querySelector ( 'h1' ) ;
@@ -143,8 +147,6 @@ function animateIn() {
143147
144148function init ( ) {
145149 loadThemes ( ) ;
146- changeTheme ( themes [ 1 ] ) ;
147- preloadFormImages ( ) ;
148150 Tracking . registerAllExternalLinks ( ) ;
149151
150152 const wrapperEl = document . querySelector ( '.wrapper' ) ;
0 commit comments