| 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 bool platformJsFound = false; | 41 Element platformJs; |
| 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 (_platformJS.hasMatch(last)) { |
| 50 platformJsFound = true; | 50 platformJs = tag; |
| 51 } else if (_dartSupportJS.hasMatch(last)) { | 51 } else if (_dartSupportJS.hasMatch(last)) { |
| 52 dartSupportFound = true; | 52 dartSupportFound = true; |
| 53 } else if (last == 'dart.js') { | 53 } else if (last == 'dart.js') { |
| 54 dartJs = tag; | 54 dartJs = tag; |
| 55 } | 55 } |
| 56 } | 56 } |
| 57 | 57 |
| 58 if (tag.attributes['type'] == 'application/dart') { | 58 if (tag.attributes['type'] == 'application/dart') { |
| 59 dartScripts.add(tag); | 59 dartScripts.add(tag); |
| 60 } | 60 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 90 } else { | 90 } else { |
| 91 document.body.nodes.add(parseFragment( | 91 document.body.nodes.add(parseFragment( |
| 92 '<script src="packages/browser/dart.js"></script>')); | 92 '<script src="packages/browser/dart.js"></script>')); |
| 93 } | 93 } |
| 94 | 94 |
| 95 _addScriptFirst(urlSegment) { | 95 _addScriptFirst(urlSegment) { |
| 96 document.head.nodes.insert(0, parseFragment( | 96 document.head.nodes.insert(0, parseFragment( |
| 97 '<script src="packages/$urlSegment"></script>\n')); | 97 '<script src="packages/$urlSegment"></script>\n')); |
| 98 } | 98 } |
| 99 | 99 |
| 100 var suffix = options.releaseMode ? '.js' : '.concat.js'; | 100 // Inserts dart_support.js either at the top of the document or directly |
| 101 if (!dartSupportFound) _addScriptFirst('web_components/dart_support.js'); | 101 // after platform.js if it exists. |
| 102 // platform.js should come before all other scripts. | 102 if (!dartSupportFound) { |
| 103 if (!platformJsFound && options.injectPlatformJs) { | 103 if (platformJs == null) { |
| 104 _addScriptFirst('web_components/dart_support.js'); |
| 105 } else { |
| 106 var parentsNodes = platformJs.parentNode.nodes; |
| 107 parentsNodes.insert( |
| 108 parentsNodes.indexOf(platformJs) + 1, |
| 109 parseFragment( |
| 110 '\n<script src="packages/web_components/dart_support.js">' |
| 111 '</script>')); |
| 112 } |
| 113 } |
| 114 |
| 115 // By default platform.js should come before all other scripts. |
| 116 if (platformJs == null && options.injectPlatformJs) { |
| 117 var suffix = options.releaseMode ? '.js' : '.concat.js'; |
| 104 _addScriptFirst('web_components/platform$suffix'); | 118 _addScriptFirst('web_components/platform$suffix'); |
| 105 } | 119 } |
| 106 | 120 |
| 107 transform.addOutput( | 121 transform.addOutput( |
| 108 new Asset.fromString(transform.primaryInput.id, document.outerHtml)); | 122 new Asset.fromString(transform.primaryInput.id, document.outerHtml)); |
| 109 }); | 123 }); |
| 110 } | 124 } |
| 111 } | 125 } |
| 112 | 126 |
| 113 final _platformJS = new RegExp(r'platform.*\.js', caseSensitive: false); | 127 final _platformJS = new RegExp(r'platform.*\.js', caseSensitive: false); |
| 114 final _dartSupportJS = new RegExp(r'dart_support.js', caseSensitive: false); | 128 final _dartSupportJS = new RegExp(r'dart_support.js', caseSensitive: false); |
| OLD | NEW |