UNPKG

api-console-assets

Version:

This repo only exists to publish api console components to npm

101 lines (93 loc) 2.93 kB
<!-- @license Copyright 2016 The Advanced REST client authors <arc@mulesoft.com> Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <link rel="import" href="../polymer/polymer.html"> <!-- An element that will display a header list value as a link. Regular data binding in Polymer is using innerText setter to assign the value. Thus any HTML tag won't be recognized and displayed as text. This element will find links in the header value and display it as a link if necessary. Parent elements may catch link action and prohibit from navigation and use the link value somehow. To catch autogenerated link check class name on an event target. It should contain `auto-link` CSS class name. ### Styling `<headers-list-view>` provides the following custom properties and mixins for styling: Custom property | Description | Default ----------------|-------------|---------- `--headers-list-item-value` | Mixin applied to the element | `{}` `--arc-link` | Mixin applied to autogenerated link | `{}` @group UI Elements @element headers-list-item-value --> <dom-module id="headers-list-item-value"> <template> <style> :host { display: inline; font-family: inherit; font-size: inherit; @apply(--headers-list-item-value); } .auto-link { @apply(--arc-link); } </style> <span id="display"></span> </template> </dom-module> <script> Polymer({ is: 'headers-list-item-value', properties: { /** * Header value to display */ value: { type: String, observer: '_valueChanged' } }, _valueChanged: function() { var value = this.value; if (!value) { this.$.display.innerHTML = ''; return; } this.$.display.innerHTML = this._autoLink(value); }, // Finds URLs in input string and adds anchors tags. _autoLink: function(input) { if (typeof input !== 'string') { return input; } var r = new RegExp('(https?:\\/\\/([^" >]*))', 'gim'); var matches = input.match(r); input = input.replace(/</g, '&lt;').replace(/>/g, '&gt;'); if (!matches) { return input; } var index = input.indexOf(matches[0]); var result = input.substr(0, index); result += '<a target="_blank" class="auto-link" href="'; result += matches[0]; result += '">'; result += matches[0]; result += '</a>'; index += matches[0].length; result += input.substr(index); return result; } }); </script>