Chromium Code Reviews| 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 const BookmarkTree = bmm.BookmarkTree; | 5 const BookmarkTree = bmm.BookmarkTree; |
| 6 const TreeItem = cr.ui.TreeItem; | 6 const TreeItem = cr.ui.TreeItem; |
| 7 | 7 |
| 8 // Delay time (ms) of updating hash after changing current folder. | 8 // Delay time (ms) of updating hash after changing current folder. |
| 9 const NAVIGATE_HASH_UPDATE_DELAY = 250; | 9 const NAVIGATE_HASH_UPDATE_DELAY = 250; |
| 10 // Delay time (ms) of selecting new folder after creation of it. | 10 // Delay time (ms) of selecting new folder after creation of it. |
| 11 const NEWFOLDER_SELECTION_DELAY = 50; | 11 const NEWFOLDER_SELECTION_DELAY = 50; |
| 12 | 12 |
| 13 // Sometimes the extension API is not initialized. | 13 // Sometimes the extension API is not initialized. |
| 14 if (!chrome.bookmarks) | 14 if (!chrome.bookmarks) |
| 15 console.error('Bookmarks extension API is not available'); | 15 console.error('Bookmarks extension API is not available'); |
| 16 | 16 |
| 17 /** | |
| 18 * The local strings object which is used to do the translation. | |
| 19 * @type {!LocalStrings} | |
| 20 */ | |
| 21 var localStrings = new LocalStrings; | |
| 22 | |
| 23 // Get the localized strings from the backend. | 17 // Get the localized strings from the backend. |
| 24 chrome.experimental.bookmarkManager.getStrings(function(data) { | 18 chrome.experimental.bookmarkManager.getStrings(function(data) { |
| 25 // The strings may contain & which we need to strip. | 19 // The strings may contain & which we need to strip. |
| 26 for (var key in data) { | 20 for (var key in data) { |
| 27 data[key] = data[key].replace(/&/, ''); | 21 data[key] = data[key].replace(/&/, ''); |
| 28 } | 22 } |
| 29 | 23 |
| 30 localStrings.templateData = data; | 24 loadTimeData.data = data; |
| 31 i18nTemplate.process(document, data); | 25 var process = document.createElement('script'); |
| 26 process.src = "chrome://resources/js/i18n_template2.js"; | |
|
Dan Beam
2012/04/30 17:04:00
single quotes
Evan Stade
2012/04/30 18:41:48
I confirmed with the author this file is no longer
| |
| 27 document.body.appendChild(process); | |
| 32 }); | 28 }); |
| 33 | 29 |
| 34 /** | 30 /** |
| 35 * The id of the bookmark root. | 31 * The id of the bookmark root. |
| 36 * @type {number} | 32 * @type {number} |
| 37 */ | 33 */ |
| 38 const ROOT_ID = '0'; | 34 const ROOT_ID = '0'; |
|
Dan Beam
2012/04/30 17:04:00
you're gonna get a warning about using const here,
Evan Stade
2012/04/30 18:41:48
oh, just touching this file produces a lot of warn
| |
| 39 | 35 |
| 40 var searchTreeItem = new TreeItem({ | 36 var searchTreeItem = new TreeItem({ |
| 41 icon: 'images/bookmark_manager_search.png', | 37 icon: 'images/bookmark_manager_search.png', |
| 42 bookmarkId: 'q=' | 38 bookmarkId: 'q=' |
| 43 }); | 39 }); |
| 44 bmm.treeLookup[searchTreeItem.bookmarkId] = searchTreeItem; | 40 bmm.treeLookup[searchTreeItem.bookmarkId] = searchTreeItem; |
| 45 | 41 |
| 46 var recentTreeItem = new TreeItem({ | 42 var recentTreeItem = new TreeItem({ |
| 47 icon: 'images/bookmark_manager_recent.png', | 43 icon: 'images/bookmark_manager_recent.png', |
| 48 bookmarkId: 'recent' | 44 bookmarkId: 'recent' |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 114 tree.addEventListener('change', checkDisabilities); | 110 tree.addEventListener('change', checkDisabilities); |
| 115 checkDisabilities(); | 111 checkDisabilities(); |
| 116 | 112 |
| 117 /** | 113 /** |
| 118 * Callback for the new folder command. This creates a new folder and starts | 114 * Callback for the new folder command. This creates a new folder and starts |
| 119 * a rename of it. | 115 * a rename of it. |
| 120 */ | 116 */ |
| 121 function newFolder() { | 117 function newFolder() { |
| 122 var parentId = tree.selectedItem.bookmarkId; | 118 var parentId = tree.selectedItem.bookmarkId; |
| 123 chrome.bookmarks.create({ | 119 chrome.bookmarks.create({ |
| 124 title: localStrings.getString('new_folder_name'), | 120 title: loadTimeData.getString('new_folder_name'), |
| 125 parentId: parentId | 121 parentId: parentId |
| 126 }, function(newNode) { | 122 }, function(newNode) { |
| 127 // This callback happens before the event that triggers the tree/list to | 123 // This callback happens before the event that triggers the tree/list to |
| 128 // get updated so delay the work so that the tree/list gets updated first. | 124 // get updated so delay the work so that the tree/list gets updated first. |
| 129 setTimeout(function() { | 125 setTimeout(function() { |
| 130 var newItem = bmm.treeLookup[newNode.id]; | 126 var newItem = bmm.treeLookup[newNode.id]; |
| 131 tree.selectedItem = newItem; | 127 tree.selectedItem = newItem; |
| 132 newItem.editing = true; | 128 newItem.editing = true; |
| 133 }, NEWFOLDER_SELECTION_DELAY); | 129 }, NEWFOLDER_SELECTION_DELAY); |
| 134 }); | 130 }); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 190 window.close(); | 186 window.close(); |
| 191 }); | 187 }); |
| 192 } | 188 } |
| 193 | 189 |
| 194 /** | 190 /** |
| 195 * Adds handlers to buttons. | 191 * Adds handlers to buttons. |
| 196 */ | 192 */ |
| 197 document.querySelector('#new-folder').addEventListener('click', newFolder); | 193 document.querySelector('#new-folder').addEventListener('click', newFolder); |
| 198 document.querySelector('#save').addEventListener('click', bookmarkAllTabs); | 194 document.querySelector('#save').addEventListener('click', bookmarkAllTabs); |
| 199 document.querySelector('#cancel').addEventListener('click', cancel); | 195 document.querySelector('#cancel').addEventListener('click', cancel); |
| OLD | NEW |