-
Notifications
You must be signed in to change notification settings - Fork 2k
Fixes #4357. #4360
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes #4357. #4360
Changes from 2 commits
4a6e06d
f21282a
04a7579
1de623b
4538baa
359ce9e
9cd7d80
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -392,13 +392,16 @@ | |
* style scoping. | ||
* @param {HTMLElement} proto | ||
* @param {HTMLTemplateElement} template | ||
* @param {string} baseURI URL against which to resolve urls in | ||
* style element cssText. | ||
* @param {string} is | ||
* @param {string} ext | ||
* @private | ||
*/ | ||
function finalizeTemplate(proto, template, is, ext) { | ||
function finalizeTemplate(proto, template, baseURI, is, ext) { | ||
// support `include="module-name"` | ||
let cssText = Polymer.StyleGather.cssFromTemplate(template) + | ||
let cssText = | ||
Polymer.StyleGather.cssFromTemplate(template, baseURI) + | ||
Polymer.StyleGather.cssFromModuleImports(is); | ||
if (cssText) { | ||
let style = document.createElement('style'); | ||
|
@@ -489,6 +492,8 @@ | |
* return memoizedTemplate; | ||
* } | ||
* } | ||
* | ||
* @returns {HTMLTemplateElement|string} | ||
*/ | ||
static get template() { | ||
if (!this.hasOwnProperty(goog.reflect.objectProperty('_template', this))) { | ||
|
@@ -501,6 +506,26 @@ | |
return this._template; | ||
} | ||
|
||
/** | ||
* Path matching the url from which the element was imported. | ||
* This path is used to resolve url's in template style cssText. | ||
* The `importPath` property is also set on element instances and can be | ||
* used to create bindings relative to the import path. | ||
* Defaults to the path matching the url containing a `dom-module` element | ||
* matching this element's static `is` property. | ||
* Note, this path should contain a trailing `/`. | ||
* | ||
* @returns {string} | ||
*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
static get importPath() { | ||
if (!this.hasOwnProperty(goog.reflect.objectProperty('_importPath', this))) { | ||
const module = Polymer.DomModule.import(this.is); | ||
this._importPath = module ? module.assetpath : '' || | ||
Object.getPrototypeOf(this.prototype).constructor.importPath; | ||
} | ||
return this._importPath; | ||
} | ||
|
||
constructor() { | ||
super(); | ||
Polymer.telemetry.instanceCount++; | ||
|
@@ -524,13 +549,20 @@ | |
*/ | ||
_initializeProperties() { | ||
this.constructor.finalize(); | ||
const importPath = this.constructor.importPath; | ||
// note: finalize template when we have access to `localName` to | ||
// avoid dependence on `is` for polyfilling styling. | ||
if (this._template && !this._template.__polymerFinalized) { | ||
this._template.__polymerFinalized = true; | ||
finalizeTemplate(this.__proto__, this._template, this.localName); | ||
const baseURI = | ||
importPath ? Polymer.ResolveUrl.resolveUrl(importPath) : ''; | ||
finalizeTemplate(this.__proto__, this._template, baseURI, | ||
this.localName); | ||
} | ||
super._initializeProperties(); | ||
// set path defaults | ||
this.rootPath = Polymer.rootPath; | ||
this.importPath = importPath; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reminder to discuss why it was bad if these went before initializeProperties |
||
// apply property defaults... | ||
let p$ = propertyDefaultsForClass(this.constructor); | ||
if (!p$) { | ||
|
@@ -673,13 +705,12 @@ | |
* | ||
* @param {string} url URL to resolve. | ||
* @param {string=} base Optional base URL to resolve against, defaults | ||
* to the element template's ownerDocument baseURI. | ||
* @return {string} Rewritten URL relative to the import | ||
* to the element's `importPath` | ||
* @return {string} Rewritten URL relative to base | ||
*/ | ||
resolveUrl(url, base) { | ||
if (!base) { | ||
const module = Polymer.DomModule.import(this.constructor.is); | ||
base = module ? module.assetpath : document.baseURI; | ||
if (!base && this.importPath) { | ||
base = Polymer.ResolveUrl.resolveUrl(this.importPath); | ||
} | ||
return Polymer.ResolveUrl.resolveUrl(url, base); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,9 @@ | |
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt | ||
--> | ||
<script> | ||
(function() { | ||
|
||
const userPolymer = window.Polymer; | ||
|
||
/** | ||
* @namespace Polymer | ||
|
@@ -18,6 +21,12 @@ | |
window.Polymer = function(info) { | ||
return window.Polymer._polymerFn(info); | ||
} | ||
|
||
// support user settings on the Polymer object | ||
if (userPolymer) { | ||
Object.assign(Polymer, userPolymer); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just noting, this fixes the ability to set |
||
|
||
// To be plugged by legacy implementation if loaded | ||
window.Polymer._polymerFn = function() { | ||
throw new Error('Load polymer.html to use the Polymer() function.'); | ||
|
@@ -29,12 +38,14 @@ | |
When using Closure Compiler, goog.reflect.objectProperty(property, object) is replaced by the munged name for object[property] | ||
We cannot alias this function, so we have to use a small shim that has the same behavior when not compiling. | ||
*/ | ||
var goog = { | ||
window.goog = { | ||
reflect: { | ||
objectProperty(s, o) { | ||
return s; | ||
} | ||
} | ||
} | ||
/* eslint-enable */ | ||
|
||
})(); | ||
</script> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@returns {HTMLTemplateElement}