| 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..3bc47038343be1422a05104cb936f6e8d99fd911
|
| --- /dev/null
|
| +++ b/chrome/browser/resources/md_bookmarks/util.js
|
| @@ -0,0 +1,63 @@
|
| +// 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) {
|
| + return assert(state.nodes[assert(state.selectedFolder)].children);
|
| + }
|
| +
|
| + /**
|
| + * @param {BookmarkTreeNode} rootNode
|
| + * @return {NodeList}
|
| + */
|
| + function normalizeNodes(rootNode) {
|
| + /** @type {NodeList} */
|
| + var nodeList = {};
|
| + var stack = [];
|
| + stack.push(rootNode);
|
| +
|
| + while (stack.length > 0) {
|
| + var node = stack.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;
|
| + nodeList[node.id] = node;
|
| + if (!node.children)
|
| + continue;
|
| +
|
| + var childIds = [];
|
| + node.children.forEach(function(child) {
|
| + childIds.push(child.id);
|
| + stack.push(child);
|
| + });
|
| + node.children = childIds;
|
| + }
|
| +
|
| + return nodeList;
|
| + }
|
| +
|
| + /** @return {!BookmarksPageState} */
|
| + function createEmptyState() {
|
| + return {
|
| + nodes: {},
|
| + selectedFolder: '0',
|
| + closedFolders: {},
|
| + };
|
| + }
|
| +
|
| + return {
|
| + createEmptyState: createEmptyState,
|
| + getDisplayedList: getDisplayedList,
|
| + normalizeNodes: normalizeNodes,
|
| + };
|
| +});
|
|
|