OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 /** | 5 /** |
6 * @fileoverview App launcher start page implementation. | 6 * @fileoverview App launcher start page implementation. |
7 */ | 7 */ |
8 | 8 |
9 <include src="speech_manager.js"> | 9 <include src="speech_manager.js"> |
10 | 10 |
11 cr.define('appList.startPage', function() { | 11 cr.define('appList.startPage', function() { |
12 'use strict'; | 12 'use strict'; |
13 | 13 |
14 var speechManager = null; | 14 var speechManager = null; |
15 | 15 |
16 // The element containing the current Google Doodle. | |
17 var doodle = null; | |
18 | |
16 /** | 19 /** |
17 * Initialize the page. | 20 * Initialize the page. |
18 */ | 21 */ |
19 function initialize() { | 22 function initialize() { |
20 speechManager = new speech.SpeechManager(); | 23 speechManager = new speech.SpeechManager(); |
21 chrome.send('initialize'); | 24 chrome.send('initialize'); |
22 } | 25 } |
23 | 26 |
24 /** | 27 /** |
25 * Invoked when the hotword plugin availability is changed. | 28 * Invoked when the hotword plugin availability is changed. |
(...skipping 15 matching lines...) Expand all Loading... | |
41 /** | 44 /** |
42 * Invoked when the app-list bubble is shown. | 45 * Invoked when the app-list bubble is shown. |
43 * | 46 * |
44 * @param {boolean} hotwordEnabled Whether the hotword is enabled or not. | 47 * @param {boolean} hotwordEnabled Whether the hotword is enabled or not. |
45 */ | 48 */ |
46 function onAppListShown(hotwordEnabled) { | 49 function onAppListShown(hotwordEnabled) { |
47 speechManager.onShown(hotwordEnabled); | 50 speechManager.onShown(hotwordEnabled); |
48 } | 51 } |
49 | 52 |
50 /** | 53 /** |
54 * Sets the doodle's visibility, hiding or showing the default logo. | |
55 * | |
56 * @param {boolean} visible Whether the doodle should be made visible. | |
57 */ | |
58 function setDoodleVisible(visible) { | |
59 var doodle = $('doodle'); | |
60 var defaultLogo = $('default_logo'); | |
61 if (visible) { | |
62 doodle.style.display = 'flex'; | |
63 defaultLogo.style.display = 'none'; | |
64 } else { | |
65 if (doodle) | |
66 doodle.style.display = 'none'; | |
67 | |
68 defaultLogo.style.display = 'block'; | |
69 } | |
70 } | |
71 | |
72 /** | |
51 * Invoked when the app-list doodle is updated. | 73 * Invoked when the app-list doodle is updated. |
52 * | 74 * |
53 * @param {Object} data The data object representing the current doodle. | 75 * @param {Object} data The data object representing the current doodle. |
54 */ | 76 */ |
55 function onAppListDoodleUpdated(data, base_url) { | 77 function onAppListDoodleUpdated(data, base_url) { |
56 var defaultLogo = $('default_logo'); | 78 if (this.doodle) { |
57 var doodle = $('doodle'); | 79 this.doodle.parentNode.removeChild(this.doodle); |
58 if (!data.ddljson || !data.ddljson.transparent_large_image) { | 80 this.doodle = null; |
59 defaultLogo.style.display = 'block'; | 81 } |
60 doodle.style.display = 'none'; | 82 |
83 var doodleData = data.ddljson; | |
84 if (!doodleData || !doodleData.transparent_large_image) { | |
85 setDoodleVisible(false); | |
61 return; | 86 return; |
62 } | 87 } |
63 | 88 |
64 doodle.onload = function() { | 89 // Set the page's base URL so that links will resolve relative to the Google |
65 defaultLogo.style.display = 'none'; | 90 // homepage. |
66 doodle.style.display = 'block'; | 91 $('base').href = base_url; |
92 | |
93 this.doodle = document.createElement('div'); | |
94 this.doodle.id = 'doodle'; | |
95 this.doodle.style.display = 'none'; | |
96 | |
97 var doodleImage = document.createElement('img'); | |
98 doodleImage.id = 'doodle_image'; | |
99 if (doodleData.alt_text) { | |
100 doodleImage.alt = doodleData.alt_text; | |
101 doodleImage.title = doodleData.alt_text; | |
102 } | |
103 | |
104 doodleImage.onload = function() { | |
105 setDoodleVisible(true); | |
67 }; | 106 }; |
68 doodle.src = base_url + data.ddljson.transparent_large_image.url; | 107 doodleImage.src = doodleData.transparent_large_image.url; |
108 | |
109 if (doodleData.target_url) { | |
110 var doodleLink = document.createElement('a'); | |
111 doodleLink.id = 'doodle_link'; | |
112 doodleLink.href = doodleData.target_url; | |
113 doodleLink.target = '_blank'; | |
114 doodleLink.appendChild(doodleImage); | |
115 this.doodle.appendChild(doodleLink); | |
116 } else { | |
117 this.doodle.appendChild(doodleImage); | |
118 } | |
119 $('logo_container').appendChild(this.doodle); | |
69 } | 120 } |
70 | 121 |
71 /** | 122 /** |
72 * Invoked when the app-list bubble is hidden. | 123 * Invoked when the app-list bubble is hidden. |
73 */ | 124 */ |
74 function onAppListHidden() { | 125 function onAppListHidden() { |
75 speechManager.onHidden(); | 126 speechManager.onHidden(); |
76 } | 127 } |
77 | 128 |
78 /** | 129 /** |
79 * Invoked when the user explicitly wants to toggle the speech recognition | 130 * Invoked when the user explicitly wants to toggle the speech recognition |
80 * state. | 131 * state. |
81 */ | 132 */ |
82 function toggleSpeechRecognition() { | 133 function toggleSpeechRecognition() { |
83 speechManager.toggleSpeechRecognition(); | 134 speechManager.toggleSpeechRecognition(); |
84 } | 135 } |
85 | 136 |
86 return { | 137 return { |
87 initialize: initialize, | 138 initialize: initialize, |
88 setHotwordEnabled: setHotwordEnabled, | 139 setHotwordEnabled: setHotwordEnabled, |
89 setNaclArch: setNaclArch, | 140 setNaclArch: setNaclArch, |
90 onAppListDoodleUpdated: onAppListDoodleUpdated, | 141 onAppListDoodleUpdated: onAppListDoodleUpdated, |
91 onAppListShown: onAppListShown, | 142 onAppListShown: onAppListShown, |
92 onAppListHidden: onAppListHidden, | 143 onAppListHidden: onAppListHidden, |
93 toggleSpeechRecognition: toggleSpeechRecognition | 144 toggleSpeechRecognition: toggleSpeechRecognition |
94 }; | 145 }; |
95 }); | 146 }); |
96 | 147 |
148 document.addEventListener('contextmenu', function(e) { e.preventDefault(); }); | |
calamity
2015/02/04 03:16:22
Oops, this got lost.
| |
97 document.addEventListener('DOMContentLoaded', appList.startPage.initialize); | 149 document.addEventListener('DOMContentLoaded', appList.startPage.initialize); |
OLD | NEW |