OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 The Native Client Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be found | |
3 // in the LICENSE file. | |
4 | |
5 /** | |
6 * @fileoverview This file contains the top level JavaScript required for the | |
7 * WebGTT application. The two main functions are fired when the page loads and | |
8 * when the NaCl module loads, respectively. We handle these load events | |
9 * separately since the order in which these events are fired is much less | |
10 * predictable than other standard DOM elements (for which we assume that they | |
11 * are loaded when the page is loaded). | |
12 * | |
13 * @author ragad@google.com (Raga Gopalakrishnan) | |
14 */ | |
15 | |
16 /** | |
17 * Each of these variables is an object corresponding to a DOM element. Since | |
18 * event handlers for one DOM element may need to modify properties of or | |
19 * perform actions on another DOM element, these objects have global scope. | |
20 */ | |
21 var naclModule1 = undefined; // NaClModule object. See naclmodule.js | |
22 var graph1 = new Graph(); // Graph object. See graph.js | |
23 var canvas1 = undefined; // Canvas object. See canvas.js | |
24 var coloringButton1 = undefined; // ColoringButton object. See button.js | |
25 | |
26 /** | |
27 * This constant holds the default status message. | |
28 * @type {string} | |
29 * @const | |
30 */ | |
31 STATUS_TEXT = 'NO-STATUS'; | |
32 | |
33 /** | |
34 * This function is triggered when the page has finished loading, and contains | |
35 * starter code (initializing objects, etc.). | |
36 * | |
37 * The NaCl module could still be loading while the page has finished loading. | |
38 * So, the status must be updated accordingly, and no NaClModule object is | |
39 * created yet. New objects of the Canvas and ColoringButton classes are | |
40 * created, and the appropriate event handlers are attached. | |
41 */ | |
42 function main1 () { | |
43 if (naclModule1 == undefined) { | |
44 updateStatus('LOADING...'); | |
45 } else { | |
46 updateStatus(); | |
47 } | |
48 | |
49 canvas1 = new Canvas(document.getElementById('mainCanvas'), graph1); | |
50 canvas1.drawingCanvas.addEventListener( | |
51 'click', function (e) {canvas1.handleCanvasClick(e);}, false); | |
52 window.addEventListener( | |
53 'keydown', function (e) {canvas1.handleCanvasKeydown(e);}, true); | |
54 | |
55 coloringButton1 = new ColoringButton(document.getElementById('coloring'), | |
56 graph1); | |
57 coloringButton1.coloringButton.addEventListener( | |
58 'click', function (e) {coloringButton1.handleColoringButtonClick(e);}, | |
59 false); | |
60 } | |
61 | |
62 /** | |
63 * This function is triggered when the NaCl module has finished loading. It | |
64 * creates a new NaClModule object, attaches an event handler to it, and | |
65 * indcates to the user that the NaCl module has loaded successfully. | |
66 */ | |
67 function main2() { | |
68 naclModule1 = new NaClModule(document.getElementById('webgtt'), graph1); | |
69 naclModule1.naclModule.addEventListener( | |
70 'message', function (e) {naclModule1.handleMessage(e);}, false); | |
71 updateStatus('SUCCESS'); | |
72 } | |
73 | |
74 /** | |
75 * This function sets the global status message. | |
76 * | |
77 * If the element with id 'statusField' exists, then its HTML is set to the | |
78 * status message as well. opt_message is the message text. If this is null or | |
79 * undefined, then the element with id 'statusField' is set to STATUS_TEXT. | |
80 * | |
81 * @param {string} opt_message The status message to be displayed. | |
82 */ | |
83 function updateStatus(opt_message) { | |
84 var statusText = STATUS_TEXT; | |
85 if (opt_message) { | |
86 statusText = opt_message; | |
87 } | |
88 var statusField = document.getElementById('status_field'); | |
89 if (statusField) { | |
90 statusField.innerHTML = statusText; | |
91 } | |
92 } | |
OLD | NEW |