|
49 | 49 | },
|
50 | 50 |
|
51 | 51 | // search for extra style modules via `styleModules`
|
| 52 | + // TODO(sorvell): consider dropping support for `styleModules` |
52 | 53 | _prepareStyles: function() {
|
53 | 54 | var cssText = '', m$ = this.styleModules;
|
54 | 55 | if (m$) {
|
|
72 | 73 | var m = Polymer.DomModule.import(moduleId);
|
73 | 74 | if (m && !m._cssText) {
|
74 | 75 | var cssText = '';
|
75 |
| - var e$ = Array.prototype.slice.call(m.querySelectorAll('style')); |
76 |
| - this._unapplyStyles(e$); |
77 |
| - e$ = e$.concat(Array.prototype.map.call( |
78 |
| - //TODO(sorvell): add test for 404'ing import |
79 |
| - m.querySelectorAll(REMOTE_SHEET_SELECTOR), function(l) { |
80 |
| - return l.import && l.import.body; |
81 |
| - })); |
82 |
| - m._cssText = this._cssFromStyles(e$); |
83 |
| - } |
84 |
| - return m && m._cssText || ''; |
85 |
| - }, |
86 |
| - |
87 |
| - _cssFromStyles: function(styles) { |
88 |
| - var cssText = ''; |
89 |
| - for (var i=0, l=styles.length, s; (i<l) && (s = styles[i]); i++) { |
90 |
| - if (s && s.textContent) { |
91 |
| - cssText += |
92 |
| - Polymer.ResolveUrl.resolveCss(s.textContent, s.ownerDocument); |
| 76 | + var e$ = Array.prototype.slice.call( |
| 77 | + m.querySelectorAll(STYLES_SELECTOR)); |
| 78 | + for (var i=0, e; i < e$.length; i++) { |
| 79 | + e = e$[i]; |
| 80 | + // style elements inside dom-modules will apply to the main document |
| 81 | + // we don't want this, so we remove them here. |
| 82 | + if (e.localName === 'style') { |
| 83 | + // get style element applied to main doc via HTMLImports polyfill |
| 84 | + e = e.__appliedElement || e; |
| 85 | + e.parentNode.removeChild(e); |
| 86 | + // it's an import, assume this is a text file of css content. |
| 87 | + } else { |
| 88 | + e = e.import && e.import.body; |
| 89 | + } |
| 90 | + // adjust paths in css. |
| 91 | + if (e) { |
| 92 | + cssText += |
| 93 | + Polymer.ResolveUrl.resolveCss(e.textContent, e.ownerDocument); |
| 94 | + } |
93 | 95 | }
|
| 96 | + m._cssText = cssText; |
94 | 97 | }
|
95 |
| - return cssText; |
96 |
| - }, |
97 |
| - |
98 |
| - _unapplyStyles: function(styles) { |
99 |
| - for (var i=0, l=styles.length, s; (i<l) && (s = styles[i]); i++) { |
100 |
| - s = s.__appliedElement || s; |
101 |
| - s.parentNode.removeChild(s); |
102 |
| - } |
| 98 | + return m && m._cssText || ''; |
103 | 99 | },
|
104 | 100 |
|
105 | 101 | _transformStyles: function(styles, callback) {
|
|
188 | 184 |
|
189 | 185 | });
|
190 | 186 |
|
191 |
| - var REMOTE_SHEET_SELECTOR = 'link[rel=import][type~=css]'; |
| 187 | + var STYLES_SELECTOR = 'style, link[rel=import][type~=css]'; |
192 | 188 |
|
193 | 189 | })();
|
194 | 190 |
|
|
0 commit comments