Jump to content

User:Gerbrant/mng/listModules.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
new function()
{
	var globalScope = window;
	var frameworkObject = Gerbrant.fw;
	var namespaces = {};

//      ----------------------------------

	var self = this;
	var myWin = null;

	function dumpObject(buffer, name, obj)
	{
		var i;

		buffer.push("<dt>");
		buffer.push(name);
		switch(typeof obj)
		{
		case "object":
			buffer.push("</dt><dd><dl>");
			for(i in obj)
				dumpObject(buffer, i, obj[i]);
			buffer.push("</dl></dd>");
			break;
		case "function":
			buffer.push("()</dt>");
			break;
		default:
			buffer.push(" = ");
			buffer.push(obj);
			buffer.push("</dt>");
		}
	}

	function refreshWindow()
	{
		var buffer = [], i;
		buffer.push("<dl>");
		for(i in namespaces)
			dumpObject(buffer, i, namespaces[i]);
		buffer.push("</dl>");
		myWin.setContentHTML(buffer.join(""));
	}

	var oldLM = frameworkObject.module;
	var newLM = function(moduleName, callback)
	{
		oldLM(moduleName, callback);
		var NN = moduleName.slice(0, moduleName.indexOf("."));
		namespaces[NN] = globalScope[NN];
		if(myWin != null) refreshWindow();
	}
	frameworkObject.module = newLM;
	globalScope.module = newLM;

	this.show = function()
	{
		if(myWin == null)
			myWin = new Gerbrant.gui.window("Modules");
		refreshWindow();
	}
	this.caption = "Modules";

	loadModule("Gerbrant.gui.window", function()
	{
		module("Gerbrant.mng.listModules", self);
	});
}