diff --git a/js/jquery.fontselect.js b/js/jquery.fontselect.js index 7e72848..ee0912a 100644 --- a/js/jquery.fontselect.js +++ b/js/jquery.fontselect.js @@ -16,7 +16,7 @@ class FontSelect { static __bind = (fn, me) => (...args) => fn.apply(me, args); - static init = (settings) => { + static init = async (settings) => { if (typeof FontSelect_Control !== "undefined") { if ( FontSelect_Control.hasOwnProperty("bibleget_settings") && @@ -29,13 +29,15 @@ class FontSelect { "https://fonts.googleapis.com/css2?key=" + FontSelect_Control.bibleget_settings.googlefontsapi_key + "&family="; - return fetch(`https://www.googleapis.com/webfonts/v1/webfonts?key=${FontSelect_Control.bibleget_settings.googlefontsapi_key}`).then(response => { - if(response.ok) { - return response.json(); - } - }); + const response = await fetch( `https://www.googleapis.com/webfonts/v1/webfonts?key=${FontSelect_Control.bibleget_settings.googlefontsapi_key}` ); + if ( response.ok ) { + return response.json(); + } } } + return new Promise((resolve, reject) => { + reject(false); + }); } constructor( original, f ) { this.$original = jQuery( original ); @@ -124,9 +126,9 @@ class FontSelect { $li = jQuery( "li", this.$results ).first(); } $li.addClass( "active" ); - const pos = $li.position().top; + const pos = $li.position(); //console.log("this li's position is: " + pos); - if ( pos > 100 ) this.$results.scrollTop( $li.position().top ); + if ( pos && pos.top && pos.top > 100 ) this.$results.scrollTop( pos.top ); } activateFont( ev ) { jQuery( "li.active", this.$results ).removeClass( "active" ); @@ -303,205 +305,206 @@ class FontSelect { (async ($) => { + const google_fonts = [ + "Aclonica", + "Allan", + "Annie+Use+Your+Telescope", + "Anonymous+Pro", + "Allerta+Stencil", + "Allerta", + "Amaranth", + "Anton", + "Architects+Daughter", + "Arimo", + "Artifika", + "Arvo", + "Asset", + "Astloch", + "Bangers", + "Bentham", + "Bevan", + "Bigshot+One", + "Bowlby+One", + "Bowlby+One+SC", + "Brawler", + "Buda", + "Cabin", + "Calligraffitti", + "Candal", + "Cantarell", + "Cardo", + "Carter One", + "Caudex", + "Cedarville+Cursive", + "Cherry+Cream+Soda", + "Chewy", + "Coda", + "Coming+Soon", + "Copse", + "Corben", + "Cousine", + "Covered+By+Your+Grace", + "Crafty+Girls", + "Crimson+Text", + "Crushed", + "Cuprum", + "Damion", + "Dancing+Script", + "Dawning+of+a+New+Day", + "Didact+Gothic", + "Droid+Sans", + "Droid+Sans+Mono", + "Droid+Serif", + "EB+Garamond", + "Expletus+Sans", + "Fontdiner+Swanky", + "Forum", + "Francois+One", + "Geo", + "Give+You+Glory", + "Goblin+One", + "Goudy+Bookletter+1911", + "Gravitas+One", + "Gruppo", + "Hammersmith+One", + "Holtwood+One+SC", + "Homemade+Apple", + "Inconsolata", + "Indie+Flower", + "IM+Fell+DW+Pica", + "IM+Fell+DW+Pica+SC", + "IM+Fell+Double+Pica", + "IM+Fell+Double+Pica+SC", + "IM+Fell+English", + "IM+Fell+English+SC", + "IM+Fell+French+Canon", + "IM+Fell+French+Canon+SC", + "IM+Fell+Great+Primer", + "IM+Fell+Great+Primer+SC", + "Irish+Grover", + "Irish+Growler", + "Istok+Web", + "Josefin+Sans", + "Josefin+Slab", + "Judson", + "Jura", + "Just+Another+Hand", + "Just+Me+Again+Down+Here", + "Kameron", + "Kenia", + "Kranky", + "Kreon", + "Kristi", + "La+Belle+Aurore", + "Lato", + "League+Script", + "Lekton", + "Limelight", + "Lobster", + "Lobster Two", + "Lora", + "Love+Ya+Like+A+Sister", + "Loved+by+the+King", + "Luckiest+Guy", + "Maiden+Orange", + "Mako", + "Maven+Pro", + "Meddon", + "MedievalSharp", + "Megrim", + "Merriweather", + "Metrophobic", + "Michroma", + "Miltonian Tattoo", + "Miltonian", + "Modern Antiqua", + "Monofett", + "Molengo", + "Mountains of Christmas", + "Muli", + "Neucha", + "Neuton", + "News+Cycle", + "Nixie+One", + "Nobile", + "Nova+Cut", + "Nova+Flat", + "Nova+Mono", + "Nova+Oval", + "Nova+Round", + "Nova+Script", + "Nova+Slim", + "Nova+Square", + "Nunito", + "OFL+Sorts+Mill+Goudy+TT", + "Old+Standard+TT", + "Open+Sans", + "Open+Sans+Condensed", + "Orbitron", + "Oswald", + "Over+the+Rainbow", + "Reenie+Beanie", + "Pacifico", + "Patrick+Hand", + "Paytone+One", + "Permanent+Marker", + "Philosopher", + "Play", + "Playfair+Display", + "Podkova", + "PT+Sans", + "PT+Sans+Narrow", + "PT+Serif", + "PT+Serif Caption", + "Puritan", + "Quattrocento", + "Quattrocento+Sans", + "Radley", + "Raleway", + "Redressed", + "Rock+Salt", + "Rokkitt", + "Roboto", + "Ruslan+Display", + "Schoolbell", + "Shadows+Into+Light", + "Shanti", + "Sigmar+One", + "Six+Caps", + "Slackey", + "Smythe", + "Sniglet", + "Special+Elite", + "Stardos+Stencil", + "Sue+Ellen+Francisco", + "Sunshiney", + "Swanky+and+Moo+Moo", + "Syncopate", + "Tangerine", + "Tenor+Sans", + "Terminal+Dosis+Light", + "The+Girl+Next+Door", + "Tinos", + "Ubuntu", + "Ultra", + "Unkempt", + "UnifrakturCook", + "UnifrakturMaguntia", + "Varela", + "Varela Round", + "Vibur", + "Vollkorn", + "VT323", + "Waiting+for+the+Sunrise", + "Wallpoet", + "Walter+Turncoat", + "Wire+One", + "Yanone+Kaffeesatz", + "Yeseva+One", + "Zeyada", + ]; + $.fontselect = { - google_fonts: [ - "Aclonica", - "Allan", - "Annie+Use+Your+Telescope", - "Anonymous+Pro", - "Allerta+Stencil", - "Allerta", - "Amaranth", - "Anton", - "Architects+Daughter", - "Arimo", - "Artifika", - "Arvo", - "Asset", - "Astloch", - "Bangers", - "Bentham", - "Bevan", - "Bigshot+One", - "Bowlby+One", - "Bowlby+One+SC", - "Brawler", - "Buda", - "Cabin", - "Calligraffitti", - "Candal", - "Cantarell", - "Cardo", - "Carter One", - "Caudex", - "Cedarville+Cursive", - "Cherry+Cream+Soda", - "Chewy", - "Coda", - "Coming+Soon", - "Copse", - "Corben", - "Cousine", - "Covered+By+Your+Grace", - "Crafty+Girls", - "Crimson+Text", - "Crushed", - "Cuprum", - "Damion", - "Dancing+Script", - "Dawning+of+a+New+Day", - "Didact+Gothic", - "Droid+Sans", - "Droid+Sans+Mono", - "Droid+Serif", - "EB+Garamond", - "Expletus+Sans", - "Fontdiner+Swanky", - "Forum", - "Francois+One", - "Geo", - "Give+You+Glory", - "Goblin+One", - "Goudy+Bookletter+1911", - "Gravitas+One", - "Gruppo", - "Hammersmith+One", - "Holtwood+One+SC", - "Homemade+Apple", - "Inconsolata", - "Indie+Flower", - "IM+Fell+DW+Pica", - "IM+Fell+DW+Pica+SC", - "IM+Fell+Double+Pica", - "IM+Fell+Double+Pica+SC", - "IM+Fell+English", - "IM+Fell+English+SC", - "IM+Fell+French+Canon", - "IM+Fell+French+Canon+SC", - "IM+Fell+Great+Primer", - "IM+Fell+Great+Primer+SC", - "Irish+Grover", - "Irish+Growler", - "Istok+Web", - "Josefin+Sans", - "Josefin+Slab", - "Judson", - "Jura", - "Just+Another+Hand", - "Just+Me+Again+Down+Here", - "Kameron", - "Kenia", - "Kranky", - "Kreon", - "Kristi", - "La+Belle+Aurore", - "Lato", - "League+Script", - "Lekton", - "Limelight", - "Lobster", - "Lobster Two", - "Lora", - "Love+Ya+Like+A+Sister", - "Loved+by+the+King", - "Luckiest+Guy", - "Maiden+Orange", - "Mako", - "Maven+Pro", - "Meddon", - "MedievalSharp", - "Megrim", - "Merriweather", - "Metrophobic", - "Michroma", - "Miltonian Tattoo", - "Miltonian", - "Modern Antiqua", - "Monofett", - "Molengo", - "Mountains of Christmas", - "Muli", - "Neucha", - "Neuton", - "News+Cycle", - "Nixie+One", - "Nobile", - "Nova+Cut", - "Nova+Flat", - "Nova+Mono", - "Nova+Oval", - "Nova+Round", - "Nova+Script", - "Nova+Slim", - "Nova+Square", - "Nunito", - "OFL+Sorts+Mill+Goudy+TT", - "Old+Standard+TT", - "Open+Sans", - "Open+Sans+Condensed", - "Orbitron", - "Oswald", - "Over+the+Rainbow", - "Reenie+Beanie", - "Pacifico", - "Patrick+Hand", - "Paytone+One", - "Permanent+Marker", - "Philosopher", - "Play", - "Playfair+Display", - "Podkova", - "PT+Sans", - "PT+Sans+Narrow", - "PT+Serif", - "PT+Serif Caption", - "Puritan", - "Quattrocento", - "Quattrocento+Sans", - "Radley", - "Raleway", - "Redressed", - "Rock+Salt", - "Rokkitt", - "Roboto", - "Ruslan+Display", - "Schoolbell", - "Shadows+Into+Light", - "Shanti", - "Sigmar+One", - "Six+Caps", - "Slackey", - "Smythe", - "Sniglet", - "Special+Elite", - "Stardos+Stencil", - "Sue+Ellen+Francisco", - "Sunshiney", - "Swanky+and+Moo+Moo", - "Syncopate", - "Tangerine", - "Tenor+Sans", - "Terminal+Dosis+Light", - "The+Girl+Next+Door", - "Tinos", - "Ubuntu", - "Ultra", - "Unkempt", - "UnifrakturCook", - "UnifrakturMaguntia", - "Varela", - "Varela Round", - "Vibur", - "Vollkorn", - "VT323", - "Waiting+for+the+Sunrise", - "Wallpoet", - "Walter+Turncoat", - "Wire+One", - "Yanone+Kaffeesatz", - "Yeseva+One", - "Zeyada", - ], settings: { style: "font-select", placeholder: "Select a font", @@ -511,7 +514,10 @@ class FontSelect { }; //console.log('length of google fonts before api call: ' + $.fontselect.google_fonts.length); - $.fontselect.google_fonts = await FontSelect.init($.fontselect.settings).then( data => data.items.map( item => item.family.replace(/ /g, "+") ) ); + $.fontselect.google_fonts = await FontSelect.init($.fontselect.settings).then( data => data.items.map( item => item.family.replace(/ /g, "+") ), reject => reject ).catch(ex => { + console.log('Google Font API key not detected, using fallback list...'); + console.warn(ex); + }) || google_fonts; //console.log('length of google fonts after api call: ' + $.fontselect.google_fonts.length); Object.defineProperty($.fontselect, "version", {