Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(723)

Side by Side Diff: chrome/browser/resources/ntp4/apps_page.js

Issue 7792024: Show app disable and enable on NTP, and desaturate non-offline-enabled apps when offline. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: u Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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);
218 217
219 // This hack is here so that appContents.contextMenu will be the same as 218 // This hack is here so that appContents.contextMenu will be the same as
220 // this.contextMenu. 219 // this.contextMenu.
221 var self = this; 220 var self = this;
222 appContents.__defineGetter__('contextMenu', function() { 221 appContents.__defineGetter__('contextMenu', function() {
223 return self.contextMenu; 222 return self.contextMenu;
224 }); 223 });
225 appContents.addEventListener('contextmenu', cr.ui.contextMenuHandler); 224 appContents.addEventListener('contextmenu', cr.ui.contextMenuHandler);
226 225
227 this.isStore_ = this.appData_.is_webstore; 226 this.isStore_ = this.appData_.is_webstore;
228 if (this.isStore_) 227 if (this.isStore_)
229 this.createAppsPromoExtras_(); 228 this.createAppsPromoExtras_();
230 }, 229 },
231 230
232 /** 231 /**
232 * Set the app's icon image from the appData.
233 * @private
234 */
235 setIcon: function() {
236 this.appImg_.src = this.useSmallIcon_ ? this.appData_.icon_small :
237 this.appData_.icon_big;
238 if (!this.appData_.enabled ||
239 (!this.appData_.offline_enabled && !navigator.onLine)) {
240 this.appImg_.src += '?grayscale=true';
241 }
242 },
243
244 /**
233 * Creates the apps-promo section of the app (should only be called for the 245 * Creates the apps-promo section of the app (should only be called for the
234 * webstore app). 246 * webstore app).
235 * @private 247 * @private
236 */ 248 */
237 createAppsPromoExtras_: function() { 249 createAppsPromoExtras_: function() {
238 this.classList.add('webstore'); 250 this.classList.add('webstore');
239 251
240 this.appsPromoExtras_ = $('apps-promo-extras-template').cloneNode(true); 252 this.appsPromoExtras_ = $('apps-promo-extras-template').cloneNode(true);
241 this.appsPromoExtras_.id = ''; 253 this.appsPromoExtras_.id = '';
242 this.appsPromoHeading_ = 254 this.appsPromoHeading_ =
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 onClick_: function(e) { 325 onClick_: function(e) {
314 chrome.send('launchApp', 326 chrome.send('launchApp',
315 [this.appId, APP_LAUNCH.NTP_APPS_MAXIMIZED, 327 [this.appId, APP_LAUNCH.NTP_APPS_MAXIMIZED,
316 e.altKey, e.ctrlKey, e.metaKey, e.shiftKey, e.button]); 328 e.altKey, e.ctrlKey, e.metaKey, e.shiftKey, e.button]);
317 329
318 // Don't allow the click to trigger a link or anything 330 // Don't allow the click to trigger a link or anything
319 e.preventDefault(); 331 e.preventDefault();
320 }, 332 },
321 333
322 /** 334 /**
335 * Change the appData and update the appearance of the app.
336 * @param {Object} appData The new data object that describes the app.
337 */
338 replaceAppData: function(appData) {
339 this.appData_ = appData;
340 this.setIcon();
341 },
342
343 /**
323 * The data and preferences for this app. 344 * The data and preferences for this app.
324 * @type {Object} 345 * @type {Object}
325 */ 346 */
326 set appData(data) { 347 set appData(data) {
327 this.appData_ = data; 348 this.appData_ = data;
328 }, 349 },
329 get appData() { 350 get appData() {
330 return this.appData_; 351 return this.appData_;
331 }, 352 },
332 353
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 var store = document.querySelector('.webstore'); 553 var store = document.querySelector('.webstore');
533 if (store) 554 if (store)
534 store.setAppsPromoData(data); 555 store.setAppsPromoData(data);
535 }; 556 };
536 557
537 return { 558 return {
538 APP_LAUNCH: APP_LAUNCH, 559 APP_LAUNCH: APP_LAUNCH,
539 AppsPage: AppsPage, 560 AppsPage: AppsPage,
540 }; 561 };
541 }); 562 });
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/ntp4/new_tab.js » ('j') | chrome/browser/resources/ntp4/new_tab.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698