| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /// Includes any additional polyfills that may needed by the deployed app. | 5 /// Includes any additional polyfills that may needed by the deployed app. |
| 6 library polymer.src.build.polyfill_injector; | 6 library polymer.src.build.polyfill_injector; |
| 7 | 7 |
| 8 import 'dart:async'; | 8 import 'dart:async'; |
| 9 | 9 |
| 10 import 'package:barback/barback.dart'; | 10 import 'package:barback/barback.dart'; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 var id = idOrAsset is AssetId ? idOrAsset : idOrAsset.id; | 31 var id = idOrAsset is AssetId ? idOrAsset : idOrAsset.id; |
| 32 return new Future.value(options.isHtmlEntryPoint(id)); | 32 return new Future.value(options.isHtmlEntryPoint(id)); |
| 33 } | 33 } |
| 34 | 34 |
| 35 Future apply(Transform transform) { | 35 Future apply(Transform transform) { |
| 36 var logger = new BuildLogger(transform, | 36 var logger = new BuildLogger(transform, |
| 37 convertErrorsToWarnings: !options.releaseMode, | 37 convertErrorsToWarnings: !options.releaseMode, |
| 38 detailsUri: 'http://goo.gl/5HPeuP'); | 38 detailsUri: 'http://goo.gl/5HPeuP'); |
| 39 return readPrimaryAsHtml(transform, logger).then((document) { | 39 return readPrimaryAsHtml(transform, logger).then((document) { |
| 40 bool dartSupportFound = false; | 40 bool dartSupportFound = false; |
| 41 Element platformJs; | 41 Element webComponentsJs; |
| 42 Element dartJs; | 42 Element dartJs; |
| 43 final dartScripts = <Element>[]; | 43 final dartScripts = <Element>[]; |
| 44 | 44 |
| 45 for (var tag in document.querySelectorAll('script')) { | 45 for (var tag in document.querySelectorAll('script')) { |
| 46 var src = tag.attributes['src']; | 46 var src = tag.attributes['src']; |
| 47 if (src != null) { | 47 if (src != null) { |
| 48 var last = src.split('/').last; | 48 var last = src.split('/').last; |
| 49 if (_platformJS.hasMatch(last)) { | 49 if (_webComponentsJS.hasMatch(last)) { |
| 50 platformJs = tag; | 50 webComponentsJs = tag; |
| 51 } else if (_platformJS.hasMatch(last)) { |
| 52 tag.attributes['src'] = src.replaceFirst( |
| 53 _platformJS, 'webcomponents.min.js'); |
| 54 webComponentsJs = tag; |
| 51 } else if (_dartSupportJS.hasMatch(last)) { | 55 } else if (_dartSupportJS.hasMatch(last)) { |
| 52 dartSupportFound = true; | 56 dartSupportFound = true; |
| 53 } else if (last == 'dart.js') { | 57 } else if (last == 'dart.js') { |
| 54 dartJs = tag; | 58 dartJs = tag; |
| 55 } | 59 } |
| 56 } | 60 } |
| 57 | 61 |
| 58 if (tag.attributes['type'] == 'application/dart') { | 62 if (tag.attributes['type'] == 'application/dart') { |
| 59 dartScripts.add(tag); | 63 dartScripts.add(tag); |
| 60 } | 64 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 91 document.body.nodes.add(parseFragment( | 95 document.body.nodes.add(parseFragment( |
| 92 '<script src="packages/browser/dart.js"></script>')); | 96 '<script src="packages/browser/dart.js"></script>')); |
| 93 } | 97 } |
| 94 | 98 |
| 95 _addScriptFirst(urlSegment) { | 99 _addScriptFirst(urlSegment) { |
| 96 document.head.nodes.insert(0, parseFragment( | 100 document.head.nodes.insert(0, parseFragment( |
| 97 '<script src="packages/$urlSegment"></script>\n')); | 101 '<script src="packages/$urlSegment"></script>\n')); |
| 98 } | 102 } |
| 99 | 103 |
| 100 // Inserts dart_support.js either at the top of the document or directly | 104 // Inserts dart_support.js either at the top of the document or directly |
| 101 // after platform.js if it exists. | 105 // after webcomponents.js if it exists. |
| 102 if (!dartSupportFound) { | 106 if (!dartSupportFound) { |
| 103 if (platformJs == null) { | 107 if (webComponentsJs == null) { |
| 104 _addScriptFirst('web_components/dart_support.js'); | 108 _addScriptFirst('web_components/dart_support.js'); |
| 105 } else { | 109 } else { |
| 106 var parentsNodes = platformJs.parentNode.nodes; | 110 var parentsNodes = webComponentsJs.parentNode.nodes; |
| 107 parentsNodes.insert( | 111 parentsNodes.insert( |
| 108 parentsNodes.indexOf(platformJs) + 1, | 112 parentsNodes.indexOf(webComponentsJs) + 1, |
| 109 parseFragment( | 113 parseFragment( |
| 110 '\n<script src="packages/web_components/dart_support.js">' | 114 '\n<script src="packages/web_components/dart_support.js">' |
| 111 '</script>')); | 115 '</script>')); |
| 112 } | 116 } |
| 113 } | 117 } |
| 114 | 118 |
| 115 // By default platform.js should come before all other scripts. | 119 // By default webcomponents.js should come before all other scripts. |
| 116 if (platformJs == null && options.injectPlatformJs) { | 120 if (webComponentsJs == null && options.injectWebComponentsJs) { |
| 117 var suffix = options.releaseMode ? '.js' : '.concat.js'; | 121 var suffix = options.releaseMode ? '.min.js' : '.js'; |
| 118 _addScriptFirst('web_components/platform$suffix'); | 122 _addScriptFirst('web_components/webcomponents$suffix'); |
| 119 } | 123 } |
| 120 | 124 |
| 121 transform.addOutput( | 125 transform.addOutput( |
| 122 new Asset.fromString(transform.primaryInput.id, document.outerHtml)); | 126 new Asset.fromString(transform.primaryInput.id, document.outerHtml)); |
| 123 }); | 127 }); |
| 124 } | 128 } |
| 125 } | 129 } |
| 126 | 130 |
| 127 final _platformJS = new RegExp(r'platform.*\.js', caseSensitive: false); | 131 final _platformJS = new RegExp(r'platform.*\.js', caseSensitive: false); |
| 132 final _webComponentsJS = |
| 133 new RegExp(r'webcomponents.*\.js', caseSensitive: false); |
| 128 final _dartSupportJS = new RegExp(r'dart_support.js', caseSensitive: false); | 134 final _dartSupportJS = new RegExp(r'dart_support.js', caseSensitive: false); |
| OLD | NEW |