Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(405)

Side by Side Diff: remoting/webapp/event_handlers.js

Issue 158113002: [Chromoting] Break up JS event handler registration into related groups. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix alpha order Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | remoting/webapp/toolbar.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 'use strict'; 5 'use strict';
6 6
7 /** @suppress {duplicate} */ 7 /** @suppress {duplicate} */
8 var remoting = remoting || {}; 8 var remoting = remoting || {};
9 9
10 function onLoad() { 10 function onLoad() {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 }; 45 };
46 /** @param {Event} event The event. */ 46 /** @param {Event} event The event. */
47 var stopDaemon = function(event) { 47 var stopDaemon = function(event) {
48 remoting.hostSetupDialog.showForStop(); 48 remoting.hostSetupDialog.showForStop();
49 event.stopPropagation(); 49 event.stopPropagation();
50 }; 50 };
51 var cancelAccessCode = function() { 51 var cancelAccessCode = function() {
52 remoting.setMode(remoting.AppMode.HOME); 52 remoting.setMode(remoting.AppMode.HOME);
53 document.getElementById('access-code-entry').value = ''; 53 document.getElementById('access-code-entry').value = '';
54 }; 54 };
55 var newWindow = function() {
56 chrome.app.window.create('main.html', { 'width': 800, 'height': 600 });
57 };
58 /** @type {Array.<{event: string, id: string, fn: function(Event):void}>} */ 55 /** @type {Array.<{event: string, id: string, fn: function(Event):void}>} */
59 var actions = [ 56 var it2me_actions = [
60 { event: 'click', id: 'sign-out', fn: remoting.signOut },
61 { event: 'click', id: 'toolbar-disconnect', fn: remoting.disconnect },
62 { event: 'click', id: 'send-ctrl-alt-del',
63 fn: remoting.sendCtrlAltDel },
64 { event: 'click', id: 'send-print-screen',
65 fn: remoting.sendPrintScreen },
66 { event: 'click', id: 'auth-button', fn: doAuthRedirect },
67 { event: 'click', id: 'share-button', fn: remoting.tryShare },
68 { event: 'click', id: 'access-mode-button', fn: goEnterAccessCode }, 57 { event: 'click', id: 'access-mode-button', fn: goEnterAccessCode },
58 { event: 'submit', id: 'access-code-form', fn: sendAccessCode },
59 { event: 'click', id: 'cancel-access-code-button', fn: cancelAccessCode},
69 { event: 'click', id: 'cancel-share-button', fn: remoting.cancelShare }, 60 { event: 'click', id: 'cancel-share-button', fn: remoting.cancelShare },
70 { event: 'click', id: 'stop-sharing-button', fn: remoting.cancelShare }, 61 { event: 'click', id: 'client-finished-it2me-button', fn: goHome },
62 { event: 'click', id: 'get-started-it2me',
63 fn: remoting.showIT2MeUiAndSave },
71 { event: 'click', id: 'host-finished-button', fn: goHome }, 64 { event: 'click', id: 'host-finished-button', fn: goHome },
72 { event: 'click', id: 'client-finished-it2me-button', fn: goHome }, 65 { event: 'click', id: 'share-button', fn: remoting.tryShare }
66 ];
67 /** @type {Array.<{event: string, id: string, fn: function(Event):void}>} */
68 var me2me_actions = [
69 { event: 'click', id: 'change-daemon-pin',
70 fn: function() { remoting.hostSetupDialog.showForPin(); } },
73 { event: 'click', id: 'client-finished-me2me-button', fn: goHome }, 71 { event: 'click', id: 'client-finished-me2me-button', fn: goHome },
74 { event: 'click', id: 'client-reconnect-button', fn: reconnect }, 72 { event: 'click', id: 'client-reconnect-button', fn: reconnect },
75 { event: 'click', id: 'cancel-access-code-button', fn: cancelAccessCode}, 73 { event: 'click', id: 'daemon-pin-cancel', fn: goHome },
76 { event: 'click', id: 'cancel-connect-button', fn: goHome }, 74 { event: 'click', id: 'get-started-me2me',
77 { event: 'click', id: 'toolbar-stub', 75 fn: remoting.showMe2MeUiAndSave },
78 fn: function() { remoting.toolbar.toggle(); } },
79 { event: 'click', id: 'start-daemon', 76 { event: 'click', id: 'start-daemon',
80 fn: function() { remoting.hostSetupDialog.showForStart(); } }, 77 fn: function() { remoting.hostSetupDialog.showForStart(); } },
81 { event: 'click', id: 'change-daemon-pin', 78 { event: 'click', id: 'stop-daemon', fn: stopDaemon }
82 fn: function() { remoting.hostSetupDialog.showForPin(); } }, 79 ];
83 { event: 'click', id: 'stop-daemon', fn: stopDaemon }, 80 /** @type {Array.<{event: string, id: string, fn: function(Event):void}>} */
84 { event: 'submit', id: 'access-code-form', fn: sendAccessCode }, 81 var host_actions = [
85 { event: 'click', id: 'get-started-it2me', 82 { event: 'click', id: 'close-paired-client-manager-dialog', fn: goHome },
86 fn: remoting.showIT2MeUiAndSave },
87 { event: 'click', id: 'get-started-me2me',
88 fn: remoting.showMe2MeUiAndSave },
89 { event: 'click', id: 'daemon-pin-cancel', fn: goHome },
90 { event: 'click', id: 'host-config-done-dismiss', fn: goHome }, 83 { event: 'click', id: 'host-config-done-dismiss', fn: goHome },
91 { event: 'click', id: 'host-config-error-dismiss', fn: goHome }, 84 { event: 'click', id: 'host-config-error-dismiss', fn: goHome },
92 { event: 'click', id: 'token-refresh-error-ok', fn: goHome },
93 { event: 'click', id: 'token-refresh-error-sign-in', fn: doAuthRedirect },
94 { event: 'click', id: 'open-paired-client-manager-dialog', 85 { event: 'click', id: 'open-paired-client-manager-dialog',
95 fn: remoting.setMode.bind(null, 86 fn: remoting.setMode.bind(null,
96 remoting.AppMode.HOME_MANAGE_PAIRINGS) }, 87 remoting.AppMode.HOME_MANAGE_PAIRINGS) },
97 { event: 'click', id: 'close-paired-client-manager-dialog', fn: goHome }, 88 { event: 'click', id: 'stop-sharing-button', fn: remoting.cancelShare }
98 { event: 'click', id: 'new-connection', fn: newWindow }
99 ]; 89 ];
100 90 /** @type {Array.<{event: string, id: string, fn: function(Event):void}>} */
101 for (var i = 0; i < actions.length; ++i) { 91 var auth_actions = [
102 var action = actions[i]; 92 { event: 'click', id: 'auth-button', fn: doAuthRedirect },
103 var element = document.getElementById(action.id); 93 { event: 'click', id: 'cancel-connect-button', fn: goHome },
104 if (element) { 94 { event: 'click', id: 'token-refresh-error-ok', fn: goHome },
105 element.addEventListener(action.event, action.fn, false); 95 { event: 'click', id: 'token-refresh-error-sign-in', fn: doAuthRedirect }
106 } else { 96 ];
107 console.error('Could not set ' + action.event + 97 registerEventListeners(it2me_actions);
108 ' event handler on element ' + action.id + 98 registerEventListeners(me2me_actions);
109 ': element not found.'); 99 registerEventListeners(host_actions);
110 } 100 registerEventListeners(auth_actions);
111 }
112 remoting.init(); 101 remoting.init();
113 102
114 window.addEventListener('resize', remoting.onResize, false); 103 window.addEventListener('resize', remoting.onResize, false);
115 if (!remoting.isAppsV2) { 104 if (!remoting.isAppsV2) {
116 window.addEventListener('beforeunload', remoting.promptClose, false); 105 window.addEventListener('beforeunload', remoting.promptClose, false);
117 window.addEventListener('unload', remoting.disconnect, false); 106 window.addEventListener('unload', remoting.disconnect, false);
118 } 107 }
119 } 108 }
120 109
110 /**
111 * @param {Array.<{event: string, id: string,
112 * fn: function(Event):void}>} actions Array of actions to register.
113 */
114 function registerEventListeners(actions) {
115 for (var i = 0; i < actions.length; ++i) {
116 var action = actions[i];
117 registerEventListener(action.id, action.event, action.fn);
118 }
119 }
120
121 /**
122 * Add an event listener to the specified element.
123 * @param {string} id Id of element.
124 * @param {string} eventname Event name.
125 * @param {function(Event):void} fn Event handler.
126 */
127 function registerEventListener(id, eventname, fn) {
128 var element = document.getElementById(id);
129 if (element) {
130 element.addEventListener(eventname, fn, false);
131 } else {
132 console.error('Could not set ' + eventname +
133 ' event handler on element ' + id +
134 ': element not found.');
135 }
136 }
137
121 window.addEventListener('load', onLoad, false); 138 window.addEventListener('load', onLoad, false);
OLDNEW
« no previous file with comments | « no previous file | remoting/webapp/toolbar.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698