OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 (function() { | 5 (function() { |
6 /** @const */ var BookmarkList = bmm.BookmarkList; | 6 /** @const */ var BookmarkList = bmm.BookmarkList; |
7 /** @const */ var BookmarkTree = bmm.BookmarkTree; | 7 /** @const */ var BookmarkTree = bmm.BookmarkTree; |
8 /** @const */ var Command = cr.ui.Command; | 8 /** @const */ var Command = cr.ui.Command; |
9 /** @const */ var LinkKind = cr.LinkKind; | 9 /** @const */ var LinkKind = cr.LinkKind; |
10 /** @const */ var ListItem = cr.ui.ListItem; | 10 /** @const */ var ListItem = cr.ui.ListItem; |
11 /** @const */ var Menu = cr.ui.Menu; | 11 /** @const */ var Menu = cr.ui.Menu; |
12 /** @const */ var MenuButton = cr.ui.MenuButton; | 12 /** @const */ var MenuButton = cr.ui.MenuButton; |
13 /** @const */ var Splitter = cr.ui.Splitter; | 13 /** @const */ var Splitter = cr.ui.Splitter; |
14 /** @const */ var TreeItem = cr.ui.TreeItem; | 14 /** @const */ var TreeItem = cr.ui.TreeItem; |
15 | 15 |
16 /** | 16 /** |
17 * An array containing the BookmarkTreeNodes that were deleted in the last | 17 * An array containing the BookmarkTreeNodes that were deleted in the last |
18 * deletion action. This is used for implementing undo. | 18 * deletion action. This is used for implementing undo. |
19 * @type {?{nodes: Array.<Array.<BookmarkTreeNode>>, target: EventTarget}} | 19 * @type {?{nodes: Array<Array<BookmarkTreeNode>>, target: EventTarget}} |
20 */ | 20 */ |
21 var lastDeleted; | 21 var lastDeleted; |
22 | 22 |
23 /** | 23 /** |
24 * | 24 * |
25 * Holds the last DOMTimeStamp when mouse pointer hovers on folder in tree | 25 * Holds the last DOMTimeStamp when mouse pointer hovers on folder in tree |
26 * view. Zero means pointer doesn't hover on folder. | 26 * view. Zero means pointer doesn't hover on folder. |
27 * @type {number} | 27 * @type {number} |
28 */ | 28 */ |
29 var lastHoverOnFolderTimeStamp = 0; | 29 var lastHoverOnFolderTimeStamp = 0; |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 } | 301 } |
302 } | 302 } |
303 | 303 |
304 function handleLoadForTree(e) { | 304 function handleLoadForTree(e) { |
305 processHash(); | 305 processHash(); |
306 } | 306 } |
307 | 307 |
308 /** | 308 /** |
309 * Returns a promise for all the URLs in the {@code nodes} and the direct | 309 * Returns a promise for all the URLs in the {@code nodes} and the direct |
310 * children of {@code nodes}. | 310 * children of {@code nodes}. |
311 * @param {!Array.<BookmarkTreeNode>} nodes . | 311 * @param {!Array<BookmarkTreeNode>} nodes . |
312 * @return {!Promise.<Array.<string>>} . | 312 * @return {!Promise<Array<string>>} . |
313 */ | 313 */ |
314 function getAllUrls(nodes) { | 314 function getAllUrls(nodes) { |
315 var urls = []; | 315 var urls = []; |
316 | 316 |
317 // Adds the node and all its direct children. | 317 // Adds the node and all its direct children. |
318 function addNodes(node) { | 318 function addNodes(node) { |
319 if (node.id == 'new') | 319 if (node.id == 'new') |
320 return; | 320 return; |
321 | 321 |
322 if (node.children) { | 322 if (node.children) { |
(...skipping 16 matching lines...) Expand all Loading... |
339 | 339 |
340 return Promise.all(promises).then(function(nodes) { | 340 return Promise.all(promises).then(function(nodes) { |
341 nodes.forEach(addNodes); | 341 nodes.forEach(addNodes); |
342 return urls; | 342 return urls; |
343 }); | 343 }); |
344 } | 344 } |
345 | 345 |
346 /** | 346 /** |
347 * Returns the nodes (non recursive) to use for the open commands. | 347 * Returns the nodes (non recursive) to use for the open commands. |
348 * @param {HTMLElement} target | 348 * @param {HTMLElement} target |
349 * @return {!Array.<BookmarkTreeNode>} | 349 * @return {!Array<BookmarkTreeNode>} |
350 */ | 350 */ |
351 function getNodesForOpen(target) { | 351 function getNodesForOpen(target) { |
352 if (target == bmm.tree) { | 352 if (target == bmm.tree) { |
353 if (bmm.tree.selectedItem != searchTreeItem) | 353 if (bmm.tree.selectedItem != searchTreeItem) |
354 return bmm.tree.selectedFolders; | 354 return bmm.tree.selectedFolders; |
355 // Fall through to use all nodes in the list. | 355 // Fall through to use all nodes in the list. |
356 } else { | 356 } else { |
357 var items = bmm.list.selectedItems; | 357 var items = bmm.list.selectedItems; |
358 if (items.length) | 358 if (items.length) |
359 return items; | 359 return items; |
360 } | 360 } |
361 | 361 |
362 // The list starts off with a null dataModel. We can get here during startup. | 362 // The list starts off with a null dataModel. We can get here during startup. |
363 if (!bmm.list.dataModel) | 363 if (!bmm.list.dataModel) |
364 return []; | 364 return []; |
365 | 365 |
366 // Return an array based on the dataModel. | 366 // Return an array based on the dataModel. |
367 return bmm.list.dataModel.slice(); | 367 return bmm.list.dataModel.slice(); |
368 } | 368 } |
369 | 369 |
370 /** | 370 /** |
371 * Returns a promise that will contain all URLs of all the selected bookmarks | 371 * Returns a promise that will contain all URLs of all the selected bookmarks |
372 * and the nested bookmarks for use with the open commands. | 372 * and the nested bookmarks for use with the open commands. |
373 * @param {HTMLElement} target The target list or tree. | 373 * @param {HTMLElement} target The target list or tree. |
374 * @return {Promise.<Array.<string>>} . | 374 * @return {Promise<Array<string>>} . |
375 */ | 375 */ |
376 function getUrlsForOpenCommands(target) { | 376 function getUrlsForOpenCommands(target) { |
377 return getAllUrls(getNodesForOpen(target)); | 377 return getAllUrls(getNodesForOpen(target)); |
378 } | 378 } |
379 | 379 |
380 function notNewNode(node) { | 380 function notNewNode(node) { |
381 return node.id != 'new'; | 381 return node.id != 'new'; |
382 } | 382 } |
383 | 383 |
384 /** | 384 /** |
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
840 * @param {EventTarget=} opt_target The target list or tree. | 840 * @param {EventTarget=} opt_target The target list or tree. |
841 * @return {!Array} Array of bookmark nodes. | 841 * @return {!Array} Array of bookmark nodes. |
842 */ | 842 */ |
843 function getSelectedBookmarkNodes(opt_target) { | 843 function getSelectedBookmarkNodes(opt_target) { |
844 return (opt_target || document.activeElement) == bmm.tree ? | 844 return (opt_target || document.activeElement) == bmm.tree ? |
845 bmm.tree.selectedFolders : bmm.list.selectedItems; | 845 bmm.tree.selectedFolders : bmm.list.selectedItems; |
846 } | 846 } |
847 | 847 |
848 /** | 848 /** |
849 * @param {EventTarget=} opt_target The target list or tree. | 849 * @param {EventTarget=} opt_target The target list or tree. |
850 * @return {!Array.<string>} An array of the selected bookmark IDs. | 850 * @return {!Array<string>} An array of the selected bookmark IDs. |
851 */ | 851 */ |
852 function getSelectedBookmarkIds(opt_target) { | 852 function getSelectedBookmarkIds(opt_target) { |
853 var selectedNodes = getSelectedBookmarkNodes(opt_target); | 853 var selectedNodes = getSelectedBookmarkNodes(opt_target); |
854 selectedNodes.sort(function(a, b) { return a.index - b.index }); | 854 selectedNodes.sort(function(a, b) { return a.index - b.index }); |
855 return selectedNodes.map(function(node) { | 855 return selectedNodes.map(function(node) { |
856 return node.id; | 856 return node.id; |
857 }); | 857 }); |
858 } | 858 } |
859 | 859 |
860 /** | 860 /** |
861 * @param {BookmarkTreeNode} node The node to test. | 861 * @param {BookmarkTreeNode} node The node to test. |
862 * @return {boolean} Whether the given node is unmodifiable. | 862 * @return {boolean} Whether the given node is unmodifiable. |
863 */ | 863 */ |
864 function isUnmodifiable(node) { | 864 function isUnmodifiable(node) { |
865 return !!(node && node.unmodifiable); | 865 return !!(node && node.unmodifiable); |
866 } | 866 } |
867 | 867 |
868 /** | 868 /** |
869 * @param {Array.<BookmarkTreeNode>} nodes A list of BookmarkTreeNodes. | 869 * @param {Array<BookmarkTreeNode>} nodes A list of BookmarkTreeNodes. |
870 * @return {boolean} Whether any of the nodes is managed. | 870 * @return {boolean} Whether any of the nodes is managed. |
871 */ | 871 */ |
872 function hasUnmodifiable(nodes) { | 872 function hasUnmodifiable(nodes) { |
873 return nodes.some(isUnmodifiable); | 873 return nodes.some(isUnmodifiable); |
874 } | 874 } |
875 | 875 |
876 /** | 876 /** |
877 * Opens the selected bookmarks. | 877 * Opens the selected bookmarks. |
878 * @param {cr.LinkKind} kind The kind of link we want to open. | 878 * @param {cr.LinkKind} kind The kind of link we want to open. |
879 * @param {HTMLElement=} opt_eventTarget The target of the user initiated event. | 879 * @param {HTMLElement=} opt_eventTarget The target of the user initiated event. |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1218 if (contains(getSelectedBookmarkNodes(), parentNode)) | 1218 if (contains(getSelectedBookmarkNodes(), parentNode)) |
1219 return true; | 1219 return true; |
1220 | 1220 |
1221 // Keep digging. | 1221 // Keep digging. |
1222 return hasSelectedAncestor( | 1222 return hasSelectedAncestor( |
1223 bmm.tree.getBookmarkNodeById(parentNode.parentId)); | 1223 bmm.tree.getBookmarkNodeById(parentNode.parentId)); |
1224 } | 1224 } |
1225 | 1225 |
1226 /** | 1226 /** |
1227 * @param {EventTarget=} opt_target A target to get bookmark IDs from. | 1227 * @param {EventTarget=} opt_target A target to get bookmark IDs from. |
1228 * @return {Array.<string>} An array of bookmarks IDs. | 1228 * @return {Array<string>} An array of bookmarks IDs. |
1229 */ | 1229 */ |
1230 function getFilteredSelectedBookmarkIds(opt_target) { | 1230 function getFilteredSelectedBookmarkIds(opt_target) { |
1231 // Remove duplicates from filteredIds and return. | 1231 // Remove duplicates from filteredIds and return. |
1232 var filteredIds = []; | 1232 var filteredIds = []; |
1233 // Selected nodes to iterate through for matches. | 1233 // Selected nodes to iterate through for matches. |
1234 var nodes = getSelectedBookmarkNodes(opt_target); | 1234 var nodes = getSelectedBookmarkNodes(opt_target); |
1235 | 1235 |
1236 for (var i = 0; i < nodes.length; i++) | 1236 for (var i = 0; i < nodes.length; i++) |
1237 if (!hasSelectedAncestor(bmm.tree.getBookmarkNodeById(nodes[i].parentId))) | 1237 if (!hasSelectedAncestor(bmm.tree.getBookmarkNodeById(nodes[i].parentId))) |
1238 filteredIds.splice(0, 0, nodes[i].id); | 1238 filteredIds.splice(0, 0, nodes[i].id); |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1506 | 1506 |
1507 cr.ui.FocusOutlineManager.forDocument(document); | 1507 cr.ui.FocusOutlineManager.forDocument(document); |
1508 initializeSplitter(); | 1508 initializeSplitter(); |
1509 bmm.addBookmarkModelListeners(); | 1509 bmm.addBookmarkModelListeners(); |
1510 dnd.init(selectItemsAfterUserAction); | 1510 dnd.init(selectItemsAfterUserAction); |
1511 bmm.tree.reload(); | 1511 bmm.tree.reload(); |
1512 } | 1512 } |
1513 | 1513 |
1514 initializeBookmarkManager(); | 1514 initializeBookmarkManager(); |
1515 })(); | 1515 })(); |
OLD | NEW |