Don't mix data model and UI: move debug javascript to js module, also use jquery because raw javascript without validation is dangerous
Don't mix data model and UI: move debug javascript to js module, also use jquery because raw javascript without validation is dangerous

--- a/css/gitphp.css
+++ b/css/gitphp.css
@@ -234,6 +234,7 @@
 
 .debug_bt {
 	white-space: pre;
-}
-
-
+	display: none;
+}
+
+

--- a/include/DebugLog.class.php
+++ b/include/DebugLog.class.php
@@ -237,7 +237,6 @@
 		if (!$this->enabled) return;
 
 		foreach ($this->entries as $i => $e) {
-			$bt_id = 'bt_' . $i;
 			if (strlen($e['value']) > 512) {
 				$contents  = htmlspecialchars(substr($e['value'], 0, 512) . "...");
 				$contents .= "\n\n<i>" . (strlen($e['value']) - 512) . " bytes more in output</i>";
@@ -248,8 +247,8 @@
 				<td class='debug_key'>$e[name]</td>
 				<td class='debug_value'>
 					" . nl2br($contents) . ($contents != "" ? "<br§ />" : "") . "
-					<span class='debug_toggle' onclick='bt_toggle(\"$bt_id\");'>trace</span>&nbsp;
-					<div style='display: none;' class='debug_bt' id='$bt_id'>$e[bt]</div>
+					<span class='debug_toggle'>trace</span>&nbsp;
+					<div class='debug_bt'>$e[bt]</div>
 				</td>
 				<td class='debug_time'>
 					" . ($e['time'] ? sprintf("%.1f", $e['time'] * 1000) : '') . "
@@ -265,12 +264,6 @@
 
 		echo
 <<<HEREDOC
-		<script type="text/javascript">
-			function bt_toggle(id) {
-				var el = document.getElementById(id);
-				el.style.display = ((el.style.display == 'none') ? 'block' : 'none');
-			}
-		</script>
 		<table class="debug"><tbody>
 HEREDOC;
 	}

--- a/js/common.js
+++ b/js/common.js
@@ -9,7 +9,7 @@
  * @subpackage Javascript
  */
 
-define(["jquery", "modules/getproject", "modules/lang", "modules/tooltip.snapshot", "modules/tooltip.commit", "modules/tooltip.tag", 'modules/loginpopup', 'modernizr'],
+define(["jquery", "modules/getproject", "modules/lang", "modules/tooltip.snapshot", "modules/tooltip.commit", "modules/tooltip.tag", 'modules/loginpopup', 'modernizr', 'modules/debug'],
 	function($, project, lang, tooltipSnapshot, tooltipCommit, tooltipTag, loginpopup) {
 		$(function() {
 			lang($('div.lang_select'));

--- /dev/null
+++ b/js/modules/debug.js
@@ -1,1 +1,21 @@
+/*
+ * GitPHP Javascript debug menu
+ *
+ * Javascript for expandable debug output
+ *
+ * @author Christopher Han <xiphux@gmail.com>
+ * @copyright Copyright (c) 2013 Christopher Han
+ * @package GitPHP
+ * @subpackage Javascript
+ */
 
+define(["jquery"],
+  function($) {
+    $('span.debug_toggle').click(
+      function() {
+        $(this).siblings('div.debug_bt').toggle();
+      }
+    );
+  }
+);
+

comments