UNPKG

2.41 kBJavaScriptView Raw
1/**
2 * @license
3 * Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
4 * This code may only be used under the BSD style license found at
5 * http://polymer.github.io/LICENSE.txt The complete set of authors may be found
6 * at http://polymer.github.io/AUTHORS.txt The complete set of contributors may
7 * be found at http://polymer.github.io/CONTRIBUTORS.txt Code distributed by
8 * Google as part of the polymer project is also subject to an additional IP
9 * rights grant found at http://polymer.github.io/PATENTS.txt
10 */
11// Establish scope.
12const extendedWindow = window;
13extendedWindow['WebComponents'] =
14 extendedWindow['WebComponents'] || { 'flags': {} };
15// loading script
16const file = 'webcomponents-bundle';
17const script = document.querySelector('script[src*="' + file + '"]');
18const flagMatcher = /wc-(.+)/;
19// Note(rictic): a lot of this code looks wrong. Should we be pulling
20// the flags local variable off of window.WebComponents.flags? If not
21// then why check for noOpts, which can't possibly have been set?
22// Flags. Convert url arguments to flags
23let flags = {};
24if (!flags['noOpts']) {
25 // from url
26 location.search.slice(1).split('&').forEach(function (option) {
27 let parts = option.split('=');
28 let match;
29 if (parts[0] && (match = parts[0].match(flagMatcher))) {
30 flags[match[1]] = parts[1] || true;
31 }
32 });
33 // from script
34 if (script) {
35 for (let i = 0, a; (a = script.attributes[i]); i++) {
36 if (a.name !== 'src') {
37 flags[a.name] = a.value || true;
38 }
39 }
40 }
41 // log flags
42 const log = {};
43 if (flags['log'] && flags['log']['split']) {
44 let parts = flags['log'].split(',');
45 parts.forEach(function (f) {
46 log[f] = true;
47 });
48 }
49 flags['log'] = log;
50}
51// exports
52extendedWindow['WebComponents']['flags'] = flags;
53let forceShady = flags['shadydom'];
54if (forceShady) {
55 extendedWindow['ShadyDOM'] = extendedWindow['ShadyDOM'] || {};
56 extendedWindow['ShadyDOM']['force'] = forceShady;
57 const noPatch = flags['noPatch'];
58 extendedWindow['ShadyDOM']['noPatch'] = noPatch === 'true' ? true : noPatch;
59}
60let forceCE = (flags['register'] || flags['ce']);
61if (forceCE && window['customElements']) {
62 extendedWindow['customElements']['forcePolyfill'] = forceCE;
63}
64//# sourceMappingURL=flag-parser.js.map
\No newline at end of file