Chromium Code Reviews| 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) { | |
|
Matt Giuca
2015/02/03 07:08:50
So if $('doodle') doesn't exist and visible == tru
calamity
2015/02/04 03:16:22
I don't think there's an assert in JS so.....
Don
Matt Giuca
2015/02/04 04:36:10
Acknowledged.
| |
| 59 var doodle = $('doodle'); | |
| 60 var defaultLogo = $('default_logo'); | |
| 61 if (doodle && visible) { | |
| 62 doodle.style.display = 'flex'; | |
| 63 defaultLogo.style.display = 'none'; | |
| 64 console.log(defaultLogo.style.display); | |
| 65 } else { | |
| 66 if (doodle) | |
| 67 doodle.style.display = 'none'; | |
| 68 | |
| 69 defaultLogo.style.display = 'block'; | |
| 70 } | |
| 71 } | |
| 72 | |
| 73 /** | |
| 51 * Invoked when the app-list doodle is updated. | 74 * Invoked when the app-list doodle is updated. |
| 52 * | 75 * |
| 53 * @param {Object} data The data object representing the current doodle. | 76 * @param {Object} data The data object representing the current doodle. |
| 54 */ | 77 */ |
| 55 function onAppListDoodleUpdated(data, base_url) { | 78 function onAppListDoodleUpdated(data, base_url) { |
| 56 var defaultLogo = $('default_logo'); | 79 if (this.doodle) { |
| 57 var doodle = $('doodle'); | 80 this.doodle.parentNode.removeChild(this.doodle); |
| 58 if (!data.ddljson || !data.ddljson.transparent_large_image) { | 81 this.doodle = null; |
| 59 defaultLogo.style.display = 'block'; | 82 } |
| 60 doodle.style.display = 'none'; | 83 |
| 84 var doodleData = data.ddljson; | |
| 85 if (!doodleData || !doodleData.transparent_large_image) { | |
| 86 setDoodleVisible(false); | |
| 61 return; | 87 return; |
| 62 } | 88 } |
| 63 | 89 |
| 64 doodle.onload = function() { | 90 // Set the page's base URL so that links will resolve relative to the Google |
| 65 defaultLogo.style.display = 'none'; | 91 // homepage. |
| 66 doodle.style.display = 'block'; | 92 $('base').href = base_url; |
| 93 | |
| 94 this.doodle = document.createElement('div'); | |
| 95 this.doodle.id = 'doodle'; | |
| 96 this.doodle.style.display = 'none'; | |
| 97 | |
| 98 var doodleImage = document.createElement('img'); | |
| 99 doodleImage.id = 'doodle_image'; | |
| 100 if (doodleData.alt_text) { | |
| 101 doodleImage.alt = doodleData.alt_text; | |
| 102 doodleImage.title = doodleData.alt_text; | |
| 103 } | |
| 104 | |
| 105 doodleImage.onload = function() { | |
| 106 setDoodleVisible(true); | |
| 67 }; | 107 }; |
| 68 doodle.src = base_url + data.ddljson.transparent_large_image.url; | 108 doodleImage.src = doodleData.transparent_large_image.url; |
| 109 | |
| 110 if (doodleData.target_url) { | |
| 111 var doodleLink = document.createElement('a'); | |
|
Matt Giuca
2015/02/03 07:08:50
Curious: In my experience, when you have <a><img /
calamity
2015/02/04 03:16:22
I am not seeing this happen. I have no idea why. I
Matt Giuca
2015/02/04 04:36:10
Yeah, I'm not seeing it even on a totally fresh pa
| |
| 112 doodleLink.id = 'doodle_link'; | |
| 113 doodleLink.href = doodleData.target_url; | |
| 114 doodleLink.target = '_blank'; | |
| 115 doodleLink.appendChild(doodleImage); | |
| 116 this.doodle.appendChild(doodleLink); | |
| 117 } else { | |
| 118 this.doodle.appendChild(doodleImage); | |
| 119 } | |
| 120 $('logo_container').appendChild(this.doodle); | |
| 69 } | 121 } |
| 70 | 122 |
| 71 /** | 123 /** |
| 72 * Invoked when the app-list bubble is hidden. | 124 * Invoked when the app-list bubble is hidden. |
| 73 */ | 125 */ |
| 74 function onAppListHidden() { | 126 function onAppListHidden() { |
| 75 speechManager.onHidden(); | 127 speechManager.onHidden(); |
| 76 } | 128 } |
| 77 | 129 |
| 78 /** | 130 /** |
| 79 * Invoked when the user explicitly wants to toggle the speech recognition | 131 * Invoked when the user explicitly wants to toggle the speech recognition |
| 80 * state. | 132 * state. |
| 81 */ | 133 */ |
| 82 function toggleSpeechRecognition() { | 134 function toggleSpeechRecognition() { |
| 83 speechManager.toggleSpeechRecognition(); | 135 speechManager.toggleSpeechRecognition(); |
| 84 } | 136 } |
| 85 | 137 |
| 86 return { | 138 return { |
| 87 initialize: initialize, | 139 initialize: initialize, |
| 88 setHotwordEnabled: setHotwordEnabled, | 140 setHotwordEnabled: setHotwordEnabled, |
| 89 setNaclArch: setNaclArch, | 141 setNaclArch: setNaclArch, |
| 90 onAppListDoodleUpdated: onAppListDoodleUpdated, | 142 onAppListDoodleUpdated: onAppListDoodleUpdated, |
| 91 onAppListShown: onAppListShown, | 143 onAppListShown: onAppListShown, |
| 92 onAppListHidden: onAppListHidden, | 144 onAppListHidden: onAppListHidden, |
| 93 toggleSpeechRecognition: toggleSpeechRecognition | 145 toggleSpeechRecognition: toggleSpeechRecognition |
| 94 }; | 146 }; |
| 95 }); | 147 }); |
| 96 | 148 |
| 97 document.addEventListener('DOMContentLoaded', appList.startPage.initialize); | 149 document.addEventListener('DOMContentLoaded', appList.startPage.initialize); |
| OLD | NEW |