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

Side by Side Diff: appengine/config_service/ui/bower_components/polymer/lib/utils/style-gather.html

Issue 2923973003: Added base template for config ui. (Closed)
Patch Set: Created 3 years, 6 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 unified diff | Download patch
OLDNEW
(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="resolve-url.html">
11 <script>
12 (function() {
13 'use strict';
14
15 const MODULE_STYLE_LINK_SELECTOR = 'link[rel=import][type~=css]';
16 const INCLUDE_ATTR = 'include';
17
18 function importModule(moduleId) {
19 if (!Polymer.DomModule) {
20 return null;
21 }
22 return Polymer.DomModule.import(moduleId);
23 }
24
25 /**
26 * Module with utilities for collection CSS text from `<templates>`, external
27 * stylesheets, and `dom-module`s.
28 *
29 * @namespace
30 * @memberof Polymer
31 * @summary Module with utilities for collection CSS text from various sources .
32 */
33 const StyleGather = {
34
35 /**
36 * Returns CSS text of styles in a space-separated list of `dom-module`s.
37 *
38 * @memberof Polymer.StyleGather
39 * @param {string} moduleIds List of dom-module id's within which to
40 * search for css.
41 * @return {string} Concatenated CSS content from specified `dom-module`s
42 */
43 cssFromModules(moduleIds) {
44 let modules = moduleIds.trim().split(' ');
45 let cssText = '';
46 for (let i=0; i < modules.length; i++) {
47 cssText += this.cssFromModule(modules[i]);
48 }
49 return cssText;
50 },
51
52 /**
53 * Returns CSS text of styles in a given `dom-module`. CSS in a `dom-module `
54 * can come either from `<style>`s within the first `<template>`, or else
55 * from one or more `<link rel="import" type="css">` links outside the
56 * template.
57 *
58 * Any `<styles>` processed are removed from their original location.
59 *
60 * @memberof Polymer.StyleGather
61 * @param {string} moduleId dom-module id to gather styles from
62 * @return {string} Concatenated CSS content from specified `dom-module`
63 */
64 cssFromModule(moduleId) {
65 let m = importModule(moduleId);
66 if (m && m._cssText === undefined) {
67 let cssText = '';
68 // include css from the first template in the module
69 let t = m.querySelector('template');
70 if (t) {
71 cssText += this.cssFromTemplate(t, m.assetpath);
72 }
73 // module imports: <link rel="import" type="css">
74 cssText += this.cssFromModuleImports(moduleId);
75 m._cssText = cssText || null;
76 }
77 if (!m) {
78 console.warn('Could not find style data in module named', moduleId);
79 }
80 return m && m._cssText || '';
81 },
82
83 /**
84 * Returns CSS text of `<styles>` within a given template.
85 *
86 * Any `<styles>` processed are removed from their original location.
87 *
88 * @memberof Polymer.StyleGather
89 * @param {HTMLTemplateElement} template Template to gather styles from
90 * @param {string} baseURI Base URI to resolve the URL against
91 * @return {string} Concatenated CSS content from specified template
92 */
93 cssFromTemplate(template, baseURI) {
94 let cssText = '';
95 // if element is a template, get content from its .content
96 let e$ = template.content.querySelectorAll('style');
97 for (let i=0; i < e$.length; i++) {
98 let e = e$[i];
99 // support style sharing by allowing styles to "include"
100 // other dom-modules that contain styling
101 let include = e.getAttribute(INCLUDE_ATTR);
102 if (include) {
103 cssText += this.cssFromModules(include);
104 }
105 e.parentNode.removeChild(e);
106 cssText += baseURI ?
107 Polymer.ResolveUrl.resolveCss(e.textContent, baseURI) : e.textContent;
108 }
109 return cssText;
110 },
111
112 /**
113 * Returns CSS text from stylsheets loaded via `<link rel="import" type="css ">`
114 * links within the specified `dom-module`.
115 *
116 * @memberof Polymer.StyleGather
117 * @param {string} moduleId Id of `dom-module` to gather CSS from
118 * @return {string} Concatenated CSS content from links in specified `dom-mo dule`
119 */
120 cssFromModuleImports(moduleId) {
121 let cssText = '';
122 let m = importModule(moduleId);
123 if (!m) {
124 return cssText;
125 }
126 let p$ = m.querySelectorAll(MODULE_STYLE_LINK_SELECTOR);
127 for (let i=0; i < p$.length; i++) {
128 let p = p$[i];
129 if (p.import) {
130 let importDoc = p.import;
131 // NOTE: polyfill affordance.
132 // under the HTMLImports polyfill, there will be no 'body',
133 // but the import pseudo-doc can be used directly.
134 let container = importDoc.body ? importDoc.body : importDoc;
135 cssText +=
136 Polymer.ResolveUrl.resolveCss(container.textContent,
137 importDoc.baseURI);
138 }
139 }
140 return cssText;
141 }
142 };
143
144 Polymer.StyleGather = StyleGather;
145 })();
146 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698