Monday, November 08, 2010 at 12:00 AM.

scripting2Suite.server.makeOutlineExpandable

on makeOutlineExpandable (adroutline) {
	<<Changes
		<<6/7/10; 3:10:12 PM by DW
			<<Take an outline and return HTML text for an expandble rendering of it. 
	local (xmltext = op.outlinetoxml (adroutline), htmltext = "\r", indentlevel = 0, showClassName = "showForOutline");
	xml.compile (xmltext, @xstruct);
	local (adropml = xml.getaddress (@xstruct, "opml"));
	local (adrbody = xml.getaddress (adropml, "body"));
	on add (s) {
		htmltext = htmltext + string.filledstring ("\t", indentlevel) + s + "\r\n"};
	on hassubs (adrx) { //return true if the outline node has sub-outlines
		local (adr);
		for adr in adrx {
			if nameof (adr^) endswith "outline" { //contains at least one sub
				return (true)}};
		return (false)};
	on decode (s) {
		return (xml.entitydecode (s, true))};
	on addlevel (adrlevel) {
		local (adr);
		for adr in adrlevel {
			if nameof (adr^) endswith "outline" {
				local (adratts = @adr^.["/atts"], text = decode (adratts^.text));
				if hassubs (adr) {
					local (iconname = "plus");
					local (id = string.innerCaseName (text) + random (1, 10000));
					<<local (icon = "<a href=\"javascript:expandCollapse('" + id + "');\"><img border=\"0\" align=\"left\" id=\"img_" + id + "\" src=\"http://www.scripting.com/mktree/" + iconname + ".gif\"></a>")
					local (icon = scripting2Suite.server.getExpandCollapseIcon (id, false, showClassName));
					add ("<div class=\"sidebarTitle\">" + icon + text + "</div>");
					bundle { //add the text in a special <div> that makes it expandable
						local (classname = "hide");
						add ("<div class=\"" + classname + "\" id=\"" + id + "\" name=\"" + id + "\">"); indentlevel++;
						level++;
						addlevel (adr);
						level--;
						add ("</div>"); indentlevel--}}
				else {
					if defined (adratts^.type) {
						case adratts^.type {
							"link" {
								text = "<a href=\"" + adratts^.url + "\">" + text + "</a>"}}};
					add ("<p class=\"collapsedSidebarText\">" + text + "</p>")}}}};
	local (level = 0);
	addlevel (adrbody);
	return (htmltext)};
bundle { //test code
	tc = clock.ticks ();
	makeOutlineExpandable (@workspace.testoutline);
	dialog.alert (clock.ticks () - tc)}



This listing is for code that runs in the OPML Editor environment. I created these listings because I wanted the search engines to index it, so that when I want to look up something in my codebase I don't have to use the much slower search functionality in my object database. Dave Winer.