OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 // Action links are elements that are used to perform an in-page navigation or | 5 // Action links are elements that are used to perform an in-page navigation or |
6 // action (e.g. showing a dialog). | 6 // action (e.g. showing a dialog). |
7 // | 7 // |
8 // They look like normal anchor (<a>) tags as their text color is blue. However, | 8 // They look like normal anchor (<a>) tags as their text color is blue. However, |
9 // they're subtly different as they're not initially underlined (giving users a | 9 // they're subtly different as they're not initially underlined (giving users a |
10 // clue that underlined links navigate while action links don't). | 10 // clue that underlined links navigate while action links don't). |
(...skipping 26 matching lines...) Expand all Loading... |
37 | 37 |
38 /** @this {ActionLink} */ | 38 /** @this {ActionLink} */ |
39 createdCallback: function() { | 39 createdCallback: function() { |
40 // Action links can start disabled (e.g. <a is="action-link" disabled>). | 40 // Action links can start disabled (e.g. <a is="action-link" disabled>). |
41 this.tabIndex = this.disabled ? -1 : 0; | 41 this.tabIndex = this.disabled ? -1 : 0; |
42 | 42 |
43 if (!this.hasAttribute('role')) | 43 if (!this.hasAttribute('role')) |
44 this.setAttribute('role', 'link'); | 44 this.setAttribute('role', 'link'); |
45 | 45 |
46 this.addEventListener('keydown', function(e) { | 46 this.addEventListener('keydown', function(e) { |
47 if (!this.disabled && e.keyIdentifier == 'Enter' && !this.href) { | 47 if (!this.disabled && e.key == 'Enter' && !this.href) { |
48 // Schedule a click asynchronously because other 'keydown' handlers | 48 // Schedule a click asynchronously because other 'keydown' handlers |
49 // may still run later (e.g. document.addEventListener('keydown')). | 49 // may still run later (e.g. document.addEventListener('keydown')). |
50 // Specifically options dialogs break when this timeout isn't here. | 50 // Specifically options dialogs break when this timeout isn't here. |
51 // NOTE: this affects the "trusted" state of the ensuing click. I | 51 // NOTE: this affects the "trusted" state of the ensuing click. I |
52 // haven't found anything that breaks because of this (yet). | 52 // haven't found anything that breaks because of this (yet). |
53 window.setTimeout(this.click.bind(this), 0); | 53 window.setTimeout(this.click.bind(this), 0); |
54 } | 54 } |
55 }); | 55 }); |
56 | 56 |
57 function preventDefault(e) { | 57 function preventDefault(e) { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 removeAttribute: function(attr) { | 104 removeAttribute: function(attr) { |
105 if (attr.toLowerCase() == 'disabled') | 105 if (attr.toLowerCase() == 'disabled') |
106 this.disabled = false; | 106 this.disabled = false; |
107 else | 107 else |
108 HTMLAnchorElement.prototype.removeAttribute.apply(this, arguments); | 108 HTMLAnchorElement.prototype.removeAttribute.apply(this, arguments); |
109 }, | 109 }, |
110 }, | 110 }, |
111 | 111 |
112 extends: 'a', | 112 extends: 'a', |
113 }); | 113 }); |
OLD | NEW |