Add Browser.js.
[quanweb.git] / js / src / Browser.js
1 // =========
2 // Browser
3
4 // Encapsulates access to the document object, so that we can 
5 // fall back to alternate behaviour during command-line unit testing
6
7 var Browser = (function() {
8     var my = {};
9
10     function isDefined(obj) {
11         return !( typeof obj === 'undefined' || obj === null );
12     }
13
14     my.getElementById = function(id) {
15         if ( isDefined(document) ) {
16             var result = document.getElementById(id);
17             if ( isDefined(result) ) {
18                 return result;
19             }
20             else {
21                 console.log('ERROR!  Document element not found for ID:', id);
22                 return undefined;
23             }
24         }
25         else {
26             return undefined; 
27         }
28     };
29
30     my.setOnMouseMove = function(handler) {
31         if ( typeof(document) === 'undefined' || document === null ) {
32             // no-op
33         }
34         else {
35             document.onmousemove = handler;
36         }
37     };
38
39     return my;
40 })();