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

Side by Side Diff: chrome/browser/resources/md_downloads/crisper.js

Issue 2337513002: Only handle click actions for left & middle buttons (Closed)
Patch Set: vulanize the resources Created 4 years, 3 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 function assert(condition, opt_message) { 4 function assert(condition, opt_message) {
5 if (!condition) { 5 if (!condition) {
6 var message = 'Assertion failed'; 6 var message = 'Assertion failed';
7 if (opt_message) message = message + ': ' + opt_message; 7 if (opt_message) message = message + ': ' + opt_message;
8 var error = new Error(message); 8 var error = new Error(message);
9 var global = function() { 9 var global = function() {
10 return this; 10 return this;
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 return assertInstanceof($(id), HTMLElement, 'Missing required element: ' + id) ; 641 return assertInstanceof($(id), HTMLElement, 'Missing required element: ' + id) ;
642 } 642 }
643 643
644 function queryRequiredElement(selectors, opt_context) { 644 function queryRequiredElement(selectors, opt_context) {
645 var element = (opt_context || document).querySelector(selectors); 645 var element = (opt_context || document).querySelector(selectors);
646 return assertInstanceof(element, HTMLElement, 'Missing required element: ' + s electors); 646 return assertInstanceof(element, HTMLElement, 'Missing required element: ' + s electors);
647 } 647 }
648 648
649 [ 'click', 'auxclick' ].forEach(function(eventName) { 649 [ 'click', 'auxclick' ].forEach(function(eventName) {
650 document.addEventListener(eventName, function(e) { 650 document.addEventListener(eventName, function(e) {
651 if (e.button > 1) return;
651 if (e.defaultPrevented) return; 652 if (e.defaultPrevented) return;
652 var eventPath = e.path; 653 var eventPath = e.path;
653 var anchor = null; 654 var anchor = null;
654 if (eventPath) { 655 if (eventPath) {
655 for (var i = 0; i < eventPath.length; i++) { 656 for (var i = 0; i < eventPath.length; i++) {
656 var element = eventPath[i]; 657 var element = eventPath[i];
657 if (element.tagName === 'A' && element.href) { 658 if (element.tagName === 'A' && element.href) {
658 anchor = element; 659 anchor = element;
659 break; 660 break;
660 } 661 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 727
727 function elide(original, maxLength) { 728 function elide(original, maxLength) {
728 if (original.length <= maxLength) return original; 729 if (original.length <= maxLength) return original;
729 return original.substring(0, maxLength - 1) + '…'; 730 return original.substring(0, maxLength - 1) + '…';
730 } 731 }
731 732
732 function quoteString(str) { 733 function quoteString(str) {
733 return str.replace(/([\\\.\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:])/g, '\\$1'); 734 return str.replace(/([\\\.\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:])/g, '\\$1');
734 } 735 }
735 736
737 function listenOnce(target, eventNames, callback) {
738 if (!Array.isArray(eventNames)) eventNames = eventNames.split(/ +/);
739 var removeAllAndCallCallback = function(event) {
740 eventNames.forEach(function(eventName) {
741 target.removeEventListener(eventName, removeAllAndCallCallback, false);
742 });
743 return callback(event);
744 };
745 eventNames.forEach(function(eventName) {
746 target.addEventListener(eventName, removeAllAndCallCallback, false);
747 });
748 }
749
736 // <if expr="is_ios"> 750 // <if expr="is_ios">
737 if (!('key' in KeyboardEvent.prototype)) { 751 if (!('key' in KeyboardEvent.prototype)) {
738 Object.defineProperty(KeyboardEvent.prototype, 'key', { 752 Object.defineProperty(KeyboardEvent.prototype, 'key', {
739 get: function() { 753 get: function() {
740 if (this.keyCode >= 48 && this.keyCode <= 57) return String.fromCharCode(t his.keyCode); 754 if (this.keyCode >= 48 && this.keyCode <= 57) return String.fromCharCode(t his.keyCode);
741 if (this.keyCode >= 65 && this.keyCode <= 90) { 755 if (this.keyCode >= 65 && this.keyCode <= 90) {
742 var result = String.fromCharCode(this.keyCode).toLowerCase(); 756 var result = String.fromCharCode(this.keyCode).toLowerCase();
743 if (this.shiftKey) result = result.toUpperCase(); 757 if (this.shiftKey) result = result.toUpperCase();
744 return result; 758 return result;
745 } 759 }
(...skipping 6211 matching lines...) Expand 10 before | Expand all | Expand 10 after
6957 }; 6971 };
6958 return { 6972 return {
6959 Manager: Manager 6973 Manager: Manager
6960 }; 6974 };
6961 }); 6975 });
6962 6976
6963 // Copyright 2015 The Chromium Authors. All rights reserved. 6977 // Copyright 2015 The Chromium Authors. All rights reserved.
6964 // Use of this source code is governed by a BSD-style license that can be 6978 // Use of this source code is governed by a BSD-style license that can be
6965 // found in the LICENSE file. 6979 // found in the LICENSE file.
6966 window.addEventListener('load', downloads.Manager.onLoad); 6980 window.addEventListener('load', downloads.Manager.onLoad);
OLDNEW
« no previous file with comments | « chrome/browser/resources/history/other_devices.js ('k') | chrome/browser/resources/ntp4/new_tab.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698