| OLD | NEW |
| (Empty) | |
| 1 <!-- |
| 2 @license |
| 3 Copyright (c) 2017 The Polymer Project Authors. All rights reserved. |
| 4 This code may only be used under the BSD style license found at http://polymer.g
ithub.io/LICENSE.txt |
| 5 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt |
| 6 The complete set of contributors may be found at http://polymer.github.io/CONTRI
BUTORS.txt |
| 7 Code distributed by Google as part of the polymer project is also |
| 8 subject to an additional IP rights grant found at http://polymer.github.io/PATEN
TS.txt |
| 9 --> |
| 10 <link rel="import" href="boot.html"> |
| 11 |
| 12 <script> |
| 13 |
| 14 (function() { |
| 15 'use strict'; |
| 16 |
| 17 let CSS_URL_RX = /(url\()([^)]*)(\))/g; |
| 18 let ABS_URL = /(^\/)|(^#)|(^[\w-\d]*:)/; |
| 19 let workingURL; |
| 20 let resolveDoc; |
| 21 /** |
| 22 * Resolves the given URL against the provided `baseUri'. |
| 23 * |
| 24 * @memberof Polymer.ResolveUrl |
| 25 * @param {string} url Input URL to resolve |
| 26 * @param {string} baseURI Base URI to resolve the URL against |
| 27 * @return {string} resolved URL |
| 28 */ |
| 29 function resolveUrl(url, baseURI) { |
| 30 if (url && ABS_URL.test(url)) { |
| 31 return url; |
| 32 } |
| 33 // Lazy feature detection. |
| 34 if (workingURL === undefined) { |
| 35 workingURL = false; |
| 36 try { |
| 37 const u = new URL('b', 'http://a'); |
| 38 u.pathname = 'c%20d'; |
| 39 workingURL = (u.href === 'http://a/c%20d'); |
| 40 } catch (e) { |
| 41 // silently fail |
| 42 } |
| 43 } |
| 44 if (!baseURI) { |
| 45 baseURI = document.baseURI || window.location.href; |
| 46 } |
| 47 if (workingURL) { |
| 48 return (new URL(url, baseURI)).href; |
| 49 } |
| 50 // Fallback to creating an anchor into a disconnected document. |
| 51 if (!resolveDoc) { |
| 52 resolveDoc = document.implementation.createHTMLDocument('temp'); |
| 53 resolveDoc.base = resolveDoc.createElement('base'); |
| 54 resolveDoc.head.appendChild(resolveDoc.base); |
| 55 resolveDoc.anchor = resolveDoc.createElement('a'); |
| 56 resolveDoc.body.appendChild(resolveDoc.anchor); |
| 57 } |
| 58 resolveDoc.base.href = baseURI; |
| 59 resolveDoc.anchor.href = url; |
| 60 return resolveDoc.anchor.href || url; |
| 61 |
| 62 } |
| 63 |
| 64 /** |
| 65 * Resolves any relative URL's in the given CSS text against the provided |
| 66 * `ownerDocument`'s `baseURI`. |
| 67 * |
| 68 * @memberof Polymer.ResolveUrl |
| 69 * @param {string} cssText CSS text to process |
| 70 * @param {string} baseURI Base URI to resolve the URL against |
| 71 * @return {string} Processed CSS text with resolved URL's |
| 72 */ |
| 73 function resolveCss(cssText, baseURI) { |
| 74 return cssText.replace(CSS_URL_RX, function(m, pre, url, post) { |
| 75 return pre + '\'' + |
| 76 resolveUrl(url.replace(/["']/g, ''), baseURI) + |
| 77 '\'' + post; |
| 78 }); |
| 79 } |
| 80 |
| 81 /** |
| 82 * Returns a path from a given `url`. The path includes the trailing |
| 83 * `/` from the url. |
| 84 * |
| 85 * @memberof Polymer.ResolveUrl |
| 86 * @param {string} url Input URL to transform |
| 87 * @return {string} resolved path |
| 88 */ |
| 89 function pathFromUrl(url) { |
| 90 return url.substring(0, url.lastIndexOf('/') + 1); |
| 91 } |
| 92 |
| 93 /** |
| 94 * Module with utilities for resolving relative URL's. |
| 95 * |
| 96 * @namespace |
| 97 * @memberof Polymer |
| 98 * @summary Module with utilities for resolving relative URL's. |
| 99 */ |
| 100 Polymer.ResolveUrl = { |
| 101 resolveCss: resolveCss, |
| 102 resolveUrl: resolveUrl, |
| 103 pathFromUrl: pathFromUrl |
| 104 }; |
| 105 |
| 106 })(); |
| 107 |
| 108 </script> |
| OLD | NEW |