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
3 // found in the LICENSE file.
6 * @fileoverview App launcher start page implementation.
9 cr.define('appList.startPage', function() {
12 // The element containing the current Google Doodle.
16 * Initialize the page.
18 function initialize() {
19 chrome.send('initialize');
23 * Invoked when the app-list bubble is shown.
25 function onAppListShown() {
26 chrome.send('appListShown', [this.doodle != null]);
30 * Sets the doodle's visibility, hiding or showing the default logo.
32 * @param {boolean} visible Whether the doodle should be made visible.
34 function setDoodleVisible(visible) {
35 var doodle = $('doodle');
36 var defaultLogo = $('default_logo');
38 doodle.style.display = 'flex';
39 defaultLogo.style.display = 'none';
42 doodle.style.display = 'none';
44 defaultLogo.style.display = 'block';
49 * Invoked when the app-list doodle is updated.
51 * @param {Object} data The data object representing the current doodle.
53 function onAppListDoodleUpdated(data, base_url) {
55 this.doodle.parentNode.removeChild(this.doodle);
59 var doodleData = data.ddljson;
60 if (!doodleData || !doodleData.transparent_large_image) {
61 setDoodleVisible(false);
65 // Set the page's base URL so that links will resolve relative to the Google
67 $('base').href = base_url;
69 this.doodle = document.createElement('div');
70 this.doodle.id = 'doodle';
71 this.doodle.style.display = 'none';
73 var doodleImage = document.createElement('img');
74 doodleImage.id = 'doodle_image';
75 if (doodleData.alt_text) {
76 doodleImage.alt = doodleData.alt_text;
77 doodleImage.title = doodleData.alt_text;
80 doodleImage.onload = function() {
81 setDoodleVisible(true);
83 doodleImage.src = doodleData.transparent_large_image.url;
85 if (doodleData.target_url) {
86 var doodleLink = document.createElement('a');
87 doodleLink.id = 'doodle_link';
88 doodleLink.href = doodleData.target_url;
89 doodleLink.target = '_blank';
90 doodleLink.appendChild(doodleImage);
91 doodleLink.onclick = function() {
92 chrome.send('doodleClicked');
95 this.doodle.appendChild(doodleLink);
97 this.doodle.appendChild(doodleImage);
99 $('logo_container').appendChild(this.doodle);
103 initialize: initialize,
104 onAppListDoodleUpdated: onAppListDoodleUpdated,
105 onAppListShown: onAppListShown,
109 document.addEventListener('contextmenu', function(e) { e.preventDefault(); });
110 document.addEventListener('DOMContentLoaded', appList.startPage.initialize);