This repository was archived by the owner on Feb 22, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 216
feat(examples): Add a compelling Shadow DOM example #1377
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import 'package:angular/angular.dart'; | ||
import 'package:angular/application_factory.dart'; | ||
|
||
import 'dart:html'; | ||
import 'dart:js'; | ||
|
||
/** | ||
* A component with a simple template which the Javascript Google Maps API | ||
* will use to install a map inside the ShadowRoot. | ||
*/ | ||
@Component( | ||
selector: 'x-google-map', | ||
template: '<div style="height: 300px; width: 300px"></div>' | ||
) | ||
class XGoogleMaps implements ShadowRootAware { | ||
var map, infowindow; | ||
|
||
void onShadowRoot(root) { | ||
// From https://code.google.com/p/dart/source/browse/branches/bleeding_edge/dart/samples/google_maps/web/index.dart | ||
final gmaps = context['google']['maps']; | ||
var london = new JsObject(gmaps['LatLng'], [51.5, 0.125]); | ||
var mapOptions = new JsObject.jsify({ | ||
"center": london, | ||
"zoom": 8, | ||
}); | ||
|
||
map = new JsObject(gmaps['Map'], [root.querySelector('div'), mapOptions]); | ||
|
||
// The <content> tag is the exciting part of this component. Instead | ||
// of passing a string of HTML to the component, we use Shadow DOM to | ||
// punch a hole into the Shadow DOM allowing consumers to use parts of | ||
// their 'light DOM' | ||
infowindow = new JsObject(gmaps['InfoWindow'], [new JsObject.jsify({ | ||
"content": "<div style='height: 2em; width: 10em'><content></content></div>", | ||
"position": london | ||
})]); | ||
} | ||
|
||
@NgOneWay('info') | ||
set infoWindow(value) { | ||
if (value) { | ||
infowindow.callMethod('open', [map]); | ||
} else { | ||
infowindow.callMethod('close'); | ||
} | ||
} | ||
} | ||
|
||
main() { | ||
var module = new Module() | ||
..bind(XGoogleMaps); | ||
|
||
var injector = applicationFactory().addModule(module) | ||
.run(); | ||
var scope = injector.get(Scope); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta name="viewport" | ||
content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes"> | ||
<script type="text/javascript" | ||
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCYWvwtZy5UZ_O_0mG4V-sq-fQ2_yy84-Y"> | ||
</script> | ||
<script type="application/dart" src="maps.dart"></script> | ||
<script src="packages/browser/dart.js"></script> | ||
|
||
</head> | ||
<body ng-app> | ||
|
||
<x-google-map bind-info="openInfo"> | ||
Hello from {{someText}} | ||
</x-google-map> | ||
|
||
<label>Display InfoWindow: <input type="checkbox" ng-model="openInfo"></input></label> | ||
Enter text: <input type="text" ng-model="someText"></input> | ||
</body> | ||
</html> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
void
for all functions / methods