Skip to content

Commit b22f3cd

Browse files
author
Steven Orvell
committedAug 7, 2015
ensure path fixup is applied correctly to styles in templates.
1 parent f469129 commit b22f3cd

8 files changed

+40
-9
lines changed
 

‎src/lib/custom-style.html

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,6 @@
132132
_apply: function() {
133133
// used applied element from HTMLImports polyfill or this
134134
var e = this.__appliedElement || this;
135-
// path fixup iff necessary
136-
if (!this.__appliedElement) {
137-
e.textContent = styleUtil.resolveCss(e.textContent, e.ownerDocument);
138-
}
139135
if (this.include) {
140136
e.textContent += styleUtil.cssFromModules(this.include);
141137
}

‎src/lib/style-util.html

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,18 @@
104104
// support lots of ways to discover css...
105105
_cssFromElement: function(element) {
106106
var cssText = '';
107+
// if element is a template, get content from its .content
108+
var content = element.content || element;
109+
var sourceDoc = element.ownerDocument;
107110
var e$ = Array.prototype.slice.call(
108-
element.querySelectorAll(this.MODULE_STYLES_SELECTOR));
109-
for (var i=0, e, addModule; i < e$.length; i++) {
111+
content.querySelectorAll(this.MODULE_STYLES_SELECTOR));
112+
for (var i=0, e, resolveDoc, addModule; i < e$.length; i++) {
110113
e = e$[i];
114+
resolveDoc = sourceDoc;
111115
addModule = null;
112116
// look inside templates for elements
113117
if (e.localName === 'template') {
114-
cssText += this._cssFromElement(e.content);
118+
cssText += this._cssFromElement(e);
115119
} else {
116120
// style elements inside dom-modules will apply to the main document
117121
// we don't want this, so we remove them here.
@@ -125,10 +129,11 @@
125129
// TODO(sorvell): plan is to deprecate this way to get styles;
126130
// remember to add deprecation warning when this is done.
127131
e = e.import && e.import.body;
132+
resolveDoc = e.import;
128133
}
129134
// adjust paths in css.
130135
if (e) {
131-
cssText += this.resolveCss(e.textContent, e.ownerDocument);
136+
cssText += this.resolveCss(e.textContent, resolveDoc);
132137
}
133138
}
134139
// now support module refs on 'styling' elements

‎test/unit/custom-style-import.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
</template>
99
</dom-module>
1010

11-
<style is="custom-style" include="shared-style">
11+
<link rel="import" href="sub/style-import.html">
12+
13+
<style is="custom-style" include="shared-style style-import">
1214
:root {
1315

1416
--import-mixin: {

‎test/unit/custom-style.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@
119119
<br><br>
120120
<div id="after"></div>
121121

122+
<div class="foo"></div>
123+
122124

123125
<dom-module id="x-baz">
124126
<style>
@@ -253,6 +255,12 @@
253255
assertComputed(document.body, '12px');
254256
});
255257

258+
test('style paths in included dom-modules loaded in import', function() {
259+
var foo = document.querySelector('.foo');
260+
var url = getComputedStyle(foo).backgroundImage;
261+
assert.include(url, 'sub/google.png');
262+
});
263+
256264
});
257265

258266

‎test/unit/styling-remote-elements.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
<x-child2 class="wide" id="child2"></x-child2>
109109
<div id="computed" class$="{{computeClass(aClass)}}">Computed</div>
110110
<content></content>
111+
<div id="url" class="foo"></div>
111112
</template>
112113
</dom-module>
113114
<script>

‎test/unit/styling-remote-module-sheet.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
<link rel="import" href="sub/style-import.html">
12
<dom-module id="remote-styles">
23
<template>
4+
<style include="style-import"></style>
35
<style>
46
#simple {
57
border: 3px solid orange;

‎test/unit/styling-remote.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,12 @@
173173
assertComputed(order.$.me, '10px');
174174
});
175175

176+
test('style paths in included dom-modules loaded in import', function() {
177+
var el = styled.$.url;
178+
var url = getComputedStyle(el).backgroundImage;
179+
assert.include(url, 'sub/google.png');
180+
});
181+
176182
// weird check allows testing under HTMLImports polyfill
177183
if (!window.Polymer || !Polymer.Settings.useNativeShadow) {
178184

‎test/unit/sub/style-import.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<dom-module id="style-import">
2+
<template>
3+
<style>
4+
.foo {
5+
height: 2px;
6+
border: 1px solid orange;
7+
background: url(google.png);
8+
}
9+
</style>
10+
</template>
11+
</dom-module>

0 commit comments

Comments
 (0)
Please sign in to comment.