Chromium Code Reviews| 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 /** | 10 /** |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 209 this.removeAllTiles(); | 209 this.removeAllTiles(); |
| 210 for (var i = 0; i < items.length; i++) | 210 for (var i = 0; i < items.length; i++) |
| 211 this.appendTile(new Bookmark(items[i]), false); | 211 this.appendTile(new Bookmark(items[i]), false); |
| 212 }, | 212 }, |
| 213 | 213 |
| 214 /** @inheritDoc */ | 214 /** @inheritDoc */ |
| 215 shouldAcceptDrag: function(dataTransfer) { | 215 shouldAcceptDrag: function(dataTransfer) { |
| 216 return false; | 216 return false; |
| 217 }, | 217 }, |
| 218 | 218 |
| 219 bookmarkImportBegan: function() { | |
|
Evan Stade
2011/08/23 21:50:50
why is this here? why can't you just handle it in
csilv
2011/08/24 23:15:11
We could handle this in the C++ handler, but I thi
| |
| 220 this.importing = true; | |
| 221 }, | |
| 222 | |
| 223 bookmarkImportEnded: function() { | |
| 224 // When importing is done, reload the bookmarks page. | |
| 225 this.importing = false; | |
| 226 chrome.send('getBookmarksData', []); | |
| 227 }, | |
| 228 | |
| 229 bookmarkNodeAdded: function(id, bookmark) { | |
|
Evan Stade
2011/08/23 21:50:50
document each function
csilv
2011/08/24 23:15:11
Done.
| |
| 230 if (this.importing) return; | |
| 231 if (this.id == bookmark.parentId) { | |
|
Evan Stade
2011/08/23 21:50:50
no curlies
csilv
2011/08/24 23:15:11
Done.
| |
| 232 this.addTileAt(new Bookmark(bookmark), bookmark.index, false); | |
| 233 } | |
| 234 }, | |
| 235 | |
| 236 bookmarkNodeChanged: function(id, changeInfo) { | |
|
Evan Stade
2011/08/23 21:50:50
wouldn't a change to a folder name anywhere in the
csilv
2011/08/24 23:15:11
Yes indeed. Fixed here and also in move/remove.
| |
| 237 if (this.importing) return; | |
| 238 | |
| 239 // If the current folder is being re-named, reload the page. | |
| 240 // TODO(csilv): Optimize this to reload just the titles. | |
| 241 if (this.id == id) { | |
| 242 chrome.send('getBookmarksData', [this.id]); | |
| 243 return; | |
| 244 } | |
| 245 | |
| 246 // If the target item is contained in this folder, update just that item. | |
| 247 for (var i = 0; i < this.tiles.length; i++) { | |
| 248 var tile = this.tiles[i]; | |
| 249 var data = tile.firstChild.data; | |
| 250 | |
| 251 if (data.id == id) { | |
| 252 data.title = changeInfo.title; | |
| 253 var title = tile.querySelector('.title'); | |
| 254 title.textContent = data.title; | |
| 255 | |
| 256 if (changeInfo.url) { | |
| 257 data.url = changeInfo.url; | |
| 258 var button = tile.querySelector('.button'); | |
| 259 button.href = title.href = data.url; | |
| 260 } | |
| 261 break; | |
| 262 } | |
| 263 } | |
| 264 }, | |
| 265 | |
| 266 bookmarkNodeChildrenReordered: function(id, reorderInfo) { | |
| 267 if (this.id == id) | |
| 268 chrome.send('getBookmarksData', [this.id]); | |
| 269 }, | |
| 270 | |
| 271 bookmarkNodeMoved: function(id, moveInfo) { | |
| 272 // Reload the current page if the target item is the current folder | |
| 273 // or the target item is being moved to/from this folder. | |
| 274 // TODO(csilv): Optimize this by doing less than reloading the folder. | |
| 275 if (this.id == id || | |
| 276 this.id == moveInfo.parentId || | |
| 277 this.id == moveInfo.oldParentId) | |
|
Evan Stade
2011/08/23 21:50:50
curlies
csilv
2011/08/24 23:15:11
Done.
| |
| 278 chrome.send('getBookmarksData', [this.id]); | |
| 279 }, | |
| 280 | |
| 281 bookmarkNodeRemoved: function(id, removeInfo) { | |
| 282 // If the target item is the visibile folder, load the contents of the | |
| 283 // parent folder. | |
| 284 if (this.id == id) { | |
| 285 chrome.send('getBookmarksData', [removeInfo.parentId]); | |
| 286 return; | |
| 287 } | |
| 288 | |
| 289 // If the target item is contained in the visible folder, find the | |
| 290 // matching tile and delete it. | |
| 291 if (this.id == removeInfo.parentId) { | |
| 292 for (var i = 0; i < this.tiles.length; i++) { | |
| 293 var tile = this.tiles[i]; | |
| 294 if (tile.firstChild.data.id == id) { | |
| 295 this.removeTile(tile, false); | |
| 296 break; | |
| 297 } | |
| 298 } | |
| 299 } | |
| 300 }, | |
| 301 | |
| 219 /** | 302 /** |
| 220 * Set the bookmark data that should be displayed, replacing any existing | 303 * Set the bookmark data that should be displayed, replacing any existing |
| 221 * data. | 304 * data. |
| 222 */ | 305 */ |
| 223 set data(data) { | 306 set data(data) { |
| 307 this.id = data.navigationItems[0].id; | |
| 224 this.updateBookmarkTiles_(data.items); | 308 this.updateBookmarkTiles_(data.items); |
| 225 this.updateBookmarkTitles_(data.navigationItems); | 309 this.updateBookmarkTitles_(data.navigationItems); |
| 226 }, | 310 }, |
| 227 }; | 311 }; |
| 228 | 312 |
| 229 /** | 313 /** |
| 230 * Initializes and renders the bookmark chevron canvas. This needs to be | 314 * Initializes and renders the bookmark chevron canvas. This needs to be |
| 231 * performed after the page has been loaded so that we have access to the | 315 * performed after the page has been loaded so that we have access to the |
| 232 * style sheet values. | 316 * style sheet values. |
| 233 */ | 317 */ |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 258 }; | 342 }; |
| 259 | 343 |
| 260 return { | 344 return { |
| 261 BookmarksPage: BookmarksPage, | 345 BookmarksPage: BookmarksPage, |
| 262 initBookmarkChevron: initBookmarkChevron, | 346 initBookmarkChevron: initBookmarkChevron, |
| 263 setBookmarksFaviconDominantColor: setBookmarksFaviconDominantColor | 347 setBookmarksFaviconDominantColor: setBookmarksFaviconDominantColor |
| 264 }; | 348 }; |
| 265 }); | 349 }); |
| 266 | 350 |
| 267 window.addEventListener('load', ntp4.initBookmarkChevron); | 351 window.addEventListener('load', ntp4.initBookmarkChevron); |
| OLD | NEW |