Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit 028b237

Browse files
committed
feat(examples): Add a compelling Shadow DOM example
Conflicts: example/web/index.html Closes #1377
1 parent 76ff760 commit 028b237

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed

example/web/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<li><a href="shadow_dom_components.html">shadow_dom_components.html</a></li>
99
<li><a href="paper.html">paper.html</a></li>
1010
<li><a href="form.html">form.html</a></li>
11+
<li><a href="maps.html">maps.html</a></li>
1112
</ul>
1213
</body>
1314
</html>

example/web/maps.dart

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import 'package:angular/angular.dart';
2+
import 'package:angular/application_factory.dart';
3+
4+
import 'dart:html';
5+
import 'dart:js';
6+
7+
/**
8+
* A component with a simple template which the Javascript Google Maps API
9+
* will use to install a map inside the ShadowRoot.
10+
*/
11+
@Component(
12+
selector: 'x-google-map',
13+
template: '<div style="height: 300px; width: 300px"></div>'
14+
)
15+
class XGoogleMaps implements ShadowRootAware {
16+
var map, infowindow;
17+
18+
onShadowRoot(root) {
19+
// From https://code.google.com/p/dart/source/browse/branches/bleeding_edge/dart/samples/google_maps/web/index.dart
20+
final gmaps = context['google']['maps'];
21+
var london = new JsObject(gmaps['LatLng'], [51.5, 0.125]);
22+
var mapOptions = new JsObject.jsify({
23+
"center": london,
24+
"zoom": 8,
25+
});
26+
27+
map = new JsObject(gmaps['Map'], [root.querySelector('div'), mapOptions]);
28+
29+
// The <content> tag is the exciting part of this component. Instead
30+
// of passing a string of HTML to the component, we use Shadow DOM to
31+
// punch a hole into the Shadow DOM allowing consumers to use parts of
32+
// their 'light DOM'
33+
infowindow = new JsObject(gmaps['InfoWindow'], [new JsObject.jsify({
34+
"content": "<div style='height: 2em; width: 10em'><content></content></div>",
35+
"position": london
36+
})]);
37+
}
38+
39+
@NgOneWay('info')
40+
set infoWindow(value) {
41+
if (value) {
42+
infowindow.callMethod('open', [map]);
43+
} else {
44+
infowindow.callMethod('close');
45+
}
46+
}
47+
}
48+
49+
main() {
50+
var module = new Module()
51+
..bind(XGoogleMaps);
52+
53+
var injector = applicationFactory().addModule(module)
54+
.run();
55+
var scope = injector.get(Scope);
56+
}

example/web/maps.html

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta name="viewport"
5+
content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
6+
<script type="text/javascript"
7+
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCYWvwtZy5UZ_O_0mG4V-sq-fQ2_yy84-Y">
8+
</script>
9+
<script type="application/dart" src="maps.dart"></script>
10+
<script src="packages/browser/dart.js"></script>
11+
12+
</head>
13+
<body ng-app>
14+
15+
<x-google-map bind-info="openInfo">
16+
Hello from {{someText}}
17+
</x-google-map>
18+
19+
Open InfoWindow: <input type="checkbox" ng-model="openInfo"></input>
20+
Enter text: <input type="text" ng-model="someText"></input>
21+
</body>
22+
</html>

0 commit comments

Comments
 (0)