Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(569)

Side by Side Diff: chrome/browser/resources/bookmark_manager/js/main.js

Issue 7572022: Use bookmark manager to add/edit bookmark pages with webui_dialogs=1. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 const BookmarkList = bmm.BookmarkList; 5 const BookmarkList = bmm.BookmarkList;
6 const BookmarkTree = bmm.BookmarkTree; 6 const BookmarkTree = bmm.BookmarkTree;
7 const ListItem = cr.ui.ListItem; 7 const ListItem = cr.ui.ListItem;
8 const TreeItem = cr.ui.TreeItem; 8 const TreeItem = cr.ui.TreeItem;
9 const LinkKind = cr.LinkKind; 9 const LinkKind = cr.LinkKind;
10 const Command = cr.ui.Command; 10 const Command = cr.ui.Command;
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 function updateParentId(id) { 147 function updateParentId(id) {
148 list.parentId = id; 148 list.parentId = id;
149 if (id in bmm.treeLookup) 149 if (id in bmm.treeLookup)
150 tree.selectedItem = bmm.treeLookup[id]; 150 tree.selectedItem = bmm.treeLookup[id];
151 } 151 }
152 152
153 // We listen to hashchange so that we can update the currently shown folder when 153 // We listen to hashchange so that we can update the currently shown folder when
154 // the user goes back and forward in the history. 154 // the user goes back and forward in the history.
155 window.onhashchange = function(e) { 155 window.onhashchange = function(e) {
156 var id = window.location.hash.slice(1); 156 var id = window.location.hash.slice(1);
157 if (!id) {
158 // If we do not have a hash select first item in the tree.
159 id = tree.items[0].bookmarkId;
160 }
157 161
158 var valid = false; 162 var valid = false;
163 if (/^e=/.test(id)) {
164 var editId = id.slice(2);
Rick Byers 2011/08/04 18:26:07 This 'slice' line is duplicated in 3 places now.
flackr 2011/08/12 18:11:24 Done. In the case of q= the id is not changed.
Rick Byers 2011/08/15 14:59:41 Ah, I missed this subtlety. Thanks for adding com
165 // If hash contains e= edit the item specified.
166 chrome.bookmarks.get(editId, function(bookmarkNodes) {
167 // Verify the node to edit is a valid node.
168 if (!bookmarkNodes || bookmarkNodes.length != 1)
169 return;
170 var bookmarkNode = bookmarkNodes[0];
171 // After the list reloads edit the desired bookmark.
172 var f = function(e) {
Rick Byers 2011/08/04 18:26:07 This add/remove pattern is duplicated often enough
Rick Byers 2011/08/04 18:26:07 Should probably use a variable name more descripti
flackr 2011/08/12 18:11:24 Done.
flackr 2011/08/12 18:11:24 Done.
173 var index;
174 if ((index = list.dataModel.findIndexById(bookmarkNode.id)) != -1) {
175 var sm = list.selectionModel;
176 sm.anchorIndex = sm.leadIndex = sm.selectedIndex = index;
177 scrollIntoViewAndMakeEditable(index);
178 }
179 list.removeEventListener('load', f);
180 }
181 list.addEventListener('load', f);
159 182
160 // In case we got a search hash update the text input and the bmm.treeLookup 183 // Navigate to the parent folder of the node to edit and call function.
Rick Byers 2011/08/04 18:26:07 I find this a little confusing (especially given t
flackr 2011/08/12 18:11:24 Done.
161 // to use the new id. 184 if (list.parentId == bookmarkNode.parentId)
162 if (/^q=/.test(id)) { 185 f();
186 else
187 updateParentId(bookmarkNode.parentId);
188 });
189 // We need more information before we know which folder to navigate to.
Rick Byers 2011/08/04 18:26:07 What is this comment referring to? The delayed ca
flackr 2011/08/12 18:11:24 Done.
190 return;
191 } else if (/^a=/.test(id)) {
192 id = id.slice(2);
193 // After the list reloads add the desired bookmark.
194 var f = function(e) {
195 addPage();
196 list.removeEventListener('load', f);
197 }
arv (Not doing code reviews) 2011/08/11 22:32:22 missing semicolon
flackr 2011/08/12 18:11:24 Done.
198 list.addEventListener('load', f);
199 } else if (/^q=/.test(id)) {
200 // In case we got a search hash update the text input and the
201 // bmm.treeLookup to use the new id.
163 setSearch(id.slice(2)); 202 setSearch(id.slice(2));
164 valid = true; 203 valid = true;
165 } else if (id == 'recent') { 204 } else if (id == 'recent') {
166 valid = true; 205 valid = true;
167 } 206 }
168 207
Rick Byers 2011/08/04 18:26:07 Since this is now non-trivial, add a comment like:
flackr 2011/08/12 18:11:24 Done.
169 if (valid) { 208 if (valid) {
170 updateParentId(id); 209 updateParentId(id);
171 } else { 210 } else {
172 // We need to verify that this is a correct ID. 211 // We need to verify that this is a correct ID.
173 chrome.bookmarks.get(id, function(items) { 212 chrome.bookmarks.get(id, function(items) {
174 if (items && items.length == 1) 213 if (items && items.length == 1)
175 updateParentId(id); 214 updateParentId(id);
176 }); 215 });
177 } 216 }
178 }; 217 };
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 if (parentNode.parentId != ROOT_ID) { 379 if (parentNode.parentId != ROOT_ID) {
341 return getFolder(parentNode.parentId) + '/' + s; 380 return getFolder(parentNode.parentId) + '/' + s;
342 } 381 }
343 return s; 382 return s;
344 } 383 }
345 } 384 }
346 385
347 tree.addEventListener('load', function(e) { 386 tree.addEventListener('load', function(e) {
348 // Add hard coded tree items 387 // Add hard coded tree items
349 tree.add(recentTreeItem); 388 tree.add(recentTreeItem);
350 389 // Call onhashchange to navigate to hash location.
351 // Now we can select a tree item. 390 window.onhashchange();
Rick Byers 2011/08/04 18:26:07 Technically I'd consider it invalid to call this e
arv (Not doing code reviews) 2011/08/11 22:32:22 Yeah, don't do this. Just do what Rick suggested.
flackr 2011/08/12 18:11:24 Done.
352 var hash = window.location.hash.slice(1);
353 if (!hash) {
354 // If we do not have a hash select first item in the tree.
355 hash = tree.items[0].bookmarkId;
356 }
357
358 if (/^q=/.test(hash)) {
359 var searchTerm = hash.slice(2);
360 $('term').value = searchTerm;
361 setSearch(searchTerm);
362 } else {
363 navigateTo(hash);
364 }
365 }); 391 });
366 392
367 tree.reload(); 393 tree.reload();
368 addBookmarkModelListeners(); 394 addBookmarkModelListeners();
369 395
370 var dnd = { 396 var dnd = {
371 dragData: null, 397 dragData: null,
372 398
373 getBookmarkElement: function(el) { 399 getBookmarkElement: function(el) {
374 while (el && !el.bookmarkNode) { 400 while (el && !el.bookmarkNode) {
(...skipping 1238 matching lines...) Expand 10 before | Expand all | Expand 10 after
1613 document.addEventListener('copy', handle('copy-command')); 1639 document.addEventListener('copy', handle('copy-command'));
1614 document.addEventListener('cut', handle('cut-command')); 1640 document.addEventListener('cut', handle('cut-command'));
1615 1641
1616 var pasteHandler = handle('paste-command'); 1642 var pasteHandler = handle('paste-command');
1617 document.addEventListener('paste', function(e) { 1643 document.addEventListener('paste', function(e) {
1618 // Paste is a bit special since we need to do an async call to see if we can 1644 // Paste is a bit special since we need to do an async call to see if we can
1619 // paste because the paste command might not be up to date. 1645 // paste because the paste command might not be up to date.
1620 updatePasteCommand(pasteHandler); 1646 updatePasteCommand(pasteHandler);
1621 }); 1647 });
1622 })(); 1648 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698