Skip to content

Instantly share code, notes, and snippets.

@natecavanaugh
Created March 28, 2013 15:35
Show Gist options
  • Save natecavanaugh/5264133 to your computer and use it in GitHub Desktop.
Save natecavanaugh/5264133 to your computer and use it in GitHub Desktop.
Getting cached AUI instance to accomodate for cross-window retrieval
var getCachedInstance = function(yuiInstance, o, args) {
var instance = this;
// Need the current window, not A.config.win
var alloyInstance = yuiInstance._AUI_CACHED || ALLOY;
if (o || instance instanceof AUI) {
args = ALLOY.Array(args);
args.unshift(ALLOY.config);
var newInstance = yuiInstance.apply(null, args);
AUI._uaExtensions(newInstance);
AUI._miscExtensions(newInstance);
AUI._guidExtensions(newInstance);
var WIN = newInstance.config.win;
if (!WIN.YUI) {
WIN.YUI = yuiInstance;
}
if (!WIN.AUI) {
var auiFunction = function(){
console.log('new aui', WIN);
return getCachedInstance.call(this, WIN.YUI, o, arguments);
};
WIN.YUI.AUI = auiFunction;
WIN.AUI = auiFunction;
WIN.YUI._AUI_CACHED = newInstance;
}
if (!WIN.Alloy) {
WIN.Alloy = newInstance;
}
alloyInstance = newInstance;
}
return alloyInstance;
};
YUI.AUI = function(o) {
return getCachedInstance.call(this, WIN.YUI, o, arguments);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment