Quick and dirty modification:
(function (UI, B, e, a, r, d)
{
try
{
while (r = UI.frames[e++])
{
if ((a = r.$display && r.$display.getView()) && a.getId() == B)
{
d = a;
break;
}
}
var onSchemaLoaded = function()
{
m1.$evt.removeEventHandler(schema, 'load', onSchemaLoaded);
alert('Schema URI: ' + schema.getId() + ', Title: ' + schema.getTitle());
}
var m1 = window.top.frames[1];
var myitem = d.getMainInterface().getListSelection();
var comp = m1.$models.getItem(myitem.getVersionlessIds()[0]);
var schema = comp.getSchema();
m1.$evt.addEventHandler(schema, 'load', onSchemaLoaded);
schema.load();
}
catch (x) {};
})(window.top, 'DashboardView', 0)
Alternatively, if you only want the ID and Title of the Schema, you could simply load it from the Component XML. You would need to load the Component instead, then, but at least you can be reasonably certain the the user is allowed to read the Component if he can select it (whereas he might not have access to the Schema).
Edit: Here's an example of the alternative solution I mentioned:
(function ()
{
try
{
var frame;
var view;
function initialize()
{
var topFrame = window.top;
var index = 0;
var v, currentFrame;
while (currentFrame = topFrame.frames[index++])
{
if ((v = currentFrame.$display && currentFrame.$display.getView()) && v.getId() == 'DashboardView')
{
view = v;
frame = currentFrame;
return;
}
}
}
function onComponentLoaded()
{
if (load) evt.removeEventHandler(comp, 'load', onComponentLoaded);
var xmlDoc = comp.getXmlDocument();
var schemaId = xml.getInnerText(xmlDoc, "/tcm:Component/tcm:Data/tcm:Schema/@xlink:href");
var schemaTitle = xml.getInnerText(xmlDoc, "/tcm:Component/tcm:Data/tcm:Schema/@xlink:title");
if (load) comp.invalidateEditableProperties();
alert('Schema URI: ' + schemaId + '\nSchema Title: ' + schemaTitle);
}
initialize();
var evt = frame.$evt;
var models = frame.$models;
var xml = frame.$xml;
var selectedItemId = view.getMainInterface().getListSelection().getVersionlessIds()[0];
if (!selectedItemId) return;
var comp = models.getItem(selectedItemId);
var load = !comp.isLoaded();
if (load)
{
evt.addEventHandler(comp, 'load', onComponentLoaded);
comp.load();
}
else
{
onComponentLoaded();
}
}
catch (x) {};
})()
It handles the case where the Component has to be loaded and then unloaded again afterwards. It can certainly be made less verbose, to your liking.