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

Side by Side Diff: chrome/browser/resources/downloads/downloads.js

Issue 668983004: Add <a is="action-link">, a web component extension of <a> for in-page actions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixes Created 6 years, 2 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
OLDNEW
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 // TODO(jhawkins): Use hidden instead of showInline* and display:none. 5 // TODO(jhawkins): Use hidden instead of showInline* and display:none.
6 6
7 /** 7 /**
8 * The type of the download object. The definition is based on 8 * The type of the download object. The definition is based on
9 * chrome/browser/ui/webui/downloads_dom_handler.cc:CreateDownloadItemValue() 9 * chrome/browser/ui/webui/downloads_dom_handler.cc:CreateDownloadItemValue()
10 * @typedef {{by_ext_id: (string|undefined), 10 * @typedef {{by_ext_id: (string|undefined),
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 * @param {!Element} node The target element to show or hide. 45 * @param {!Element} node The target element to show or hide.
46 * @param {boolean} isShow Should the target element be visible. 46 * @param {boolean} isShow Should the target element be visible.
47 */ 47 */
48 function showInlineBlock(node, isShow) { 48 function showInlineBlock(node, isShow) {
49 node.style.display = isShow ? 'inline-block' : 'none'; 49 node.style.display = isShow ? 'inline-block' : 'none';
50 } 50 }
51 51
52 /** 52 /**
53 * Creates a link with a specified onclick handler and content. 53 * Creates a link with a specified onclick handler and content.
54 * @param {function()} onclick The onclick handler. 54 * @param {function()} onclick The onclick handler.
55 * @param {string} value The link text. 55 * @param {string=} opt_text The link text.
56 * @return {!Element} The created link element. 56 * @return {!Element} The created link element.
57 */ 57 */
58 function createLink(onclick, value) { 58 function createLink(onclick, opt_text) {
aboxhall 2014/10/22 21:33:31 Perhaps this should be renamed createActionLink, t
Dan Beam 2014/10/23 03:05:44 Done.
59 var link = document.createElement('a'); 59 var link = document.createElement('a', 'action-link');
60 link.onclick = onclick; 60 link.onclick = onclick;
61 link.href = '#'; 61 if (opt_text) link.textContent = opt_text;
62 link.textContent = value;
63 link.oncontextmenu = function() { return false; };
64 return link; 62 return link;
65 } 63 }
66 64
67 /** 65 /**
68 * Creates a button with a specified onclick handler and content. 66 * Creates a button with a specified onclick handler and content.
69 * @param {function()} onclick The onclick handler. 67 * @param {function()} onclick The onclick handler.
70 * @param {string} value The button text. 68 * @param {string} value The button text.
71 * @return {Element} The created button. 69 * @return {Element} The created button.
72 */ 70 */
73 function createButton(onclick, value) { 71 function createButton(onclick, value) {
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 } 321 }
324 322
325 this.nodeImg_ = createElementWithClassName('img', 'icon'); 323 this.nodeImg_ = createElementWithClassName('img', 'icon');
326 this.nodeImg_.alt = ''; 324 this.nodeImg_.alt = '';
327 this.safe_.appendChild(this.nodeImg_); 325 this.safe_.appendChild(this.nodeImg_);
328 326
329 // FileLink is used for completed downloads, otherwise we show FileName. 327 // FileLink is used for completed downloads, otherwise we show FileName.
330 this.nodeTitleArea_ = createElementWithClassName('div', 'title-area'); 328 this.nodeTitleArea_ = createElementWithClassName('div', 'title-area');
331 this.safe_.appendChild(this.nodeTitleArea_); 329 this.safe_.appendChild(this.nodeTitleArea_);
332 330
333 this.nodeFileLink_ = createLink(this.openFile_.bind(this), ''); 331 this.nodeFileLink_ = createLink(this.openFile_.bind(this));
334 this.nodeFileLink_.className = 'name'; 332 this.nodeFileLink_.className = 'name';
335 this.nodeFileLink_.style.display = 'none'; 333 this.nodeFileLink_.style.display = 'none';
336 this.nodeTitleArea_.appendChild(this.nodeFileLink_); 334 this.nodeTitleArea_.appendChild(this.nodeFileLink_);
337 335
338 this.nodeFileName_ = createElementWithClassName('span', 'name'); 336 this.nodeFileName_ = createElementWithClassName('span', 'name');
339 this.nodeFileName_.style.display = 'none'; 337 this.nodeFileName_.style.display = 'none';
340 this.nodeTitleArea_.appendChild(this.nodeFileName_); 338 this.nodeTitleArea_.appendChild(this.nodeFileName_);
341 339
342 this.nodeStatus_ = createElementWithClassName('span', 'status'); 340 this.nodeStatus_ = createElementWithClassName('span', 'status');
343 this.nodeTitleArea_.appendChild(this.nodeStatus_); 341 this.nodeTitleArea_.appendChild(this.nodeStatus_);
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 clearAllHolder.classList.remove('disabled-link'); 887 clearAllHolder.classList.remove('disabled-link');
890 } else { 888 } else {
891 clearAllElement = document.createTextNode( 889 clearAllElement = document.createTextNode(
892 loadTimeData.getString('clear_all')); 890 loadTimeData.getString('clear_all'));
893 clearAllHolder.classList.add('disabled-link'); 891 clearAllHolder.classList.add('disabled-link');
894 } 892 }
895 if (!loadTimeData.getBoolean('show_delete_history')) 893 if (!loadTimeData.getBoolean('show_delete_history'))
896 clearAllHolder.hidden = true; 894 clearAllHolder.hidden = true;
897 895
898 clearAllHolder.appendChild(clearAllElement); 896 clearAllHolder.appendChild(clearAllElement);
899 clearAllElement.oncontextmenu = function() { return false; };
900 897
901 // TODO(jhawkins): Use a link-button here. 898 $('open-downloads-folder').onclick = function() {
902 var openDownloadsFolderLink = $('open-downloads-folder');
903 openDownloadsFolderLink.onclick = function() {
904 chrome.send('openDownloadsFolder'); 899 chrome.send('openDownloadsFolder');
905 }; 900 };
906 openDownloadsFolderLink.oncontextmenu = function() { return false; };
907 901
908 $('term').onsearch = function(e) { 902 $('term').onsearch = function(e) {
909 setSearch($('term').value); 903 setSearch($('term').value);
910 }; 904 };
911 } 905 }
912 906
913 function setSearch(searchText) { 907 function setSearch(searchText) {
914 fifoResults.length = 0; 908 fifoResults.length = 0;
915 downloads.setSearchText(searchText); 909 downloads.setSearchText(searchText);
916 searchText = searchText.toString().match(/(?:[^\s"]+|"[^"]*")+/g); 910 searchText = searchText.toString().match(/(?:[^\s"]+|"[^"]*")+/g);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
982 if (Date.now() - start > 50) { 976 if (Date.now() - start > 50) {
983 clearTimeout(resultsTimeout); 977 clearTimeout(resultsTimeout);
984 resultsTimeout = setTimeout(tryDownloadUpdatedPeriodically, 5); 978 resultsTimeout = setTimeout(tryDownloadUpdatedPeriodically, 5);
985 break; 979 break;
986 } 980 }
987 } 981 }
988 } 982 }
989 983
990 // Add handlers to HTML elements. 984 // Add handlers to HTML elements.
991 window.addEventListener('DOMContentLoaded', load); 985 window.addEventListener('DOMContentLoaded', load);
992
993 preventDefaultOnPoundLinkClicks(); // From util.js.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698