From: Chris Jaekl Date: Tue, 16 Jul 2019 04:02:34 +0000 (-0400) Subject: Add Browser.js. X-Git-Url: http://jaekl.net/gitweb/?p=quanweb.git;a=commitdiff_plain;h=acae2687686306633e53a6075ce9b0ab3806bbfa;hp=18a0d7dec5cf675855108e0f463062d1ac7d948e Add 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; +})();