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

Unified Diff: appengine/config_service/ui/bower_components/shadycss/examples/document-style-lib.js

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 side-by-side diff with in-line comments
Download patch
Index: appengine/config_service/ui/bower_components/shadycss/examples/document-style-lib.js
diff --git a/appengine/config_service/ui/bower_components/shadycss/examples/document-style-lib.js b/appengine/config_service/ui/bower_components/shadycss/examples/document-style-lib.js
new file mode 100644
index 0000000000000000000000000000000000000000..a1c032c0fdf43a5cca90db94c0a351043eec26b2
--- /dev/null
+++ b/appengine/config_service/ui/bower_components/shadycss/examples/document-style-lib.js
@@ -0,0 +1,54 @@
+/**
+@license
+Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
+This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
+The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
+The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
+Code distributed by Google as part of the polymer project is also
+subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
+*/
+
+/*
+Example library for adding document-level styles to ShadyCSS
+
+After DOMContentLoaded, synchronously add all document document level styles.
+Then, start a MutationObserver for dynamically added styles.
+
+Caveat: ShadyCSS will add a `scope` attribute to styles it controls, so do not add those styles.
+*/
+(function() {
+ 'use strict';
+
+ const CustomStyleInterface = window.ShadyCSS.CustomStyleInterface;
+
+ function shouldAddDocumentStyle(n) {
+ return n.nodeType === Node.ELEMENT_NODE && n.localName === 'style' && !n.hasAttribute('scope');
+ }
+
+ function handler(mxns) {
+ for (let i = 0; i < mxns.length; i++) {
+ let mxn = mxns[i];
+ for (let j = 0; j < mxn.addedNodes.length; j++) {
+ let n = mxn.addedNodes[j];
+ if (shouldAddDocumentStyle(n)) {
+ CustomStyleInterface.addCustomStyle(n);
+ }
+ }
+ }
+ }
+
+ const observer = new MutationObserver(handler);
+
+ document.addEventListener('DOMContentLoaded', () => {
+ const candidates = document.querySelectorAll('custom-style');
+ for (let i = 0; i < candidates.length; i++) {
+ const candidate = candidates[i];
+ if (shouldAddDocumentStyle(candidate)) {
+ CustomStyleInterface.addCustomStyle(candidate);
+ }
+ }
+ observer.observe(document, {childList: true, subtree: true});
+ });
+
+ window.documentStyleFlush = () => {handler(observer.takeRecords())};
+})();

Powered by Google App Engine
This is Rietveld 408576698