Skip to content

Commit

Permalink
Fixes nathanford#8 to my knowledge and tests.
Browse files Browse the repository at this point in the history
Problem:
scount gets passed over into the web request and doesn't call runFills until scount == 1. The problem is that if you have multiple files being requested they will asynchronously complete at different times rather than sequentially as the code would expect to be ran when the last scount comes through. If you have styling that isn't in the first styling sheet and it's first to complete then it calls runFills which will only consist of the first sheet and not the rest. (Assuming it's collecting all the styles before checking for fills)

Fix:
Implemented a global counter that increments for each sheet and decrements when it's finished, whether it's inline or requested. Once all sheets have been collected runFills is then called.

Extra: I was going to implement a 304 check, but it seems it never fired, so I removed it.
  • Loading branch information
ctsstc committed May 5, 2015
1 parent 9d510ef commit 9dba004
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions js/mm-fontsize.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Notes:
*/

var gSheetsCount = 0;

var stylefill = {

allRules : new Object(),
Expand Down Expand Up @@ -81,8 +83,10 @@ var stylefill = {

},

loadFile : function(params, url, scount) {

loadFile : function(params, url) {

gSheetsCount ++;

var req;

if (window.XMLHttpRequest) req = new XMLHttpRequest();
Expand All @@ -92,7 +96,10 @@ var stylefill = {

req.onreadystatechange = function() {

if (this.readyState == 4 && this.status == 200) stylefill.findRules(params, this.responseText, scount);
if (this.readyState == 4) {
gSheetsCount --;
if(this.status == 200) stylefill.findRules(params, this.responseText);
}

};

Expand All @@ -116,8 +123,8 @@ var stylefill = {
var sheet = sheets[scount];

if (sheet == undefined) continue;
if (sheet.innerHTML) this.findRules(params, sheet.innerHTML, scount);
else if (sheet.href && sheet.href.match(document.domain)) this.loadFile(params, sheet.href, scount);
if (sheet.innerHTML) {gSheetsCount--; this.findRules(params, sheet.innerHTML);}
else if (sheet.href && sheet.href.match(document.domain)) this.loadFile(params, sheet.href);

}

Expand All @@ -136,7 +143,7 @@ var stylefill = {

},

findRules : function (params, sheettext, scount) {
findRules : function (params, sheettext) {

if (sheettext) {

Expand Down Expand Up @@ -172,7 +179,7 @@ var stylefill = {

}

if (scount == 1) this.runFills();
if (gSheetsCount == 0) this.runFills();

}

Expand Down

0 comments on commit 9dba004

Please sign in to comment.