| Index: chrome/browser/resources/md_bookmarks/util.js
|
| diff --git a/chrome/browser/resources/md_bookmarks/util.js b/chrome/browser/resources/md_bookmarks/util.js
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..9c1e942146e8e072d41d79e71f22a249c8983f79
|
| --- /dev/null
|
| +++ b/chrome/browser/resources/md_bookmarks/util.js
|
| @@ -0,0 +1,75 @@
|
| +// Copyright 2017 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +/**
|
| + * @fileoverview Utility functions for the Bookmarks page.
|
| + */
|
| +
|
| +cr.define('bookmarks.util', function() {
|
| + /**
|
| + * @param {BookmarksPageState} state
|
| + * @return {!Array<string>}
|
| + */
|
| + function getDisplayedList(state) {
|
| + if (state.selectedFolder)
|
| + return assert(state.nodes[state.selectedFolder].children);
|
| +
|
| + return state.search.results;
|
| + }
|
| +
|
| + /**
|
| + * @param {BookmarkTreeNode} rootNode
|
| + * @return {NodeList}
|
| + */
|
| + function normalizeNodes(rootNode) {
|
| + /** @type {NodeList} */
|
| + var nodeMap = {};
|
| + var queue = [];
|
| + queue.push(rootNode);
|
| +
|
| + while (queue.length > 0) {
|
| + var node = queue.pop();
|
| + // Node index is not necessary and not kept up-to-date. Remove it from the
|
| + // data structure so we don't accidentally depend on the incorrect
|
| + // information.
|
| + delete node.index;
|
| + nodeMap[node.id] = node;
|
| + if (node.children) {
|
| + var childIds = [];
|
| + node.children.forEach(function(child) {
|
| + childIds.push(child.id);
|
| + queue.push(child);
|
| + });
|
| + node.children = childIds;
|
| + }
|
| + }
|
| +
|
| + return nodeMap;
|
| + }
|
| +
|
| + /** @return {BookmarksPageState} */
|
| + function createEmptyState() {
|
| + return {
|
| + nodes: {},
|
| + selectedFolder: '0',
|
| + closedFolders: {},
|
| + search: {
|
| + term: '',
|
| + inProgress: false,
|
| + results: [],
|
| + },
|
| + selection: {
|
| + items: {},
|
| + anchor: null,
|
| + count: 0,
|
| + },
|
| + };
|
| + }
|
| +
|
| + return {
|
| + createEmptyState: createEmptyState,
|
| + getDisplayedList: getDisplayedList,
|
| + normalizeNodes: normalizeNodes,
|
| + };
|
| +});
|
|
|