OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 cr.define('ntp4', function() { | 5 cr.define('ntp4', function() { |
6 'use strict'; | 6 'use strict'; |
7 | 7 |
8 var localStrings = new LocalStrings; | 8 var localStrings = new LocalStrings; |
9 | 9 |
10 var APP_LAUNCH = { | 10 var APP_LAUNCH = { |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 setupForApp: function(app) { | 112 setupForApp: function(app) { |
113 this.app_ = app; | 113 this.app_ = app; |
114 | 114 |
115 this.launch_.textContent = app.appData.name; | 115 this.launch_.textContent = app.appData.name; |
116 | 116 |
117 this.forAllLaunchTypes_(function(launchTypeButton, id) { | 117 this.forAllLaunchTypes_(function(launchTypeButton, id) { |
118 launchTypeButton.disabled = false; | 118 launchTypeButton.disabled = false; |
119 launchTypeButton.checked = app.appData.launch_type == id; | 119 launchTypeButton.checked = app.appData.launch_type == id; |
120 }); | 120 }); |
121 | 121 |
122 this.options_.disabled = !app.appData.options_url; | 122 this.options_.disabled = !app.appData.options_url || !app.appData.enabled; |
123 this.uninstall_.disabled = !app.appData.can_uninstall; | 123 this.uninstall_.disabled = !app.appData.can_uninstall; |
124 }, | 124 }, |
125 | 125 |
126 /** | 126 /** |
127 * Handlers for menu item activation. | 127 * Handlers for menu item activation. |
128 * @param {Event} e The activation event. | 128 * @param {Event} e The activation event. |
129 * @private | 129 * @private |
130 */ | 130 */ |
131 onLaunch_: function(e) { | 131 onLaunch_: function(e) { |
132 chrome.send('launchApp', [this.app_.appId, APP_LAUNCH.NTP_APPS_MENU]); | 132 chrome.send('launchApp', [this.app_.appId, APP_LAUNCH.NTP_APPS_MENU]); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 appContents.className = 'app-contents'; | 182 appContents.className = 'app-contents'; |
183 | 183 |
184 var appImgContainer = this.ownerDocument.createElement('div'); | 184 var appImgContainer = this.ownerDocument.createElement('div'); |
185 appImgContainer.className = 'app-img-container'; | 185 appImgContainer.className = 'app-img-container'; |
186 this.appImgContainer_ = appImgContainer; | 186 this.appImgContainer_ = appImgContainer; |
187 | 187 |
188 if (!this.appData_.icon_big_exists && this.appData_.icon_small_exists) | 188 if (!this.appData_.icon_big_exists && this.appData_.icon_small_exists) |
189 this.useSmallIcon_ = true; | 189 this.useSmallIcon_ = true; |
190 | 190 |
191 var appImg = this.ownerDocument.createElement('img'); | 191 var appImg = this.ownerDocument.createElement('img'); |
192 appImg.src = this.useSmallIcon_ ? this.appData_.icon_small : | 192 this.appImg_ = appImg; |
193 this.appData_.icon_big; | 193 this.setIcon(); |
194 appImgContainer.appendChild(appImg); | 194 appImgContainer.appendChild(appImg); |
195 | 195 |
196 if (this.useSmallIcon_) { | 196 if (this.useSmallIcon_) { |
197 var imgDiv = this.ownerDocument.createElement('div'); | 197 var imgDiv = this.ownerDocument.createElement('div'); |
198 imgDiv.className = 'app-icon-div'; | 198 imgDiv.className = 'app-icon-div'; |
199 imgDiv.appendChild(appImgContainer); | 199 imgDiv.appendChild(appImgContainer); |
200 imgDiv.addEventListener('click', this.onClick_.bind(this)); | 200 imgDiv.addEventListener('click', this.onClick_.bind(this)); |
201 this.imgDiv_ = imgDiv; | 201 this.imgDiv_ = imgDiv; |
202 appContents.appendChild(imgDiv); | 202 appContents.appendChild(imgDiv); |
203 } else { | 203 } else { |
204 appImgContainer.addEventListener('click', this.onClick_.bind(this)); | 204 appImgContainer.addEventListener('click', this.onClick_.bind(this)); |
205 appContents.appendChild(appImgContainer); | 205 appContents.appendChild(appImgContainer); |
206 } | 206 } |
207 this.appImg_ = appImg; | |
208 | 207 |
209 var appSpan = this.ownerDocument.createElement('span'); | 208 var appSpan = this.ownerDocument.createElement('span'); |
210 appSpan.textContent = this.appData_.name; | 209 appSpan.textContent = this.appData_.name; |
211 appSpan.addEventListener('click', this.onClick_.bind(this)); | 210 appSpan.addEventListener('click', this.onClick_.bind(this)); |
212 appContents.appendChild(appSpan); | 211 appContents.appendChild(appSpan); |
213 this.appendChild(appContents); | 212 this.appendChild(appContents); |
214 this.appContents_ = appContents; | 213 this.appContents_ = appContents; |
215 | 214 |
216 this.addEventListener('keydown', cr.ui.contextMenuHandler); | 215 this.addEventListener('keydown', cr.ui.contextMenuHandler); |
217 this.addEventListener('keyup', cr.ui.contextMenuHandler); | 216 this.addEventListener('keyup', cr.ui.contextMenuHandler); |
(...skipping 19 matching lines...) Expand all Loading... |
237 */ | 236 */ |
238 remove: function() { | 237 remove: function() { |
239 // Unset the ID immediately, because the app is already gone. But leave | 238 // Unset the ID immediately, because the app is already gone. But leave |
240 // the tile on the page as it animates out. | 239 // the tile on the page as it animates out. |
241 this.id = ''; | 240 this.id = ''; |
242 var tile = findAncestorByClass(this, 'tile'); | 241 var tile = findAncestorByClass(this, 'tile'); |
243 tile.doRemove(); | 242 tile.doRemove(); |
244 }, | 243 }, |
245 | 244 |
246 /** | 245 /** |
| 246 * Set the app's icon image from the appData. |
| 247 * @private |
| 248 */ |
| 249 setIcon: function() { |
| 250 this.appImg_.src = this.useSmallIcon_ ? this.appData_.icon_small : |
| 251 this.appData_.icon_big; |
| 252 if (!this.appData_.enabled || |
| 253 (!this.appData_.offline_enabled && !navigator.onLine)) { |
| 254 this.appImg_.src += '?grayscale=true'; |
| 255 } |
| 256 }, |
| 257 |
| 258 /** |
247 * Creates the apps-promo section of the app (should only be called for the | 259 * Creates the apps-promo section of the app (should only be called for the |
248 * webstore app). | 260 * webstore app). |
249 * @private | 261 * @private |
250 */ | 262 */ |
251 createAppsPromoExtras_: function() { | 263 createAppsPromoExtras_: function() { |
252 this.classList.add('webstore'); | 264 this.classList.add('webstore'); |
253 | 265 |
254 this.appsPromoExtras_ = $('apps-promo-extras-template').cloneNode(true); | 266 this.appsPromoExtras_ = $('apps-promo-extras-template').cloneNode(true); |
255 this.appsPromoExtras_.id = ''; | 267 this.appsPromoExtras_.id = ''; |
256 this.appsPromoHeading_ = | 268 this.appsPromoHeading_ = |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 * @param {Event} e The mousedown event. | 352 * @param {Event} e The mousedown event. |
341 */ | 353 */ |
342 onMousedown_: function(e) { | 354 onMousedown_: function(e) { |
343 if (e.button == 2) | 355 if (e.button == 2) |
344 this.classList.add('right-mouse-down'); | 356 this.classList.add('right-mouse-down'); |
345 else | 357 else |
346 this.classList.remove('right-mouse-down'); | 358 this.classList.remove('right-mouse-down'); |
347 }, | 359 }, |
348 | 360 |
349 /** | 361 /** |
| 362 * Change the appData and update the appearance of the app. |
| 363 * @param {Object} appData The new data object that describes the app. |
| 364 */ |
| 365 replaceAppData: function(appData) { |
| 366 this.appData_ = appData; |
| 367 this.setIcon(); |
| 368 }, |
| 369 |
| 370 /** |
350 * The data and preferences for this app. | 371 * The data and preferences for this app. |
351 * @type {Object} | 372 * @type {Object} |
352 */ | 373 */ |
353 set appData(data) { | 374 set appData(data) { |
354 this.appData_ = data; | 375 this.appData_ = data; |
355 }, | 376 }, |
356 get appData() { | 377 get appData() { |
357 return this.appData_; | 378 return this.appData_; |
358 }, | 379 }, |
359 | 380 |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 }; | 595 }; |
575 | 596 |
576 return { | 597 return { |
577 APP_LAUNCH: APP_LAUNCH, | 598 APP_LAUNCH: APP_LAUNCH, |
578 AppsPage: AppsPage, | 599 AppsPage: AppsPage, |
579 launchAppAfterEnable: launchAppAfterEnable, | 600 launchAppAfterEnable: launchAppAfterEnable, |
580 }; | 601 }; |
581 }); | 602 }); |
582 | 603 |
583 var launchAppAfterEnable = ntp4.launchAppAfterEnable; | 604 var launchAppAfterEnable = ntp4.launchAppAfterEnable; |
OLD | NEW |