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 function $(criterion) { |
| 6 return document.querySelector(criterion); |
| 7 } |
| 8 |
| 9 var cyclerUI = new (function () { |
| 10 |
| 11 /** |
| 12 * Enum for different UI states. |
| 13 * @enum {number} |
| 14 * @private |
| 15 */ |
| 16 var EnableState_ = {capture: 0, playback: 1}; |
| 17 |
| 18 this.cyclerData_ = new CyclerData(); |
| 19 |
| 20 // Members for all UI elements subject to programmatic adjustment. |
| 21 this.captureTabLabel_ = $('#capture-tab-label'); |
| 22 this.playbackTabLabel_ = $('#playback-tab-label'); |
| 23 |
| 24 this.playbackTab_ = new PlaybackTab(this, this.cyclerData_); |
| 25 this.captureTab_ = new CaptureTab(this, this.cyclerData_, this.playbackTab_); |
| 26 |
| 27 this.popupDialog_ = $('#popup'); |
| 28 this.popupContent_ = $('#popup-content'); |
| 29 this.doPopupDismiss_ = $('#do-popup-dismiss'); |
| 30 |
| 31 /** |
| 32 * Name of the most recent capture made, or the one most recently chosen |
| 33 * for playback. |
| 34 * @type {!string} |
| 35 */ |
| 36 this.currentCaptureName = null; |
| 37 |
| 38 /** |
| 39 * One of the EnableState_ values, showing which tab is presently |
| 40 * enabled. |
| 41 * @type {number} |
| 42 */ |
| 43 this.enableState = null; |
| 44 |
| 45 /* |
| 46 * Enable the capture tab, changing tab labels approproiately. |
| 47 * @private |
| 48 */ |
| 49 this.enableCapture_ = function() { |
| 50 if (this.enableState != EnableState_.capture) { |
| 51 this.enableState = EnableState_.capture; |
| 52 |
| 53 this.captureTab_.enable(); |
| 54 this.playbackTab_.disable(); |
| 55 } |
| 56 }; |
| 57 |
| 58 /* |
| 59 * Enable the playback tab, changing tab labels approproiately. |
| 60 * @private |
| 61 */ |
| 62 this.enablePlayback_ = function() { |
| 63 if (this.enableState != EnableState_.playback) { |
| 64 this.enableState = EnableState_.playback; |
| 65 |
| 66 this.captureTab_.disable(); |
| 67 this.playbackTab_.enable(); |
| 68 } |
| 69 }; |
| 70 |
| 71 /** |
| 72 * Show an overlay with a message, a dismiss button with configurable |
| 73 * label, and an action to call upon dismissal. |
| 74 * @param {!string} content The message to display. |
| 75 * @param {!string} dismissLabel The label on the dismiss button. |
| 76 * @param {function()} action Additional action to take, if any, upon |
| 77 * dismissal. |
| 78 */ |
| 79 this.showMessage = function(content, dismissLabel, action) { |
| 80 this.popupContent_.innerText = content; |
| 81 this.doPopupDismiss_.innerText = dismissLabel; |
| 82 this.popupDialog_.hidden = false; |
| 83 if (action != null) |
| 84 doPopupDismiss_.addEventListener('click', action); |
| 85 } |
| 86 |
| 87 /** |
| 88 * Default action for popup dismissal button, performed in addition to |
| 89 * any other actions that may be specified in showMessage_ call. |
| 90 * @private |
| 91 */ |
| 92 this.clearMessage_ = function() { |
| 93 this.popupDialog_.hidden = true; |
| 94 } |
| 95 |
| 96 // Set up listeners on all buttons. |
| 97 this.doPopupDismiss_.addEventListener('click', this.clearMessage_.bind(this)); |
| 98 |
| 99 // Set up listeners on tab labels. |
| 100 this.captureTabLabel_.addEventListener('click', |
| 101 this.enableCapture_.bind(this)); |
| 102 this.playbackTabLabel_.addEventListener('click', |
| 103 this.enablePlayback_.bind(this)); |
| 104 |
| 105 // Start with capture tab displayed. |
| 106 this.enableCapture_(); |
| 107 })(); |
OLD | NEW |