Created
August 18, 2010 21:34
-
-
Save FrozenCanuck/536260 to your computer and use it in GitHub Desktop.
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
function findClassNames() { | |
if (SC._object_foundObjectClassNames) return ; | |
SC._object_foundObjectClassNames = true ; | |
var seen = [] ; | |
var detectedSC = false; | |
var searchObject = function(root, object, levels) { | |
levels-- ; | |
// not the fastest, but safe | |
if (seen.indexOf(object) >= 0) return ; | |
seen.push(object) ; | |
for(var key in object) { | |
if (key == '__scope__') continue ; | |
if (key == 'superclass') continue ; | |
if (key == '__SC__') key = 'SC' ; | |
if (!key.match(/^[A-Z0-9]/)) continue ; | |
if (key == 'SC') { | |
if (detectedSC) continue; | |
detectedSC = true; | |
} | |
var path = (root) ? [root,key].join('.') : key ; | |
var value = object[key] ; | |
switch(SC.typeOf(value)) { | |
case SC.T_CLASS: | |
if (!value._object_className) value._object_className = path; | |
if (levels>=0) searchObject(path, value, levels) ; | |
break ; | |
case SC.T_OBJECT: | |
if (levels>=0) searchObject(path, value, levels) ; | |
break ; | |
case SC.T_HASH: | |
if (((root) || (path==='SC')) && (levels>=0)) searchObject(path, value, levels) ; | |
break ; | |
default: | |
break; | |
} | |
} | |
} ; | |
// Fix for IE 7 and 8 in order to detect the SC global variable. When you create | |
// a global variable in IE, it is not added to the window object like in other | |
// browsers. Therefore the searchObject method will not pick it up. So we have to | |
// update the window object to have a reference to the global variable. And | |
// doing window['SC'] does not work since the global variable already exists. For | |
// any object that you create that is used act as a namespace, be sure to create it | |
// like so: | |
// | |
// window.MyApp = window.MyApp || SC.Object.create({ ... }) | |
// | |
window['__SC__'] = SC; | |
searchObject(null, window, 2) ; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment