Skip to content

Instantly share code, notes, and snippets.

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 FrozenCanuck/536260 to your computer and use it in GitHub Desktop.
Save FrozenCanuck/536260 to your computer and use it in GitHub Desktop.
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