Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add YUI, $script.js, toast, and little-loader
Recommend little-loader. Make clear that this is a reference implementation.
- Loading branch information
Showing
10 changed files
with
12,203 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('little-loader'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('scriptjs'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('pyrsmk-toast'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
var YUI = require('../vendor/yui'); | ||
var sandbox = YUI(); // YUI instances are called sandboxes. | ||
var Y; | ||
|
||
function loadScript(src, callback) { | ||
var options = { async: true }; // Is false by default. | ||
var tx = Y.Get.js(src, options, callback); | ||
// This is the most important bit. Each call is a transaction, and | ||
// transactions are processed serially. That means you can't actually load | ||
// scripts in parallel if you use Get multiple times. Calling `execute` will | ||
// ensure that we fetch right away, in parallel with any other transactions. | ||
tx.execute(); | ||
} | ||
|
||
module.exports = function(src, callback) { | ||
if (Y) { | ||
loadScript(src, callback); | ||
} else { | ||
sandbox.use('get', function(instance) { | ||
Y = instance; // Save Y instance so we don't have to do this every time. | ||
loadScript(src, callback); | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,69 @@ | ||
var expect = require("expect.js"); // Can't use Chai due to IE8. | ||
var loadScript = require("../loader"); | ||
|
||
describe("loadScript", function() { | ||
it("runs the callback after execution", function(done) { | ||
// Sometimes IE (via Sauce Labs) loads these scripts VERY slowly. | ||
this.timeout(300000); | ||
// Could be done with an async library or Promises, but this works fine | ||
// for now. | ||
var count = 0; | ||
function checkDone() { | ||
if (++count === 10) { | ||
done(); | ||
} | ||
function jQueryTest(done) { | ||
// Sometimes IE (via Sauce Labs) loads these scripts VERY slowly. | ||
this.timeout(300000); | ||
// Could be done with an async library or Promises, but this works fine | ||
// for now. | ||
var count = 0; | ||
function checkDone() { | ||
if (++count === 10) { | ||
done(); | ||
} | ||
function assertIsolatedLoad(version) { | ||
// Need the try/catch because we're in an async callback and any assertion | ||
// errors thrown won't be caught by Mocha; it'll time out instead. | ||
try { | ||
// jQuery must exist. | ||
expect(window.jQuery).to.be.a('function'); | ||
// Remove the global. | ||
var jQuery = window.jQuery.noConflict(true); | ||
// Shouldn't be an instance we've previously loaded and marked. | ||
expect(jQuery.FOO).to.be(undefined); | ||
// Should be the expected version. | ||
expect(jQuery.fn.jquery).to.equal(version); | ||
// Mark the instance with a flag. | ||
jQuery.FOO = true; | ||
checkDone(); | ||
} catch(err) { | ||
done(err); | ||
} | ||
} | ||
function assertIsolatedLoad(version) { | ||
// Need the try/catch because we're in an async callback and any assertion | ||
// errors thrown won't be caught by Mocha; it'll time out instead. | ||
try { | ||
// jQuery must exist. | ||
expect(window.jQuery).to.be.a('function'); | ||
// Remove the global. | ||
var jQuery = window.jQuery.noConflict(true); | ||
// Shouldn't be an instance we've previously loaded and marked. | ||
expect(jQuery.FOO).to.be(undefined); | ||
// Should be the expected version. | ||
expect(jQuery.fn.jquery).to.equal(version); | ||
// Mark the instance with a flag. | ||
jQuery.FOO = true; | ||
checkDone(); | ||
} catch(err) { | ||
done(err); | ||
} | ||
loadScript("http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js", function() { | ||
assertIsolatedLoad("1.11.3"); | ||
}); | ||
loadScript("http://code.jquery.com/jquery-1.11.3.min.js", function() { | ||
assertIsolatedLoad("1.11.3"); | ||
}); | ||
loadScript("http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js", function() { | ||
assertIsolatedLoad("1.11.2"); | ||
}); | ||
loadScript("http://code.jquery.com/jquery-1.11.2.min.js", function() { | ||
assertIsolatedLoad("1.11.2"); | ||
}); | ||
loadScript("http://code.jquery.com/jquery-1.7.2.min.js", function() { | ||
assertIsolatedLoad("1.7.2"); | ||
}); | ||
loadScript("http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js", function() { | ||
assertIsolatedLoad("1.11.1"); | ||
}); | ||
loadScript("http://code.jquery.com/jquery-1.11.1.min.js", function() { | ||
assertIsolatedLoad("1.11.1"); | ||
}); | ||
loadScript("http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js", function() { | ||
assertIsolatedLoad("1.7.2"); | ||
}); | ||
loadScript("http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js", function() { | ||
assertIsolatedLoad("1.11.3"); | ||
}); | ||
loadScript("http://code.jquery.com/jquery-1.11.3.min.js", function() { | ||
assertIsolatedLoad("1.11.3"); | ||
}); | ||
} | ||
loadScript("http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js", function() { | ||
assertIsolatedLoad("1.11.3"); | ||
}); | ||
loadScript("http://code.jquery.com/jquery-1.11.3.min.js", function() { | ||
assertIsolatedLoad("1.11.3"); | ||
}); | ||
loadScript("http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js", function() { | ||
assertIsolatedLoad("1.11.2"); | ||
}); | ||
loadScript("http://code.jquery.com/jquery-1.11.2.min.js", function() { | ||
assertIsolatedLoad("1.11.2"); | ||
}); | ||
loadScript("http://code.jquery.com/jquery-1.7.2.min.js", function() { | ||
assertIsolatedLoad("1.7.2"); | ||
}); | ||
loadScript("http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js", function() { | ||
assertIsolatedLoad("1.11.1"); | ||
}); | ||
loadScript("http://code.jquery.com/jquery-1.11.1.min.js", function() { | ||
assertIsolatedLoad("1.11.1"); | ||
}); | ||
loadScript("http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js", function() { | ||
assertIsolatedLoad("1.7.2"); | ||
}); | ||
loadScript("http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js", function() { | ||
assertIsolatedLoad("1.11.3"); | ||
}); | ||
loadScript("http://code.jquery.com/jquery-1.11.3.min.js", function() { | ||
assertIsolatedLoad("1.11.3"); | ||
}); | ||
} | ||
|
||
describe("loadScript", function() { | ||
it("atomically fires the callback after execution", jQueryTest); | ||
it("runs the exact same test again for good measure", jQueryTest); | ||
}); |
Oops, something went wrong.