From acae2687686306633e53a6075ce9b0ab3806bbfa Mon Sep 17 00:00:00 2001 From: Chris Jaekl Date: Tue, 16 Jul 2019 00:02:34 -0400 Subject: [PATCH] Add Browser.js. --- js/src/Browser.js | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 js/src/Browser.js diff --git a/js/src/Browser.js b/js/src/Browser.js new file mode 100644 index 0000000..243195d --- /dev/null +++ b/js/src/Browser.js @@ -0,0 +1,40 @@ +// ========= +// Browser + +// Encapsulates access to the document object, so that we can +// fall back to alternate behaviour during command-line unit testing + +var Browser = (function() { + var my = {}; + + function isDefined(obj) { + return !( typeof obj === 'undefined' || obj === null ); + } + + my.getElementById = function(id) { + if ( isDefined(document) ) { + var result = document.getElementById(id); + if ( isDefined(result) ) { + return result; + } + else { + console.log('ERROR! Document element not found for ID:', id); + return undefined; + } + } + else { + return undefined; + } + }; + + my.setOnMouseMove = function(handler) { + if ( typeof(document) === 'undefined' || document === null ) { + // no-op + } + else { + document.onmousemove = handler; + } + }; + + return my; +})(); -- 2.30.2