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

Unified Diff: third_party/polymer/v0_8/components-chromium/polymer/src/lib/resolve-url-extracted.js

Issue 1082403004: Import Polymer 0.8 and several key elements. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Also remove polymer/explainer Created 5 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: third_party/polymer/v0_8/components-chromium/polymer/src/lib/resolve-url-extracted.js
diff --git a/third_party/polymer/v0_8/components-chromium/polymer/src/lib/resolve-url-extracted.js b/third_party/polymer/v0_8/components-chromium/polymer/src/lib/resolve-url-extracted.js
new file mode 100644
index 0000000000000000000000000000000000000000..9013ed56193ae596fd96a13373ddb030cdbe9026
--- /dev/null
+++ b/third_party/polymer/v0_8/components-chromium/polymer/src/lib/resolve-url-extracted.js
@@ -0,0 +1,72 @@
+
+
+ (function() {
+
+ // path fixup for urls in cssText that's expected to
+ // come from a given ownerDocument
+ function resolveCss(cssText, ownerDocument) {
+ return cssText.replace(CSS_URL_RX, function(m, pre, url, post) {
+ return pre + '\'' +
+ resolve(url.replace(/["']/g, ''), ownerDocument) +
+ '\'' + post;
+ });
+ }
+
+ // url fixup for urls in an element's attributes made relative to
+ // ownerDoc's base url
+ function resolveAttrs(element, ownerDocument) {
+ for (var name in URL_ATTRS) {
+ var a$ = URL_ATTRS[name];
+ for (var i=0, l=a$.length, a, at, v; (i<l) && (a=a$[i]); i++) {
+ if (name === '*' || element.localName === name) {
+ at = element.attributes[a];
+ v = at && at.value;
+ if (v && (v.search(BINDING_RX) < 0)) {
+ at.value = (a === 'style') ?
+ resolveCss(v, ownerDocument) :
+ resolve(v, ownerDocument);
+ }
+ }
+ }
+ }
+ }
+
+ function resolve(url, ownerDocument) {
+ var resolver = getUrlResolver(ownerDocument);
+ resolver.href = url;
+ return resolver.href || url;
+ }
+
+ var tempDoc;
+ var tempDocBase;
+ function resolveUrl(url, baseUri) {
+ if (!tempDoc) {
+ tempDoc = document.implementation.createHTMLDocument('temp');
+ tempDocBase = tempDoc.createElement('base');
+ tempDoc.head.appendChild(tempDocBase);
+ }
+ tempDocBase.href = baseUri;
+ return resolve(url, tempDoc);
+ }
+
+ function getUrlResolver(ownerDocument) {
+ return ownerDocument.__urlResolver ||
+ (ownerDocument.__urlResolver = ownerDocument.createElement('a'));
+ }
+
+ var CSS_URL_RX = /(url\()([^)]*)(\))/g;
+ var URL_ATTRS = {
+ '*': ['href', 'src', 'style', 'url'],
+ form: ['action']
+ };
+ var BINDING_RX = /\{\{|\[\[/;
+
+ // exports
+ Polymer.ResolveUrl = {
+ resolveCss: resolveCss,
+ resolveAttrs: resolveAttrs,
+ resolveUrl: resolveUrl
+ };
+
+ })();
+

Powered by Google App Engine
This is Rietveld 408576698