|
| 1 | +/** |
| 2 | + * Copyright (c) 2014 The Polymer Project Authors. All rights reserved. |
| 3 | + * This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt |
| 4 | + * The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt |
| 5 | + * The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt |
| 6 | + * Code distributed by Google as part of the polymer project is also |
| 7 | + * subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt |
| 8 | + */ |
| 9 | + |
| 10 | +window.Platform = window.Platform || {}; |
| 11 | +// prepopulate window.logFlags if necessary |
| 12 | +window.logFlags = window.logFlags || {}; |
| 13 | +// process flags |
| 14 | +(function(scope){ |
| 15 | + // import |
| 16 | + var flags = scope.flags || {}; |
| 17 | + // populate flags from location |
| 18 | + location.search.slice(1).split('&').forEach(function(o) { |
| 19 | + o = o.split('='); |
| 20 | + o[0] && (flags[o[0]] = o[1] || true); |
| 21 | + }); |
| 22 | + var entryPoint = document.currentScript || |
| 23 | + document.querySelector('script[src*="platform.js"]'); |
| 24 | + if (entryPoint) { |
| 25 | + var a = entryPoint.attributes; |
| 26 | + for (var i = 0, n; i < a.length; i++) { |
| 27 | + n = a[i]; |
| 28 | + if (n.name !== 'src') { |
| 29 | + flags[n.name] = n.value || true; |
| 30 | + } |
| 31 | + } |
| 32 | + } |
| 33 | + if (flags.log) { |
| 34 | + flags.log.split(',').forEach(function(f) { |
| 35 | + window.logFlags[f] = true; |
| 36 | + }); |
| 37 | + } |
| 38 | + // If any of these flags match 'native', then force native ShadowDOM; any |
| 39 | + // other truthy value, or failure to detect native |
| 40 | + // ShadowDOM, results in polyfill |
| 41 | + flags.shadow = flags.shadow || flags.shadowdom || flags.polyfill; |
| 42 | + if (flags.shadow === 'native') { |
| 43 | + flags.shadow = false; |
| 44 | + } else { |
| 45 | + flags.shadow = flags.shadow || !HTMLElement.prototype.createShadowRoot; |
| 46 | + } |
| 47 | + |
| 48 | + if (flags.shadow && document.querySelectorAll('script').length > 1) { |
| 49 | + console.warn('platform.js is not the first script on the page. ' + |
| 50 | + 'See http://www.polymer-project.org/docs/start/platform.html#setup ' + |
| 51 | + 'for details.'); |
| 52 | + } |
| 53 | + |
| 54 | + // CustomElements polyfill flag |
| 55 | + if (flags.register) { |
| 56 | + window.CustomElements = window.CustomElements || {flags: {}}; |
| 57 | + window.CustomElements.flags.register = flags.register; |
| 58 | + } |
| 59 | + |
| 60 | + if (flags.imports) { |
| 61 | + window.HTMLImports = window.HTMLImports || {flags: {}}; |
| 62 | + window.HTMLImports.flags.imports = flags.imports; |
| 63 | + } |
| 64 | + |
| 65 | + // export |
| 66 | + scope.flags = flags; |
| 67 | +})(Platform); |
0 commit comments