Commit b25ae712 authored by estade@chromium.org's avatar estade@chromium.org

ntp4: fix brokeness when new apps are added

this code should go away soon but for now this is less broke.

BUG=none
TEST=when you add a new app, the nav dots at the bottom don't break horribly.

Review URL: http://codereview.chromium.org/6990063

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86479 0039d316-1c4b-4281-b951-d872f2087c98
parent 13daa302
...@@ -272,6 +272,21 @@ var CardSlider = (function() { ...@@ -272,6 +272,21 @@ var CardSlider = (function() {
} }
}, },
/**
* Selects a card from the stack. Passes through to selectCard.
* @param {Node} newCard The card that should be selected.
* @param {boolean=} opt_animate Whether to animate.
*/
selectCardByValue: function(newCard, opt_animate) {
for (var i = 0; i < this.cards_.length; i++) {
if (newCard == this.cards_[i]) {
this.selectCard(i, opt_animate);
return;
}
}
assert(false);
},
/** /**
* Centers the view on the card denoted by this.currentCard. Can either * Centers the view on the card denoted by this.currentCard. Can either
* animate to that card or snap to it. * animate to that card or snap to it.
......
...@@ -78,12 +78,6 @@ cr.define('ntp4', function() { ...@@ -78,12 +78,6 @@ cr.define('ntp4', function() {
*/ */
var DEFAULT_TRANSITION_TIME = 500; var DEFAULT_TRANSITION_TIME = 500;
/**
* All the Grabber objects currently in use on the page
* @type {Array.<Grabber>}
*/
var grabbers = [];
/** /**
* Invoked at startup once the DOM is available to initialize the app. * Invoked at startup once the DOM is available to initialize the app.
*/ */
...@@ -217,29 +211,13 @@ cr.define('ntp4', function() { ...@@ -217,29 +211,13 @@ cr.define('ntp4', function() {
* applications. * applications.
*/ */
function getAppsCallback(data) { function getAppsCallback(data) {
// Clean up any existing grabber objects - cancelling any outstanding drag.
// Ideally an async app update wouldn't disrupt an active drag but
// that would require us to re-use existing elements and detect how the apps
// have changed, which would be a lot of work.
// Note that we have to explicitly clean up the grabber objects so they stop
// listening to events and break the DOM<->JS cycles necessary to enable
// collection of all these objects.
grabbers.forEach(function(g) {
// Note that this may raise DRAG_END/RELEASE events to clean up an
// oustanding drag.
g.dispose();
});
assert(!draggingAppContainer && !draggingAppOriginalPosition &&
!draggingAppOriginalPage);
grabbers = [];
// Clear any existing apps pages and dots. // Clear any existing apps pages and dots.
// TODO(rbyers): It might be nice to preserve animation of dots after an // TODO(rbyers): It might be nice to preserve animation of dots after an
// uninstall. Could we re-use the existing page and dot elements? It seems // uninstall. Could we re-use the existing page and dot elements? It seems
// unfortunate to have Chrome send us the entire apps list after an // unfortunate to have Chrome send us the entire apps list after an
// uninstall. // uninstall.
for (var i = 0; i < appsPages.length; i++) { while (appsPages.length > 0) {
var page = appsPages[i]; var page = appsPages[0];
var dot = page.navigationDot; var dot = page.navigationDot;
page.tearDown(); page.tearDown();
...@@ -344,7 +322,6 @@ cr.define('ntp4', function() { ...@@ -344,7 +322,6 @@ cr.define('ntp4', function() {
pageList.appendChild(page); pageList.appendChild(page);
// Make a deep copy of the dot template to add a new one. // Make a deep copy of the dot template to add a new one.
var dotCount = dots.length;
var newDot = dotTemplate.cloneNode(true); var newDot = dotTemplate.cloneNode(true);
newDot.querySelector('span').textContent = page.pageName; newDot.querySelector('span').textContent = page.pageName;
if (opt_animate) if (opt_animate)
...@@ -353,7 +330,7 @@ cr.define('ntp4', function() { ...@@ -353,7 +330,7 @@ cr.define('ntp4', function() {
page.navigationDot = newDot; page.navigationDot = newDot;
newDot.showPage = function() { newDot.showPage = function() {
cardSlider.selectCard(dotCount, true); cardSlider.selectCardByValue(page, true);
}; };
function switchPage(e) { function switchPage(e) {
newDot.showPage(); newDot.showPage();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment