Skip to content

Instantly share code, notes, and snippets.

@parker
Created June 27, 2011 22:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parker/1049989 to your computer and use it in GitHub Desktop.
Save parker/1049989 to your computer and use it in GitHub Desktop.
Attempting to hijack the global "io:complete" event so that it's accessible across YUI instances
// fetch profile results for any ajax calls done via jQuery
$(document).ajaxComplete(function (e, xhr, settings) {
if (xhr) {
var id = xhr.getResponseHeader('X-MiniProfiler-Id');
if (id) {
fetchResults(id);
}
}
});
// fetch profile results for any ajax calls done via YUI3
// CURRENTLY DOESN"T WORK
YUI().use("io-base", function (Y) {
Y.on("io:complete", function (trxId, xhr, args) {
if (xhr) {
var id = xhr.getResponseHeader('X-MiniProfiler-Id');
if (id) {
if (MiniProfiler) {
MiniProfiler.fetchResults(id);
}
}
}
});
});
Y1 = YUI().use("io-base", function(Y1)
{
Y1.Global.on("io:complete", function(){
Y1.log(arguments);
Y1.log("complete - Y1.Global");
});
Y1.on("io:complete", function(){
Y1.log(arguments);
Y1.log("complete - Y1.on");
});
Y1.publish("io:complete", { broadcast: 2} );
});
Y2 = YUI().use("io-base", function(Y2)
{
Y2.Global.on("io:complete", function(){
Y2.log(arguments);
Y2.log("complete - Y2.Global.on");
});
Y2.on("io:complete", function(){
Y2.log(arguments);
Y2.log("complete - Y2.on");
});
});
Y1.io("http://yui.yahooapis.com/3.3.0/build/yui/yui-min.js");
/*
complete - Y1.on
complete - Y1.Global
complete - Y2.Global.on
*/
Y2.io("http://yui.yahooapis.com/3.3.0/build/yui/yui-min.js");
/*
complete - Y2.on
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment