| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Action links are elements that are used to perform an in-page navigation or |
| 6 // action (e.g. showing a dialog). |
| 7 // |
| 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 |
| 10 // clue that underlined links navigate while action links don't). |
| 11 // |
| 12 // Action links look very similar to normal links when hovered (hand cursor, |
| 13 // underlined). This gives the user an idea that clicking this link will do |
| 14 // something similar to navigation but in the same page. |
| 15 // |
| 16 // They can be created in JavaScript like this: |
| 17 // |
| 18 // var link = document.createElement('a', 'action-link'); // Note second arg. |
| 19 // |
| 20 // or with a constructor like this: |
| 21 // |
| 22 // var link = new ActionLink(); |
| 23 // |
| 24 // They can be used easily from HTML as well, like so: |
| 25 // |
| 26 // <a is="action-link">Click me!</a> |
| 27 // |
| 28 // Using the <action-link> tag or document.createElement('action-link') is not |
| 29 // currently supported and is not the preferred way of extending tags. |
| 30 |
| 31 /** |
| 32 * @constructor |
| 33 * @extends {HTMLAnchorElement} |
| 34 */ |
| 35 var ActionLink = document.registerElement('action-link', { |
| 36 prototype: { |
| 37 __proto__: HTMLAnchorElement.prototype, |
| 38 |
| 39 createdCallback: function() { |
| 40 if (this.tagName == 'action-link') |
| 41 throw 'Use <a is="action-link"> instead of <action-link>'; |
| 42 |
| 43 // Links aren't tabble unless there's an [href] attribute set. Setting |
| 44 // this adds undesirable "Open link in new tab..." context menu handlers |
| 45 // so just manually add to tab order instead. |
| 46 this.tabIndex = 0; |
| 47 |
| 48 this.addEventListener('click', function(e) { |
| 49 e.preventDefault(); |
| 50 }); |
| 51 |
| 52 this.addEventListener('keydown', function(e) { |
| 53 if (e.keyIdentifier == 'Enter') { |
| 54 e.preventDefault(); |
| 55 e.stopPropagation(); |
| 56 this.click(); |
| 57 } |
| 58 }); |
| 59 }, |
| 60 }, |
| 61 extends: 'a', |
| 62 }); |
| OLD | NEW |