diff --git a/src/_phantomjs.js b/src/_phantomjs.js index eee56bfd7..d9fb90366 100644 --- a/src/_phantomjs.js +++ b/src/_phantomjs.js @@ -14,6 +14,35 @@ console.log("CONSOLE: " + message); }; + page.onInitialized = function () { + page.evaluate(function () { + var typekitConfig = window.__typekitConfig = {}; + var fonts = []; + + typekitConfig.fontactive = function fontactive(family, variant) { + fonts.push({ + family: family, + variant: variant + }); + }; + + typekitConfig.active = typekitConfig.inactive = function done() { + window.callPhantom(fonts); + }; + }); + }; + + page.onCallback = function (loadedFonts) { + var error = page.evaluate(checkFonts, loadedFonts); + if (error) { + console.log("error", error); + phantom.exit(1); + } + else { + phantom.exit(0); + } + }; + page.open("http://localhost:5000", function(success) { try { var error = page.evaluate(inBrowser); @@ -21,16 +50,6 @@ console.log(error); phantom.exit(1); } - else { - setTimeout(function() { - error = page.evaluate(checkFonts); - if (error) { - console.log("error", error); - phantom.exit(1); - } - phantom.exit(0); - }, 10000); - } } catch(err) { console.log("Exception in PhantomJS code", err); @@ -38,21 +57,22 @@ } }); - function checkFonts() { + function checkFonts(loadedFonts) { try { - checkFont("alwyn-new-rounded-web", "n3"); - checkFont("alwyn-new-rounded-web", "n4"); - checkFont("alwyn-new-rounded-web", "n7"); + checkFont(loadedFonts, "alwyn-new-rounded-web", "n3"); + checkFont(loadedFonts, "alwyn-new-rounded-web", "n4"); + checkFont(loadedFonts, "alwyn-new-rounded-web", "n6"); } catch (err) { return "checkFonts() failed: " + err.stack; } - function checkFont(family, variant) { - var hasFont = window.wwp_loadedFonts.some(function(loadedFont) { + function checkFont(loadedFonts, family, variant) { + var hasFont = loadedFonts.some(function(loadedFont) { return (loadedFont.family === family) && (loadedFont.variant === variant); }); if (!hasFont) throw new Error("font not loaded: " + family + " " + variant); + else console.log("font loaded: " + family + " " + variant); } } @@ -77,4 +97,4 @@ } } -}()); \ No newline at end of file +}()); diff --git a/src/client/index.html b/src/client/index.html index 4b40241ac..37a089131 100644 --- a/src/client/index.html +++ b/src/client/index.html @@ -11,27 +11,14 @@ - \ No newline at end of file +