Skip to content

Loading…

Fixed double active event on IE9 #68

Merged
merged 4 commits into from

2 participants

@bramstein
Typekit member

This pull request fixes the double active event in IE9 reported in #64. The fix is implemented according to the suggestions made on MSDN:

http://msdn.microsoft.com/en-us/library/ie/hh180173(v=vs.85).aspx

@seanami

Nicely done, Bram! I don't think we'll get the attention of any fonts.com folks to review this, but given that you've explored this and the user in one of the references tickets has tried it and fixed the problem for them, I think we can go ahead with getting this merged at the same time that we merge the font watching fix next week.

@bramstein
Typekit member

I made some small changes and made this pull request up to date with the latest master. I've also tested this in IE6,7,8,9 and 10 and events are now fired correctly and once. I think this is ready to be merged in.

@seanami seanami merged commit f3bfe34 into master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 34 additions and 19 deletions.
  1. +20 −10 src-test/monotype/monotype_script_test.js
  2. +14 −9 src/monotype/monotype_script.js
View
30 src-test/monotype/monotype_script_test.js
@@ -8,8 +8,10 @@ MonotypeScriptTest.prototype.testIfScriptTagIsAdded = function () {
var config = { projectId: '01e2ff27-25bf-4801-a23e-73d328e6c7cc', api: "http://fast.fonts.com/jsapidev" };
var fakeDomHelper = {
- createScriptSrc: function (s) {
- script = { src: s };
+ createElement: function () {
+ script = {
+ addEventListener: function () {}
+ };
return script;
},
insertInto: function (tag, elem) {
@@ -67,8 +69,10 @@ MonotypeScriptTest.prototype.testIfScriptTagHasCorrectSSL = function () {
var config = { projectId: '01e2ff27-25bf-4801-a23e-73d328e6c7cc', api: "http://fast.fonts.com/jsapidev" };
var fakeDomHelper = {
- createScriptSrc: function (s) {
- script = { src: s };
+ createElement: function () {
+ script = {
+ addEventListener: function () {}
+ };
return script;
},
insertInto: function (tag, elem) {
@@ -139,8 +143,10 @@ MonotypeScriptTest.prototype.testIfScriptTagIsAddedWithoutApiurl = function () {
var config = { projectId: '01e2ff27-25bf-4801-a23e-73d328e6c7cc' };
var fakeDomHelper = {
- createScriptSrc: function (s) {
- script = { src: s };
+ createElement: function () {
+ script = {
+ addEventListener: function () {}
+ };
return script;
},
insertInto: function (tag, elem) {
@@ -199,8 +205,10 @@ MonotypeScriptTest.prototype.testIfScriptTagIsAddedWithoutApiurlAndTheScriptUrlH
var config = { projectId: '01e2ff27-25bf-4801-a23e-73d328e6c7cc' };
var fakeDomHelper = {
- createScriptSrc: function (s) {
- script = { src: s };
+ createElement: function () {
+ script = {
+ addEventListener: function () {}
+ };
return script;
},
insertInto: function (tag, elem) {
@@ -259,8 +267,10 @@ MonotypeScriptTest.prototype.testWithoutProjectId = function () {
var config = {};
var fakeDomHelper = {
- createScriptSrc: function (s) {
- script = { src: s };
+ createElement: function () {
+ script = {
+ addEventListener: function () {}
+ };
return script;
},
insertInto: function (tag, elem) {
View
23 src/monotype/monotype_script.js
@@ -40,18 +40,12 @@ webfont.MonotypeScript.prototype.supportUserAgent = function (userAgent, support
var self = this;
var projectId = self.configuration_['projectId'];
if (projectId) {
- var sc = self.domHelper_.createScriptSrc(self.getScriptSrc(projectId));
+ var sc = self.domHelper_.createElement("script");
sc["id"] = webfont.MonotypeScript.SCRIPTID + projectId;
- sc["onreadystatechange"] = function (e) {
- if (sc["readyState"] === "loaded" || sc["readyState"] === "complete") {
- sc["onreadystatechange"] = null;
- sc["onload"](e);
- }
- };
-
var loadWindow = this.domHelper_.getLoadWindow();
- sc["onload"] = function (e) {
+
+ function onload() {
if (loadWindow[webfont.MonotypeScript.HOOK + projectId]) {
var mti_fnts = loadWindow[webfont.MonotypeScript.HOOK + projectId]();
if (mti_fnts && mti_fnts.length) {
@@ -62,8 +56,19 @@ webfont.MonotypeScript.prototype.supportUserAgent = function (userAgent, support
}
}
support(userAgent.isSupportingWebFont());
+ }
+
+ var done = false;
+
+ sc["onload"] = sc["onreadystatechange"] = function () {
+ if (!done && (!this["readyState"] || this["readyState"] === "loaded" || this["readyState"] === "complete")) {
+ done = true;
+ onload();
+ sc["onload"] = sc["onreadystatechange"] = null;
+ }
};
+ sc["src"] = self.getScriptSrc(projectId);
this.domHelper_.insertInto('head', sc);
}
else {
Something went wrong with that request. Please try again.