| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 /** | |
| 6 * @fileoverview | |
| 7 * Functions related to controlling the modal ui state of the app. | |
| 8 */ | |
| 9 | |
| 10 'use strict'; | |
| 11 | |
| 12 /** @suppress {duplicate} */ | |
| 13 var remoting = remoting || {}; | |
| 14 | |
| 15 /** @enum {string} */ | |
| 16 remoting.AppMode = { | |
| 17 HOME: 'home', | |
| 18 UNAUTHENTICATED: 'auth', | |
| 19 CLIENT: 'client', | |
| 20 CLIENT_UNCONNECTED: 'client.unconnected', | |
| 21 CLIENT_PIN_PROMPT: 'client.pin-prompt', | |
| 22 CLIENT_CONNECTING: 'client.connecting', | |
| 23 CLIENT_CONNECT_FAILED_IT2ME: 'client.connect-failed.it2me', | |
| 24 CLIENT_CONNECT_FAILED_ME2ME: 'client.connect-failed.me2me', | |
| 25 CLIENT_SESSION_FINISHED_IT2ME: 'client.session-finished.it2me', | |
| 26 CLIENT_SESSION_FINISHED_ME2ME: 'client.session-finished.me2me', | |
| 27 HOST: 'host', | |
| 28 HOST_WAITING_FOR_CODE: 'host.waiting-for-code', | |
| 29 HOST_WAITING_FOR_CONNECTION: 'host.waiting-for-connection', | |
| 30 HOST_SHARED: 'host.shared', | |
| 31 HOST_SHARE_FAILED: 'host.share-failed', | |
| 32 HOST_SHARE_FINISHED: 'host.share-finished', | |
| 33 IN_SESSION: 'in-session' | |
| 34 }; | |
| 35 | |
| 36 /** | |
| 37 * @type {remoting.AppMode} The current app mode | |
| 38 */ | |
| 39 remoting.currentMode = remoting.AppMode.HOME; | |
| 40 | |
| 41 /** | |
| 42 * Change the app's modal state to |mode|, which is considered to be a dotted | |
| 43 * hierachy of modes. For example, setMode('host.shared') will show any modal | |
| 44 * elements with an data-ui-mode attribute of 'host' or 'host.shared' and hide | |
| 45 * all others. | |
| 46 * | |
| 47 * @param {remoting.AppMode} mode The new modal state, expressed as a dotted | |
| 48 * hiearchy. | |
| 49 */ | |
| 50 remoting.setMode = function(mode) { | |
| 51 var modes = mode.split('.'); | |
| 52 for (var i = 1; i < modes.length; ++i) | |
| 53 modes[i] = modes[i - 1] + '.' + modes[i]; | |
| 54 var elements = document.querySelectorAll('[data-ui-mode]'); | |
| 55 for (var i = 0; i < elements.length; ++i) { | |
| 56 var element = /** @type {Element} */ elements[i]; | |
| 57 var hidden = true; | |
| 58 for (var m = 0; m < modes.length; ++m) { | |
| 59 if (hasClass(element.getAttribute('data-ui-mode'), modes[m])) { | |
| 60 hidden = false; | |
| 61 break; | |
| 62 } | |
| 63 } | |
| 64 element.hidden = hidden; | |
| 65 } | |
| 66 remoting.debug.log('App mode: ' + mode); | |
| 67 remoting.currentMode = mode; | |
| 68 if (mode == remoting.AppMode.IN_SESSION) { | |
| 69 document.removeEventListener('keydown', remoting.DebugLog.onKeydown, false); | |
| 70 } else { | |
| 71 document.addEventListener('keydown', remoting.DebugLog.onKeydown, false); | |
| 72 } | |
| 73 if (mode == remoting.AppMode.HOME) { | |
| 74 var display = function() { remoting.hostList.display(); }; | |
| 75 remoting.hostList.refresh(display); | |
| 76 } | |
| 77 }; | |
| 78 | |
| 79 /** | |
| 80 * Get the major mode that the app is running in. | |
| 81 * @return {string} The app's current major mode. | |
| 82 */ | |
| 83 remoting.getMajorMode = function() { | |
| 84 return remoting.currentMode.split('.')[0]; | |
| 85 }; | |
| OLD | NEW |