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

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

Issue 8264001: ntp4: apps apps apps... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 2 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
« no previous file with comments | « no previous file | chrome/browser/ui/webui/ntp/app_launcher_handler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 /** 5 /**
6 * @fileoverview New tab page 6 * @fileoverview New tab page
7 * This is the main code for the new tab page used by touch-enabled Chrome 7 * This is the main code for the new tab page used by touch-enabled Chrome
8 * browsers. For now this is still a prototype. 8 * browsers. For now this is still a prototype.
9 */ 9 */
10 10
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 var pageNames = data.appPageNames; 307 var pageNames = data.appPageNames;
308 308
309 function stringListIsEmpty(list) { 309 function stringListIsEmpty(list) {
310 for (var i = 0; i < list.length; i++) { 310 for (var i = 0; i < list.length; i++) {
311 if (list[i]) 311 if (list[i])
312 return false; 312 return false;
313 } 313 }
314 return true; 314 return true;
315 } 315 }
316 316
317 if (!pageNames || stringListIsEmpty(pageNames))
318 pageNames = [localStrings.getString('appDefaultPageName')];
319
320 // Sort by launch index 317 // Sort by launch index
321 apps.sort(function(a, b) { 318 apps.sort(function(a, b) {
322 return a.app_launch_index - b.app_launch_index; 319 return a.app_launch_index - b.app_launch_index;
323 }); 320 });
324 321
325 // An app to animate (in case it was just installed). 322 // An app to animate (in case it was just installed).
326 var highlightApp; 323 var highlightApp;
327 324
328 // Add the apps, creating pages as necessary 325 // Add the apps, creating pages as necessary
329 for (var i = 0; i < apps.length; i++) { 326 for (var i = 0; i < apps.length; i++) {
330 var app = apps[i]; 327 var app = apps[i];
331 var pageIndex = (app.page_index || 0); 328 var pageIndex = (app.page_index || 0);
332 while (pageIndex >= appsPages.length) { 329 while (pageIndex >= appsPages.length) {
333 var pageName = ''; 330 var pageName = localStrings.getString('appDefaultPageName');
334 if (appsPages.length < pageNames.length) 331 if (appsPages.length < pageNames.length)
335 pageName = pageNames[appsPages.length]; 332 pageName = pageNames[appsPages.length];
336 333
337 var origPageCount = appsPages.length; 334 var origPageCount = appsPages.length;
338 appendTilePage(new ntp4.AppsPage(), pageName, true, bookmarksPage); 335 appendTilePage(new ntp4.AppsPage(), pageName, true, bookmarksPage);
339 // Confirm that appsPages is a live object, updated when a new page is 336 // Confirm that appsPages is a live object, updated when a new page is
340 // added (otherwise we'd have an infinite loop) 337 // added (otherwise we'd have an infinite loop)
341 assert(appsPages.length == origPageCount + 1, 'expected new page'); 338 assert(appsPages.length == origPageCount + 1, 'expected new page');
342 } 339 }
343 340
(...skipping 27 matching lines...) Expand all
371 function appAdded(appData, opt_highlight) { 368 function appAdded(appData, opt_highlight) {
372 if (appData.id == highlightAppId) { 369 if (appData.id == highlightAppId) {
373 opt_highlight = true; 370 opt_highlight = true;
374 highlightAppId = null; 371 highlightAppId = null;
375 } 372 }
376 373
377 var pageIndex = appData.page_index || 0; 374 var pageIndex = appData.page_index || 0;
378 375
379 if (pageIndex >= appsPages.length) { 376 if (pageIndex >= appsPages.length) {
380 while (pageIndex >= appsPages.length) { 377 while (pageIndex >= appsPages.length) {
381 appendTilePage(new ntp4.AppsPage(), '', true, bookmarksPage); 378 appendTilePage(new ntp4.AppsPage(),
379 localStrings.getString('appDefaultPageName'), true,
380 bookmarksPage);
382 } 381 }
383 updateSliderCards(); 382 updateSliderCards();
384 } 383 }
385 384
386 var page = appsPages[pageIndex]; 385 var page = appsPages[pageIndex];
387 var app = $(appData.id); 386 var app = $(appData.id);
388 if (app) 387 if (app)
389 app.replaceAppData(appData); 388 app.replaceAppData(appData);
390 else 389 else
391 page.appendApp(appData, opt_highlight); 390 page.appendApp(appData, opt_highlight);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 function appsPrefChangeCallback(data) { 433 function appsPrefChangeCallback(data) {
435 for (var i = 0; i < data.apps.length; ++i) { 434 for (var i = 0; i < data.apps.length; ++i) {
436 $(data.apps[i].id).appData = data.apps[i]; 435 $(data.apps[i].id).appData = data.apps[i];
437 } 436 }
438 437
439 // Set the App dot names. Skip the first and last dots (Most Visited and 438 // Set the App dot names. Skip the first and last dots (Most Visited and
440 // Bookmarks). 439 // Bookmarks).
441 var dots = dotList.getElementsByClassName('dot'); 440 var dots = dotList.getElementsByClassName('dot');
442 // TODO(csilv): Remove this calcluation if/when we remove the flag for 441 // TODO(csilv): Remove this calcluation if/when we remove the flag for
443 // for the bookmarks page. 442 // for the bookmarks page.
444 var length = bookmarksPage ? dots.length - 2 : dots.Length - 1; 443 var length = bookmarksPage ? dots.length - 1 : dots.length;
445 for (var i = 1; i < length; ++i) { 444 for (var i = 1; i < length; ++i) {
446 dots[i].displayTitle = data.appPageNames[i - 1] || ''; 445 dots[i].displayTitle = data.appPageNames[i - 1] || '';
447 } 446 }
448 } 447 }
449 448
450 /** 449 /**
451 * Listener for offline status change events. Updates apps that are 450 * Listener for offline status change events. Updates apps that are
452 * not offline-enabled to be grayscale if the browser is offline. 451 * not offline-enabled to be grayscale if the browser is offline.
453 */ 452 */
454 function updateOfflineEnabledApps() { 453 function updateOfflineEnabledApps() {
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 return null; 534 return null;
536 } 535 }
537 536
538 /** 537 /**
539 * Called whenever tiles should be re-arranging themselves out of the way of a 538 * Called whenever tiles should be re-arranging themselves out of the way of a
540 * moving or insert tile. 539 * moving or insert tile.
541 */ 540 */
542 function enterRearrangeMode() { 541 function enterRearrangeMode() {
543 var tempPage = new ntp4.AppsPage(); 542 var tempPage = new ntp4.AppsPage();
544 tempPage.classList.add('temporary'); 543 tempPage.classList.add('temporary');
545 appendTilePage(tempPage, '', true, bookmarksPage); 544 appendTilePage(tempPage, localStrings.getString('appDefaultPageName'),
545 true, bookmarksPage);
546 var tempIndex = Array.prototype.indexOf.call(tilePages, tempPage); 546 var tempIndex = Array.prototype.indexOf.call(tilePages, tempPage);
547 if (cardSlider.currentCard >= tempIndex) 547 if (cardSlider.currentCard >= tempIndex)
548 cardSlider.currentCard += 1; 548 cardSlider.currentCard += 1;
549 updateSliderCards(); 549 updateSliderCards();
550 550
551 if (ntp4.getCurrentlyDraggingTile().firstChild.canBeRemoved()) 551 if (ntp4.getCurrentlyDraggingTile().firstChild.canBeRemoved())
552 $('footer').classList.add('showing-trash-mode'); 552 $('footer').classList.add('showing-trash-mode');
553 } 553 }
554 554
555 /** 555 /**
556 * Invoked whenever some app is released 556 * Invoked whenever some app is released
557 * @param {Grabber.Event} e The Grabber RELEASE event. 557 * @param {Grabber.Event} e The Grabber RELEASE event.
558 */ 558 */
559 function leaveRearrangeMode(e) { 559 function leaveRearrangeMode(e) {
560 var tempPage = document.querySelector('.tile-page.temporary'); 560 var tempPage = document.querySelector('.tile-page.temporary');
561 var dot = tempPage.navigationDot; 561 var dot = tempPage.navigationDot;
562 if (!tempPage.tileCount && tempPage != cardSlider.currentCardValue) { 562 if (!tempPage.tileCount && tempPage != cardSlider.currentCardValue) {
563 dot.animateRemove(); 563 dot.animateRemove();
564 var tempIndex = Array.prototype.indexOf.call(tilePages, tempPage); 564 var tempIndex = Array.prototype.indexOf.call(tilePages, tempPage);
565 if (cardSlider.currentCard > tempIndex) 565 if (cardSlider.currentCard > tempIndex)
566 cardSlider.currentCard -= 1; 566 cardSlider.currentCard -= 1;
567 tempPage.parentNode.removeChild(tempPage); 567 tempPage.parentNode.removeChild(tempPage);
568 updateSliderCards(); 568 updateSliderCards();
569 } else { 569 } else {
570 tempPage.classList.remove('temporary'); 570 tempPage.classList.remove('temporary');
571 saveAppPageName(tempPage, ''); 571 saveAppPageName(tempPage, localStrings.getString('appDefaultPageName'));
Dan Beam 2011/10/14 08:19:56 Might it make sense to keep one central var app
572 } 572 }
573 573
574 $('footer').classList.remove('showing-trash-mode'); 574 $('footer').classList.remove('showing-trash-mode');
575 } 575 }
576 576
577 /** 577 /**
578 * Handler for key events on the page. Ctrl-Arrow will switch the visible 578 * Handler for key events on the page. Ctrl-Arrow will switch the visible
579 * page. 579 * page.
580 * @param {Event} e The KeyboardEvent. 580 * @param {Event} e The KeyboardEvent.
581 */ 581 */
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
972 var getAppsCallback = ntp4.getAppsCallback; 972 var getAppsCallback = ntp4.getAppsCallback;
973 var appsPrefChangeCallback = ntp4.appsPrefChangeCallback; 973 var appsPrefChangeCallback = ntp4.appsPrefChangeCallback;
974 var themeChanged = ntp4.themeChanged; 974 var themeChanged = ntp4.themeChanged;
975 var recentlyClosedTabs = ntp4.setRecentlyClosedTabs; 975 var recentlyClosedTabs = ntp4.setRecentlyClosedTabs;
976 var setMostVisitedPages = ntp4.setMostVisitedPages; 976 var setMostVisitedPages = ntp4.setMostVisitedPages;
977 var updateLogin = ntp4.updateLogin; 977 var updateLogin = ntp4.updateLogin;
978 978
979 document.addEventListener('DOMContentLoaded', ntp4.initialize); 979 document.addEventListener('DOMContentLoaded', ntp4.initialize);
980 window.addEventListener('online', ntp4.updateOfflineEnabledApps); 980 window.addEventListener('online', ntp4.updateOfflineEnabledApps);
981 window.addEventListener('offline', ntp4.updateOfflineEnabledApps); 981 window.addEventListener('offline', ntp4.updateOfflineEnabledApps);
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/webui/ntp/app_launcher_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698