[ease] JS based navigation in HTML exports.



commit c91373ddebe1a433f81210e870438f93fcd03b9b
Author: Nate Stedman <natesm gmail com>
Date:   Wed May 19 18:09:22 2010 -0400

    JS based navigation in HTML exports.

 src/libease/Document.vala     |    6 ++--
 src/libease/HTMLExporter.vala |   45 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+), 3 deletions(-)
---
diff --git a/src/libease/Document.vala b/src/libease/Document.vala
index f89519e..1cd516e 100644
--- a/src/libease/Document.vala
+++ b/src/libease/Document.vala
@@ -240,15 +240,15 @@ public class Ease.Document : GLib.Object
 		var html = "<!DOCTYPE html>\n<html>\n";
 		
 		// make the header
-		html += "<head>\n<title>Presentation</title>\n";
-		html += "<style>\n.slide {\nwidth:" + width.to_string() +
+		html += "<head>\n<title>Presentation</title>\n" + HTMLExporter.js;
+		html += "<style>\n.slide {\ndisplay:none;\nwidth:" + width.to_string() +
 		        "px;\noverflow:hidden;height:" + height.to_string() +
 		        "px; position: relative;margin: 20px auto 20px auto}\n" + 
 		        "html { padding: 0px; margin: 0px; background-color:" +
 		        "black;}\n</style>\n</head>\n";
 		
 		// make the body
-		html += "<body>\n";
+		html += "<body onload=\"load()\">\n";
 		
 		// add each slide
 		for (var i = 0; i < slides.size; i++)
diff --git a/src/libease/HTMLExporter.vala b/src/libease/HTMLExporter.vala
index 61137d0..ba7340a 100644
--- a/src/libease/HTMLExporter.vala
+++ b/src/libease/HTMLExporter.vala
@@ -142,5 +142,50 @@ public class Ease.HTMLExporter : GLib.Object
 			dialog.destroy();
 		}
 	}
+	
+	/**
+	 * JavaScript needed to run HTML presentations
+	 */
+	public static const string js =
+"""<script type="text/javascript">
+var slide = -1;
+
+function load() {
+	advance();
+}
+
+function keydown(e) {
+	var code = e.keyCode;
+	if (code == 32 || code == 39 || code == 13 || code == 40 || code == 39) {
+		advance();
+	}
+	
+	else if (code == 8 || code == 46 || code == 37 || code == 38) {
+		retreat();
+	}
+}
+
+function advance() {
+	if (document.getElementById("slide" + (slide + 1)) != null) {
+		if (slide >= 0) {
+			document.getElementById("slide" + slide).style.display = "none";
+		}
+		slide++;
+		document.getElementById("slide" + slide).style.display = "block";
+	}
+}
+
+function retreat() {
+	if (slide > 0) {
+		document.getElementById("slide" + slide).style.display = "none";
+		slide--;
+		document.getElementById("slide" + slide).style.display = "block";
+	}
+}
+
+document.onkeydown = keydown;
+
+</script>""";
+
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]