@@ -5,63 +5,80 @@ const fontFileBlobs = { regular: null, italic: null, bold: null, bolditalic: nul
55let downloadStarted = false
66async function downloadFont ( kindOfDownload , button ) {
77 // console.log("downloadFont")
8- if ( ! downloadStarted ) {
9- downloadStarted = true
10- button . classList . remove ( "loaded" , "error" )
11- button . classList . add ( "loading" )
128
13- let allSettings = { }
14- if ( kindOfDownload === "dev" ) {
15- allSettings . regular = { ...downloadSettingsCustom , style : "Regular" }
16- allSettings . italic = {
17- ...downloadSettingsCustom ,
18- style : "Italic" ,
19- italic : true ,
20- }
21- allSettings . bold = { ...downloadSettingsCustom , style : "Bold" , weight : 700 }
22- allSettings . bolditalic = {
23- ...downloadSettingsCustom ,
24- style : "Bold Italic" ,
25- italic : true ,
26- weight : 700 ,
27- }
28- }
29- if ( kindOfDownload === "default" ) {
30- allSettings . regular = { ...downloadSettingsDefault , style : "Regular" }
31- allSettings . italic = {
32- ...downloadSettingsDefault ,
33- style : "Italic" ,
34- italic : true ,
35- }
36- allSettings . bold = { ...downloadSettingsDefault , style : "Bold" , weight : 700 }
37- allSettings . bolditalic = {
38- ...downloadSettingsDefault ,
39- style : "Bold Italic" ,
40- italic : true ,
41- weight : 700 ,
42- }
43- }
44- if ( kindOfDownload === "design" ) {
45- for ( let weight = 300 ; weight <= 700 ; weight += 25 ) {
46- allSettings [ weight + "Regular" ] = {
9+ // detect safari
10+ const userAgentString = navigator . userAgent || "."
11+ let usingChrome = userAgentString . indexOf ( "Chrome" ) > - 1 || false
12+ let usingSafari = userAgentString . indexOf ( "Safari" ) > - 1 || false
13+ if ( usingChrome && usingSafari ) usingSafari = false
14+
15+ // block download if from Safari since zip is corrupted
16+ if ( usingSafari ) {
17+ button . classList . remove ( "loaded" , "error" , "safari" )
18+ button . classList . add ( "loading" )
19+ setTimeout ( ( ) => {
20+ button . classList . remove ( "loading" )
21+ button . classList . add ( "safari" )
22+ } , 500 )
23+ } else {
24+ if ( ! downloadStarted ) {
25+ downloadStarted = true
26+ button . classList . remove ( "loaded" , "error" , "safari" )
27+ button . classList . add ( "loading" )
28+
29+ let allSettings = { }
30+ if ( kindOfDownload === "dev" ) {
31+ allSettings . regular = { ...downloadSettingsCustom , style : "Regular" }
32+ allSettings . italic = {
4733 ...downloadSettingsCustom ,
48- style : weight + "Regular" ,
49- weight,
50- italic : false ,
34+ style : "Italic" ,
35+ italic : true ,
5136 }
52- allSettings [ weight + "Italic" ] = {
37+ allSettings . bold = { ...downloadSettingsCustom , style : "Bold" , weight : 700 }
38+ allSettings . bolditalic = {
5339 ...downloadSettingsCustom ,
54- style : weight + "Italic" ,
55- weight,
40+ style : "Bold Italic" ,
5641 italic : true ,
42+ weight : 700 ,
43+ }
44+ }
45+ if ( kindOfDownload === "default" ) {
46+ allSettings . regular = { ...downloadSettingsDefault , style : "Regular" }
47+ allSettings . italic = {
48+ ...downloadSettingsDefault ,
49+ style : "Italic" ,
50+ italic : true ,
51+ }
52+ allSettings . bold = { ...downloadSettingsDefault , style : "Bold" , weight : 700 }
53+ allSettings . bolditalic = {
54+ ...downloadSettingsDefault ,
55+ style : "Bold Italic" ,
56+ italic : true ,
57+ weight : 700 ,
58+ }
59+ }
60+ if ( kindOfDownload === "design" ) {
61+ for ( let weight = 300 ; weight <= 700 ; weight += 25 ) {
62+ allSettings [ weight + "Regular" ] = {
63+ ...downloadSettingsCustom ,
64+ style : weight + "Regular" ,
65+ weight,
66+ italic : false ,
67+ }
68+ allSettings [ weight + "Italic" ] = {
69+ ...downloadSettingsCustom ,
70+ style : weight + "Italic" ,
71+ weight,
72+ italic : true ,
73+ }
5774 }
5875 }
59- }
6076
61- Promise . all ( Object . values ( allSettings ) . map ( ( settings ) => makeCustomFont ( settings ) ) )
62- . then ( ( resolve ) => getZipFileBlob ( kindOfDownload , resolve ) )
63- . then ( ( resolve ) => initializeDownload ( button , resolve ) )
64- . catch ( ( error ) => catchError ( button , error ) )
77+ Promise . all ( Object . values ( allSettings ) . map ( ( settings ) => makeCustomFont ( settings ) ) )
78+ . then ( ( resolve ) => getZipFileBlob ( kindOfDownload , resolve ) )
79+ . then ( ( resolve ) => initializeDownload ( button , resolve ) )
80+ . catch ( ( error ) => catchError ( button , error ) )
81+ }
6582 }
6683}
6784
0 commit comments