From c6150f2f930c56ba8d3264f0cc5b9321b9b29d54 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Sun, 14 Apr 2013 00:15:50 +0100 Subject: [PATCH] dep-ui.js: Add some debugging machinery. The `DEP_UI.debug' function writes a trace message to the `trace' element, if there is one. Add a `trace' element. --- dep-ui.js | 16 ++++++++++++++++ rolling.html | 1 + 2 files changed, 17 insertions(+) diff --git a/dep-ui.js b/dep-ui.js index 29f5d6b..22f2e60 100644 --- a/dep-ui.js +++ b/dep-ui.js @@ -25,6 +25,22 @@ var DEP_UI = {}; (function () { with (DEP_UI) { /*----- Utility functions and classes -------------------------------------*/ +DEP_UI.debug = function(msg) { + /* Write the string MSG to the `trace' element, if there is one. */ + + var e = elt('trace'); + if (e !== null) e.textContent += msg; +} + + DEP_UI.trap = function(what, func) { + try { + func(); + } catch (e) { + debug('caught exception in ' + what + ': ' + e); + throw e; + } +} + DEP_UI.elt = function (id) { /* Find and return the element with the given ID. */ return document.getElementById(id); diff --git a/rolling.html b/rolling.html index 3ac3555..b4656a2 100644 --- a/rolling.html +++ b/rolling.html @@ -12,6 +12,7 @@

Rolling wire-strip calculator

+
-- 2.11.0