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

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: merge 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 createActionLink(onclick, opt_text) {
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_ = createActionLink(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_);
344 342
345 var nodeURLDiv = createElementWithClassName('div', 'url-container'); 343 var nodeURLDiv = createElementWithClassName('div', 'url-container');
346 this.safe_.appendChild(nodeURLDiv); 344 this.safe_.appendChild(nodeURLDiv);
347 345
348 this.nodeURL_ = createElementWithClassName('a', 'src-url'); 346 this.nodeURL_ = createElementWithClassName('a', 'src-url');
349 this.nodeURL_.target = '_blank'; 347 this.nodeURL_.target = '_blank';
350 nodeURLDiv.appendChild(this.nodeURL_); 348 nodeURLDiv.appendChild(this.nodeURL_);
351 349
352 // Controls. 350 // Controls.
353 this.nodeControls_ = createElementWithClassName('div', 'controls'); 351 this.nodeControls_ = createElementWithClassName('div', 'controls');
354 this.safe_.appendChild(this.nodeControls_); 352 this.safe_.appendChild(this.nodeControls_);
355 353
356 // We don't need 'show in folder' in chromium os. See download_ui.cc and 354 // We don't need 'show in folder' in chromium os. See download_ui.cc and
357 // http://code.google.com/p/chromium-os/issues/detail?id=916. 355 // http://code.google.com/p/chromium-os/issues/detail?id=916.
358 if (loadTimeData.valueExists('control_showinfolder')) { 356 if (loadTimeData.valueExists('control_showinfolder')) {
359 this.controlShow_ = createLink(this.show_.bind(this), 357 this.controlShow_ = createActionLink(this.show_.bind(this),
360 loadTimeData.getString('control_showinfolder')); 358 loadTimeData.getString('control_showinfolder'));
361 this.nodeControls_.appendChild(this.controlShow_); 359 this.nodeControls_.appendChild(this.controlShow_);
362 } else { 360 } else {
363 this.controlShow_ = null; 361 this.controlShow_ = null;
364 } 362 }
365 363
366 this.controlRetry_ = document.createElement('a'); 364 this.controlRetry_ = document.createElement('a');
367 this.controlRetry_.download = ''; 365 this.controlRetry_.download = '';
368 this.controlRetry_.textContent = loadTimeData.getString('control_retry'); 366 this.controlRetry_.textContent = loadTimeData.getString('control_retry');
369 this.nodeControls_.appendChild(this.controlRetry_); 367 this.nodeControls_.appendChild(this.controlRetry_);
370 368
371 // Pause/Resume are a toggle. 369 // Pause/Resume are a toggle.
372 this.controlPause_ = createLink(this.pause_.bind(this), 370 this.controlPause_ = createActionLink(this.pause_.bind(this),
373 loadTimeData.getString('control_pause')); 371 loadTimeData.getString('control_pause'));
374 this.nodeControls_.appendChild(this.controlPause_); 372 this.nodeControls_.appendChild(this.controlPause_);
375 373
376 this.controlResume_ = createLink(this.resume_.bind(this), 374 this.controlResume_ = createActionLink(this.resume_.bind(this),
377 loadTimeData.getString('control_resume')); 375 loadTimeData.getString('control_resume'));
378 this.nodeControls_.appendChild(this.controlResume_); 376 this.nodeControls_.appendChild(this.controlResume_);
379 377
380 // Anchors <a> don't support the "disabled" property. 378 // Anchors <a> don't support the "disabled" property.
381 if (loadTimeData.getBoolean('allow_deleting_history')) { 379 if (loadTimeData.getBoolean('allow_deleting_history')) {
382 this.controlRemove_ = createLink(this.remove_.bind(this), 380 this.controlRemove_ = createActionLink(this.remove_.bind(this),
383 loadTimeData.getString('control_removefromlist')); 381 loadTimeData.getString('control_removefromlist'));
384 this.controlRemove_.classList.add('control-remove-link'); 382 this.controlRemove_.classList.add('control-remove-link');
385 } else { 383 } else {
386 this.controlRemove_ = document.createElement('span'); 384 this.controlRemove_ = document.createElement('span');
387 this.controlRemove_.classList.add('disabled-link'); 385 this.controlRemove_.classList.add('disabled-link');
388 var text = document.createTextNode( 386 var text = document.createTextNode(
389 loadTimeData.getString('control_removefromlist')); 387 loadTimeData.getString('control_removefromlist'));
390 this.controlRemove_.appendChild(text); 388 this.controlRemove_.appendChild(text);
391 } 389 }
392 if (!loadTimeData.getBoolean('show_delete_history')) 390 if (!loadTimeData.getBoolean('show_delete_history'))
393 this.controlRemove_.hidden = true; 391 this.controlRemove_.hidden = true;
394 392
395 this.nodeControls_.appendChild(this.controlRemove_); 393 this.nodeControls_.appendChild(this.controlRemove_);
396 394
397 this.controlCancel_ = createLink(this.cancel_.bind(this), 395 this.controlCancel_ = createActionLink(this.cancel_.bind(this),
398 loadTimeData.getString('control_cancel')); 396 loadTimeData.getString('control_cancel'));
399 this.nodeControls_.appendChild(this.controlCancel_); 397 this.nodeControls_.appendChild(this.controlCancel_);
400 398
401 this.controlByExtension_ = document.createElement('span'); 399 this.controlByExtension_ = document.createElement('span');
402 this.nodeControls_.appendChild(this.controlByExtension_); 400 this.nodeControls_.appendChild(this.controlByExtension_);
403 401
404 // Container for 'unsafe download' UI. 402 // Container for 'unsafe download' UI.
405 this.danger_ = createElementWithClassName('div', 'show-dangerous'); 403 this.danger_ = createElementWithClassName('div', 'show-dangerous');
406 this.node.appendChild(this.danger_); 404 this.node.appendChild(this.danger_);
407 405
408 this.dangerNodeImg_ = createElementWithClassName('img', 'icon'); 406 this.dangerNodeImg_ = createElementWithClassName('img', 'icon');
409 this.dangerNodeImg_.alt = ''; 407 this.dangerNodeImg_.alt = '';
410 this.danger_.appendChild(this.dangerNodeImg_); 408 this.danger_.appendChild(this.dangerNodeImg_);
411 409
412 this.dangerDesc_ = document.createElement('div'); 410 this.dangerDesc_ = document.createElement('div');
413 this.danger_.appendChild(this.dangerDesc_); 411 this.danger_.appendChild(this.dangerDesc_);
414 412
415 // Buttons for the malicious case. 413 // Buttons for the malicious case.
416 this.malwareNodeControls_ = createElementWithClassName('div', 'controls'); 414 this.malwareNodeControls_ = createElementWithClassName('div', 'controls');
417 this.malwareSave_ = createLink( 415 this.malwareSave_ = createActionLink(
418 this.saveDangerous_.bind(this), 416 this.saveDangerous_.bind(this),
419 loadTimeData.getString('danger_restore')); 417 loadTimeData.getString('danger_restore'));
420 this.malwareNodeControls_.appendChild(this.malwareSave_); 418 this.malwareNodeControls_.appendChild(this.malwareSave_);
421 this.malwareDiscard_ = createLink( 419 this.malwareDiscard_ = createActionLink(
422 this.discardDangerous_.bind(this), 420 this.discardDangerous_.bind(this),
423 loadTimeData.getString('control_removefromlist')); 421 loadTimeData.getString('control_removefromlist'));
424 this.malwareNodeControls_.appendChild(this.malwareDiscard_); 422 this.malwareNodeControls_.appendChild(this.malwareDiscard_);
425 this.danger_.appendChild(this.malwareNodeControls_); 423 this.danger_.appendChild(this.malwareNodeControls_);
426 424
427 // Buttons for the dangerous but not malicious case. 425 // Buttons for the dangerous but not malicious case.
428 this.dangerSave_ = createButton( 426 this.dangerSave_ = createButton(
429 this.saveDangerous_.bind(this), 427 this.saveDangerous_.bind(this),
430 loadTimeData.getString('danger_save')); 428 loadTimeData.getString('danger_save'));
431 this.danger_.appendChild(this.dangerSave_); 429 this.danger_.appendChild(this.dangerSave_);
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after
877 function load() { 875 function load() {
878 chrome.send('onPageLoaded'); 876 chrome.send('onPageLoaded');
879 fifoResults = []; 877 fifoResults = [];
880 downloads = new Downloads(); 878 downloads = new Downloads();
881 $('term').focus(); 879 $('term').focus();
882 setSearch(''); 880 setSearch('');
883 881
884 var clearAllHolder = $('clear-all-holder'); 882 var clearAllHolder = $('clear-all-holder');
885 var clearAllElement; 883 var clearAllElement;
886 if (loadTimeData.getBoolean('allow_deleting_history')) { 884 if (loadTimeData.getBoolean('allow_deleting_history')) {
887 clearAllElement = createLink(clearAll, loadTimeData.getString('clear_all')); 885 clearAllElement = createActionLink(
886 clearAll, loadTimeData.getString('clear_all'));
888 clearAllElement.classList.add('clear-all-link'); 887 clearAllElement.classList.add('clear-all-link');
889 clearAllHolder.classList.remove('disabled-link'); 888 clearAllHolder.classList.remove('disabled-link');
890 } else { 889 } else {
891 clearAllElement = document.createTextNode( 890 clearAllElement = document.createTextNode(
892 loadTimeData.getString('clear_all')); 891 loadTimeData.getString('clear_all'));
893 clearAllHolder.classList.add('disabled-link'); 892 clearAllHolder.classList.add('disabled-link');
894 } 893 }
895 if (!loadTimeData.getBoolean('show_delete_history')) 894 if (!loadTimeData.getBoolean('show_delete_history'))
896 clearAllHolder.hidden = true; 895 clearAllHolder.hidden = true;
897 896
898 clearAllHolder.appendChild(clearAllElement); 897 clearAllHolder.appendChild(clearAllElement);
899 clearAllElement.oncontextmenu = function() { return false; };
900 898
901 // TODO(jhawkins): Use a link-button here. 899 $('open-downloads-folder').onclick = function() {
902 var openDownloadsFolderLink = $('open-downloads-folder');
903 openDownloadsFolderLink.onclick = function() {
904 chrome.send('openDownloadsFolder'); 900 chrome.send('openDownloadsFolder');
905 }; 901 };
906 openDownloadsFolderLink.oncontextmenu = function() { return false; };
907 902
908 $('term').onsearch = function(e) { 903 $('term').onsearch = function(e) {
909 setSearch($('term').value); 904 setSearch($('term').value);
910 }; 905 };
911 } 906 }
912 907
913 function setSearch(searchText) { 908 function setSearch(searchText) {
914 fifoResults.length = 0; 909 fifoResults.length = 0;
915 downloads.setSearchText(searchText); 910 downloads.setSearchText(searchText);
916 searchText = searchText.toString().match(/(?:[^\s"]+|"[^"]*")+/g); 911 searchText = searchText.toString().match(/(?:[^\s"]+|"[^"]*")+/g);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
982 if (Date.now() - start > 50) { 977 if (Date.now() - start > 50) {
983 clearTimeout(resultsTimeout); 978 clearTimeout(resultsTimeout);
984 resultsTimeout = setTimeout(tryDownloadUpdatedPeriodically, 5); 979 resultsTimeout = setTimeout(tryDownloadUpdatedPeriodically, 5);
985 break; 980 break;
986 } 981 }
987 } 982 }
988 } 983 }
989 984
990 // Add handlers to HTML elements. 985 // Add handlers to HTML elements.
991 window.addEventListener('DOMContentLoaded', load); 986 window.addEventListener('DOMContentLoaded', load);
992
993 preventDefaultOnPoundLinkClicks(); // From util.js.
OLDNEW
« no previous file with comments | « chrome/browser/resources/downloads/downloads.html ('k') | chrome/browser/resources/extensions/extension_error.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698