Created
March 28, 2013 15:35
-
-
Save natecavanaugh/5264133 to your computer and use it in GitHub Desktop.
Getting cached AUI instance to accomodate for cross-window retrieval
This file contains hidden or 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
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