Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 37 additions & 17 deletions src/_phantomjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,45 +14,65 @@
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);
if (error) {
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);
phantom.exit(1);
}
});

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);
}
}

Expand All @@ -77,4 +97,4 @@
}
}

}());
}());
25 changes: 6 additions & 19 deletions src/client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,14 @@

<script>
(function(d) {
window.wwp_loadedFonts = [];
var config = window.__typekitConfig || {};
config.kitId = 'qzr7zlc';
config.scriptTimeout = 3000;

function done() {
console.log("TODO: hook up to PhantomJS");
}

var config = {
kitId: 'qzr7zlc',
scriptTimeout: 3000,
active: done,
inactive: done,
fontactive: function(family, variant) {
window.wwp_loadedFonts.push({
family: family,
variant: variant
});
}
},
h = d.documentElement,
var h = d.documentElement,
t = setTimeout(function() {
h.className = h.className.replace(/\bwf-loading\b/g, "") + " wf-inactive";
if (typeof config.inactive === "function") config.inactive();
}, config.scriptTimeout),
tk = d.createElement("script"),
f = false,
Expand Down Expand Up @@ -83,4 +70,4 @@ <h1 id="logo"><img src="/images/weewiki-logo.png" width="181" height="25" alt="W
</script>

</body>
</html>
</html>