[rkward-cvs] SF.net SVN: rkward:[4143] trunk/rkward/rkward/rbackend/rpackages/rkward/R

m-eik at users.sourceforge.net m-eik at users.sourceforge.net
Sun Jan 8 14:54:36 UTC 2012


Revision: 4143
          http://rkward.svn.sourceforge.net/rkward/?rev=4143&view=rev
Author:   m-eik
Date:     2012-01-08 14:54:36 +0000 (Sun, 08 Jan 2012)
Log Message:
-----------
improved TOC menu in output document: fixed position, hidden by default, can be shown and hidden as you like.

Modified Paths:
--------------
    trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal.R
    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/rbackend/rpackages/rkward/R/internal.R
===================================================================
--- trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal.R	2012-01-07 22:38:45 UTC (rev 4142)
+++ trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal.R	2012-01-08 14:54:36 UTC (rev 4143)
@@ -358,7 +358,6 @@
 }
 
 ".rk.make.hr" <- function () {
-	.rk.cat.output ("<a href=\"#top\">Go to top</a>\n");
 	.rk.cat.output ("<hr>\n");
 }
 

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-07 22:38:45 UTC (rev 4142)
+++ trunk/rkward/rkward/rbackend/rpackages/rkward/R/rk.filename-functions.R	2012-01-08 14:54:36 UTC (rev 4143)
@@ -70,29 +70,73 @@
 	if (!file.exists (x)) {
 		.rk.cat.output (paste ("<?xml version=\"1.0\" encoding=\"", .Call ("rk.locale.name"), "\"?>\n", sep=""))
 		.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 menu in the document
+		# 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 addToMenu(id){
+		function addToTOC(id){
 			var fullHeader = document.getElementById(id);
-			var resultsMenu = document.getElementById('RKWardResultsMenu');
+			var resultsTOC = document.getElementById('RKWardResultsTOCShown');
 			var headerName = fullHeader.getAttribute('name');
 			var headerText = fullHeader.firstChild.data;
-			// create new anchor for menu
+			var headerTitle = fullHeader.getAttribute('title');
+			// 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');
-			var anchorText = document.createTextNode(headerText);
 			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);
-			resultsMenu.appendChild(newAnchor);
-			resultsMenu.appendChild(newLine);
+			resultsTOC.appendChild(newAnchor);
+			resultsTOC.appendChild(newLine);
+		}
+		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;
+		}
+		.toggleTOC:link, .toggleTOC:visited {
+			color: blue;
+			font-weight: bold;
+		}
+		.right {
+			position: absolute;
+			right: 7px;
+		}\n\t</style>\n", sep=""))
 		.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 menu gets added to dynamically
-		.rk.cat.output (paste ("<div id=\"RKWardResultsMenu\"><!-- the menu goes here --></div>\n", sep=""))
+		# 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<!-- 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",
+			"</div>\n", sep=""))
 	}
 
 	# needs to come after initialization, so initialization alone does not trigger an update during startup

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-07 22:38:45 UTC (rev 4142)
+++ trunk/rkward/rkward/rbackend/rpackages/rkward/R/rk.print-functions.R	2012-01-08 14:54:36 UTC (rev 4143)
@@ -38,9 +38,9 @@
 #'   the header with \code{<h2></h>} tag.
 #' @param parameters a list, preferably named, giving a list of "parameters" to
 #'   be printed to the output
-#' @param menu If \code{NULL}, the default, \code{rk.header()} will automatically
-#'   add h1 headers to the menu. \code{TRUE} will always add the header, and
-#'   \code{FALSE} will suppress it.
+#' @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 the header, and \code{FALSE} will suppress it.
 #' @param titles a character vector, giving the column headers for a html
 #'   table.
 #' @param print.rownames controls printing of rownames. TRUE to force printing,
@@ -99,20 +99,21 @@
 	.rk.cat.output (.rk.do.plain.call ("highlightRCode", as.character (code)))
 }
 
-"rk.header" <- function (title, parameters=list (), level=1, menu=NULL) {
+"rk.header" <- function (title, parameters=list (), level=1, toc=NULL) {
 	sink (rk.get.output.html.file(), append=TRUE)
 	on.exit (sink ())
 
 	# give header a name to be able to set anchors
-	# it's just a time string down to the fraction of a second: yyyymmddHHMMSS.ssssss
-	header.id <- format(Sys.time(), "%Y%m%d%H%M%OS6")
-	# add 'id' and 'name' attributes to the header
-	cat ("<h", level, "><a  id=\"", header.id,"\" name=\"", header.id,"n\">", title, "</a></h", level, ">\n", sep="")
-	# if 'menu' is true, also add a javascript function call to add this header to the results menu
-	# the function addToMenu() will be defined in the document head
+	# it's just a time string down to the fraction of a second: yyyy-mm-dd HH:MM:SS.ssssss
+	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="")
+	# 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(menu) || (is.null(menu) && level == 1)){
-		cat("<script>\n\t<!--\n\t\taddToMenu('", header.id,"');\n\t-->\n</script>\n", sep="")
+	if (isTRUE(toc) || (is.null(toc) && level == 1)){
+		cat("<script>\n\t<!--\n\t\taddToTOC('", header.id,"');\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