This repository has been archived by the owner on Mar 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathretrieving-the-insertion-points-for-distributed-nodes.html
87 lines (71 loc) · 2.98 KB
/
retrieving-the-insertion-points-for-distributed-nodes.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<!--
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<!--
# Retrieving the insertion points for distributed nodes
Shows how to obtain insertion points for distributed nodes when there
multiple `<content>` tags or multiple layers of Shadow DOM (e.g. when an element
extends another element).
To understand how to use the `<content>` tag, see
[Creating an insertion point using the `content` tag](creating-an-insertion-point-using-the-content-tag.html))
and
[Creating insertion points using the `select` attribute](creating-insertion-points-using-the-select-attribute.html)).
Also see this (Shadow DOM visualizer)[http://html5-demos.appspot.com/shadowdom-visualizer].
It is a common pattern to use multiple `<content>` tags with `select`
attributes to create multiple entry points for distributed nodes. For example,
`<my-element>` defines two such entry points:
<template>
<content select=".crucial"></content>
<content select=".ordinary"></content>
...
</template>
You may use `<my-element>` in this way:
<my-element>
<div class="ordinary">ordinary</div>
<div class="crucial">crucial</div>
</my-element>
In this case, Polymer inserts the `<div>` with the 'crucial' class into
the first `<content>` and the `<div>` with the 'ordinary' class into the second
`<content>`.
Use `getDestinationInsertionPoints()` to programmatically determine the
insertion points a node is distributed into:
node.getDestinationInsertionPoints();
Read more about
[insertion points and `getDestinationInsertionPoints()`](http://www.html5rocks.com/en/tutorials/webcomponents/shadowdom-301/#toc-distributed-nodes).
[jsbin](http://jsbin.com/lesago/edit)
-->
<link rel="import" href="../../components/polymer/polymer.html">
<polymer-element name="my-element">
<template>
<content select=".crucial"></content>
<content select=".ordinary"></content>
<button on-tap="{{showNodesAndEntryPoints}}">
Show nodes and entry points
</button>
<template repeat="{{el in nodesAndEntryPoints}}">
<div>{{el}}</div>
</template>
</template>
<script>
Polymer({
created: function() {
this.nodesAndEntryPoints = [];
},
showNodesAndEntryPoints: function() {
this.nodesAndEntryPoints = [];
for (var i = 0; i < this.children.length; i++) {
this.nodesAndEntryPoints.push(
this.children[i].outerHTML +
' ------> ' +
this.children[i].getDestinationInsertionPoints()[0].outerHTML
);
}
}
});
</script>
</polymer-element>