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 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 293 link.href = 'chrome://bookmarks/#' + this.id; | 293 link.href = 'chrome://bookmarks/#' + this.id; |
| 294 | 294 |
| 295 var wrapper = $('bookmarks-bottom-link-wrapper'); | 295 var wrapper = $('bookmarks-bottom-link-wrapper'); |
| 296 if (items.length > MAX_BOOKMARK_TILES) { | 296 if (items.length > MAX_BOOKMARK_TILES) { |
| 297 var link = wrapper.querySelector('a'); | 297 var link = wrapper.querySelector('a'); |
| 298 link.href = 'chrome://bookmarks/#' + this.id; | 298 link.href = 'chrome://bookmarks/#' + this.id; |
| 299 wrapper.hidden = false; | 299 wrapper.hidden = false; |
| 300 } else { | 300 } else { |
| 301 wrapper.hidden = true; | 301 wrapper.hidden = true; |
| 302 } | 302 } |
| 303 | |
| 304 if (this.id === ROOT_NODE_ID && !tile_count) | |
| 305 this.showImportPromo_(); | |
| 303 }, | 306 }, |
| 304 | 307 |
| 305 /** | 308 /** |
| 306 * Determine whether a bookmark ID matches a folder in the current | 309 * Determine whether a bookmark ID matches a folder in the current |
| 307 * hierarchy. | 310 * hierarchy. |
| 308 * @param {string} id The bookmark ID to search for. | 311 * @param {string} id The bookmark ID to search for. |
| 309 * @private | 312 * @private |
| 310 */ | 313 */ |
| 311 isBookmarkInParentHierarchy_: function(id) { | 314 isBookmarkInParentHierarchy_: function(id) { |
| 312 var titlesWrapper = $('bookmarks-title-wrapper'); | 315 var titlesWrapper = $('bookmarks-title-wrapper'); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 361 | 364 |
| 362 /** | 365 /** |
| 363 * Invoked when a node has been added. | 366 * Invoked when a node has been added. |
| 364 * @param {string} id The id of the newly created bookmark node. | 367 * @param {string} id The id of the newly created bookmark node. |
| 365 * @param {Object} bookmark The new bookmark node. | 368 * @param {Object} bookmark The new bookmark node. |
| 366 * @param {boolean} fromCurrentPage True if the action was from this page. | 369 * @param {boolean} fromCurrentPage True if the action was from this page. |
| 367 */ | 370 */ |
| 368 bookmarkNodeAdded: function(id, bookmark, fromCurrentPage) { | 371 bookmarkNodeAdded: function(id, bookmark, fromCurrentPage) { |
| 369 if (this.importing) return; | 372 if (this.importing) return; |
| 370 if (this.currentlyInFolder_(bookmark.parentId)) { | 373 if (this.currentlyInFolder_(bookmark.parentId)) { |
| 374 // Hide the import promo if it exists. | |
| 375 this.hideImportPromo_(); | |
| 371 // If source of the add came from this page, show an animated insertion, | 376 // If source of the add came from this page, show an animated insertion, |
| 372 // otherwise just quietly do it. | 377 // otherwise just quietly do it. |
| 373 this.addTileAt(new Bookmark(bookmark), bookmark.index, fromCurrentPage); | 378 this.addTileAt(new Bookmark(bookmark), bookmark.index, fromCurrentPage); |
| 374 this.repositionTiles_(); | 379 this.repositionTiles_(); |
| 375 } | 380 } |
| 376 }, | 381 }, |
| 377 | 382 |
| 378 /** | 383 /** |
| 379 * Invoked when the title or url of a node changes. | 384 * Invoked when the title or url of a node changes. |
| 380 * @param {string} id The id of the changed node. | 385 * @param {string} id The id of the changed node. |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 536 title = text || ('IMG' == img.nodeName && img.alt); | 541 title = text || ('IMG' == img.nodeName && img.alt); |
| 537 } | 542 } |
| 538 // If we *still* don't have a title, just use the URL. | 543 // If we *still* don't have a title, just use the URL. |
| 539 if (!title) | 544 if (!title) |
| 540 title = url; | 545 title = url; |
| 541 // Create a bookmark for the dropped data. | 546 // Create a bookmark for the dropped data. |
| 542 this.generateBookmarkForLink(parentId, index, title, url); | 547 this.generateBookmarkForLink(parentId, index, title, url); |
| 543 }, | 548 }, |
| 544 | 549 |
| 545 /** | 550 /** |
| 551 * Show the 'Import bookmarks' promo | |
|
Evan Stade
2011/09/07 19:16:18
.
csilv
2011/09/07 19:29:59
Done.
| |
| 552 * @private | |
| 553 */ | |
| 554 showImportPromo_: function() { | |
| 555 var importTemplate = $('bookmarks-import-data-link-template'); | |
| 556 var importWrapper = importTemplate.cloneNode(true); | |
| 557 importWrapper.id = ''; | |
| 558 importWrapper.hidden = false; | |
| 559 this.querySelector('.tile-page-content').appendChild(importWrapper); | |
| 560 }, | |
| 561 | |
| 562 /** | |
| 563 * Hide the 'Import bookmarks' promo | |
|
Evan Stade
2011/09/07 19:16:18
.
csilv
2011/09/07 19:29:59
Done.
| |
| 564 * @private | |
| 565 */ | |
| 566 hideImportPromo_: function() { | |
| 567 var wrapper = this.querySelector('.bookmarks-import-data-link-wrapper'); | |
| 568 if (wrapper) | |
| 569 wrapper.parentNode.removeChild(wrapper); | |
| 570 }, | |
| 571 | |
| 572 /** | |
| 546 * Create a bookmark from a title/url. | 573 * Create a bookmark from a title/url. |
| 547 * @param {!string} parentId Stringified int64 of the parent node's ID. | 574 * @param {!string} parentId Stringified int64 of the parent node's ID. |
| 548 * @param {number} index Sibling relative index, i.e. 3rd on this level. | 575 * @param {number} index Sibling relative index, i.e. 3rd on this level. |
| 549 * @param {string} title More human readable title of the bookmark. | 576 * @param {string} title More human readable title of the bookmark. |
| 550 * @param {string} url URL of the bookmark to be created. | 577 * @param {string} url URL of the bookmark to be created. |
| 551 */ | 578 */ |
| 552 generateBookmarkForLink: function(parentId, index, title, url) { | 579 generateBookmarkForLink: function(parentId, index, title, url) { |
| 553 // Bookmark creation actually only *requires* a parent ID, as if we just | 580 // Bookmark creation actually only *requires* a parent ID, as if we just |
| 554 // pass a parent ID it's created as a folder with blank title as a child | 581 // pass a parent ID it's created as a folder with blank title as a child |
| 555 // of that parent. | 582 // of that parent. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 596 tile.stripeColor = color; | 623 tile.stripeColor = color; |
| 597 } | 624 } |
| 598 | 625 |
| 599 return { | 626 return { |
| 600 BookmarksPage: BookmarksPage, | 627 BookmarksPage: BookmarksPage, |
| 601 initBookmarkChevron: initBookmarkChevron, | 628 initBookmarkChevron: initBookmarkChevron, |
| 602 }; | 629 }; |
| 603 }); | 630 }); |
| 604 | 631 |
| 605 window.addEventListener('load', ntp4.initBookmarkChevron); | 632 window.addEventListener('load', ntp4.initBookmarkChevron); |
| OLD | NEW |