[rkward-cvs] SF.net SVN: rkward:[4145] trunk/rkward/rkward

m-eik at users.sourceforge.net m-eik at users.sourceforge.net
Sun Jan 8 21:06:32 UTC 2012


Revision: 4145
          http://rkward.svn.sourceforge.net/rkward/?rev=4145&view=rev
Author:   m-eik
Date:     2012-01-08 21:06:31 +0000 (Sun, 08 Jan 2012)
Log Message:
-----------
added indentation to output TOC menu, h2 is now also added by default. if the TOC gets too long, it will automatically become scrollable, and also the maximum level can be defined. the latter looks quite ugly if you increse the maximum again: indentation gets lost and level 3 objects even end up in the previous line.

Modified Paths:
--------------
    trunk/rkward/rkward/pages/rkward_output.css
    trunk/rkward/rkward/rbackend/rpackages/rkward/R/rk.filename-functions.R
    trunk/rkward/rkward/rbackend/rpackages/rkward/R/rk.print-functions.R

Modified: trunk/rkward/rkward/pages/rkward_output.css
===================================================================
--- trunk/rkward/rkward/pages/rkward_output.css	2012-01-08 17:48:19 UTC (rev 4144)
+++ trunk/rkward/rkward/pages/rkward_output.css	2012-01-08 21:06:31 UTC (rev 4145)
@@ -22,4 +22,35 @@
 
 table {
 	border-spacing: 0px;
-}
\ No newline at end of file
+}
+
+/* TOC menu */
+.RKTOC {
+	background-color: #eeeeff;
+	position: fixed;
+	top: 0px;
+	right: 0px;
+	height: 100%;
+	width: 25%;
+	padding: 7px;
+	display: none;
+	overflow: auto;
+}
+
+.RKTOChidden {
+	display: inline;
+	height: 1em;
+	overflow: hidden;
+}
+
+.toggleTOC:link, .toggleTOC:visited {
+	color: blue;
+	font-weight: bold;
+}
+
+.right {
+	position: absolute;
+	right: 7px;
+	text-align: right;
+}
+/* end TOC menu */

Modified: trunk/rkward/rkward/rbackend/rpackages/rkward/R/rk.filename-functions.R
===================================================================
--- trunk/rkward/rkward/rbackend/rpackages/rkward/R/rk.filename-functions.R	2012-01-08 17:48:19 UTC (rev 4144)
+++ trunk/rkward/rkward/rbackend/rpackages/rkward/R/rk.filename-functions.R	2012-01-08 21:06:31 UTC (rev 4145)
@@ -72,70 +72,70 @@
 		.rk.cat.output (paste ("<html><head>\n<title>RKWard Output</title>\n", .rk.do.plain.call ("getCSSlink"), sep=""))
 		# the next part defines a JavaScript function to add individual results to a global table of contents menu in the document
 		.rk.cat.output (paste ("\t<script type=\"text/javascript\">
-		function addToTOC(id){
+		function addToTOC(id, level){
 			var fullHeader = document.getElementById(id);
 			var resultsTOC = document.getElementById('RKWardResultsTOCShown');
 			var headerName = fullHeader.getAttribute('name');
 			var headerText = fullHeader.firstChild.data;
 			var headerTitle = fullHeader.getAttribute('title');
+			var newDiv = document.createElement('div');
 			// create new anchor for TOC
-			var newAnchor = document.createElement('a');
-			var newLine = document.createElement('br');
-			// add the reference to link to
-			var anchorRef = document.createAttribute('href');
-			anchorRef.nodeValue = '#' + headerName;
-			newAnchor.setAttributeNode(anchorRef);
-			// add a 'title' attribute
-			var anchorTitle = document.createAttribute('title');
-			anchorTitle.nodeValue = headerTitle;
-			newAnchor.setAttributeNode(anchorTitle);
-			// make header text the anchor text
-			var anchorText = document.createTextNode(headerText);
-			newAnchor.appendChild(anchorText);
-			resultsTOC.appendChild(newAnchor);
-			resultsTOC.appendChild(newLine);
+			var newAnchor = '<a href=\"#' + headerName + '\" title=\"' + headerTitle + '\"';
+			// indent anchor depending on header level
+			if(level > 1){
+				newDiv.style.textIndent = level-1 + 'em';
+				newDiv.className = 'level' + level;
+				newAnchor = '• ' + newAnchor + '>' + headerText + '</a>';
+			} else {
+				newAnchor = newAnchor + '>' + headerText + '</a>';
+			}
+			newDiv.innerHTML = newAnchor;
+			resultsTOC.appendChild(newDiv);
 		}
 		function switchVisible(show, hide) {
 			document.getElementById(show).style.display = 'inline';
 			document.getElementById(hide).style.display = 'none';
-		}\n\t</script>\n", sep=""))
-		# positioning the TOC with CSS
-		# default state is hidden
-		.rk.cat.output (paste ("\t<style type=\"text/css\">
-		.RKTOC {
-			background-color: #eeeeff;
-			position: fixed;
-			top: 0px;
-			right: 0px;
-			height: 100%;
-			width: 25%;
-			padding: 7px;
-			display: none;
 		}
-		.RKTOChidden {
-			display: inline;
-			height: 1em;
+		function showMLevel(nodes){
+			for(var i=0; i < nodes.length; i++) {
+				nodes[i].style.display = 'inline';
+			}
 		}
-		.toggleTOC:link, .toggleTOC:visited {
-			color: blue;
-			font-weight: bold;
+		function hideMLevel(nodes){
+			for(var i=0; i < nodes.length; i++) {
+				nodes[i].style.display = 'none';
+			}
 		}
-		.right {
-			position: absolute;
-			right: 7px;
-		}\n\t</style>\n", sep=""))
+		function maxLevel(level){
+			if(level >= 3){
+				showMLevel(document.getElementsByClassName('level3'));
+			} else {
+				hideMLevel(document.getElementsByClassName('level3'));
+			}
+			if(level >= 2){
+				showMLevel(document.getElementsByClassName('level2'));
+			} else {
+				hideMLevel(document.getElementsByClassName('level2'));
+			}
+		}\n\t</script>\n", sep=""))
+		# positioning of the TOC is done by CSS, default state is hidden
+		# see $SRC/rkward/pages/rkward_output.css
 		.rk.cat.output (paste ("</head>\n<body>\n", sep=""))
 		# This initial output mostly to indicate the output is really there, just empty for now
 		.rk.cat.output (paste ("<a name=\"top\"></a>\n<pre>RKWard output initialized on", date (), "</pre>\n"))
 		# an empty <div> where the TOC menu gets added to dynamically, and a second one to toggle show/hide
 		.rk.cat.output (paste (
 			"<div id=\"RKWardResultsTOCShown\" class=\"RKTOC\">\n",
-			"\t<a onclick=\"javascript:switchVisible('RKWardResultsTOCHidden','RKWardResultsTOCShown')\" href=\"\" class=\"toggleTOC\">Hide TOC</a>\n",
-			"\t<span class=\"right\"><a href=\"#top\"class=\"toggleTOC\">Go to top</a></span><br />\n",
+			"\t<a onclick=\"javascript:switchVisible('RKWardResultsTOCHidden','RKWardResultsTOCShown'); return false;\" href=\"\" class=\"toggleTOC\">Hide TOC</a>\n",
+			"\t<span class=\"right\"><a href=\"#top\" class=\"toggleTOC\">Go to top</a><br />",
+			"\t\tMax. level: <a onclick=\"javascript:maxLevel('1'); return false;\" href=\"\" >1</a>\n",
+			"\t\t<a onclick=\"javascript:maxLevel('2'); return false;\" href=\"\" >2</a>\n",
+			"\t\t<a onclick=\"javascript:maxLevel('3'); return false;\" href=\"\" >3</a>\n",
+			"</span>\n",
 			"\t<!-- the TOC menu goes here -->\n</div>\n",
 			"<div id=\"RKWardResultsTOCHidden\" class=\"RKTOC RKTOChidden\">\n",
-			"\t<a onclick=\"javascript:switchVisible('RKWardResultsTOCShown','RKWardResultsTOCHidden')\" href=\"\" class=\"toggleTOC\">Show TOC</a>\n",
-			"\t<span class=\"right\"><a href=\"#top\" class=\"toggleTOC\">Go to top</a></span><br />\n",
+			"\t<a onclick=\"javascript:switchVisible('RKWardResultsTOCShown','RKWardResultsTOCHidden'); return false;\" href=\"\" class=\"toggleTOC\">Show TOC</a>\n",
+			"\t<span class=\"right\"><a href=\"#top\" class=\"toggleTOC\">Go to top</a></span>\n",
 			"</div>\n", sep=""))
 	}
 

Modified: trunk/rkward/rkward/rbackend/rpackages/rkward/R/rk.print-functions.R
===================================================================
--- trunk/rkward/rkward/rbackend/rpackages/rkward/R/rk.print-functions.R	2012-01-08 17:48:19 UTC (rev 4144)
+++ trunk/rkward/rkward/rbackend/rpackages/rkward/R/rk.print-functions.R	2012-01-08 21:06:31 UTC (rev 4145)
@@ -39,7 +39,7 @@
 #' @param parameters a list, preferably named, giving a list of "parameters" to
 #'   be printed to the output
 #' @param toc If \code{NULL}, the default, \code{rk.header()} will automatically
-#'   add h1 headers to the TOC menu of the output document. \code{TRUE} will always
+#'   add h1 and h2 headers to the TOC menu of the output document. \code{TRUE} will always
 #'   add the header, and \code{FALSE} will suppress it.
 #' @param titles a character vector, giving the column headers for a html
 #'   table.
@@ -108,12 +108,12 @@
 	header.id <- format(Sys.time(), "%Y-%m-%d_%H:%M:%OS6")
 	header.title <- format(Sys.time(), "%Y-%m-%d %H:%M:%S")
 	# add 'id', 'name' and 'title' attributes to the header
-	cat ("<h", level, "><a  id=\"", header.id,"\" name=\"", header.id,"n\" title=\"", header.title,"\">", title, "</a></h", level, ">\n", sep="")
+	cat ("<h", level, "><a id=\"", header.id,"\" name=\"", header.id,"n\" title=\"", header.title,"\">", title, "</a></h", level, ">\n", sep="")
 	# if 'toc' is true, also add a javascript function call to add this header to the TOC menu
 	# the function addToTOC() will be defined in the document head
 	# see rk.set.output.html.file() in rk.filename-functions.R
-	if (isTRUE(toc) || (is.null(toc) && level == 1)){
-		cat("<script>\n\t<!--\n\t\taddToTOC('", header.id,"');\n\t-->\n</script>\n", sep="")
+	if (isTRUE(toc) || (is.null(toc) && level <= 2)){
+		cat("<script>\n\t<!--\n\t\taddToTOC('",header.id,"','",level,"');\n\t-->\n</script>\n", sep="")
 	}
 	if (length (parameters)) {
 		# legacy handling: parameter=value used to be passed as parameter, value

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.





More information about the rkward-tracker mailing list