OLD | NEW |
| (Empty) |
1 <!-- | |
2 Copyright (c) 2014 The Polymer Project Authors. All rights reserved. | |
3 This code may only be used under the BSD style license found at http://polymer.g
ithub.io/LICENSE.txt | |
4 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt | |
5 The complete set of contributors may be found at http://polymer.github.io/CONTRI
BUTORS.txt | |
6 Code distributed by Google as part of the polymer project is also | |
7 subject to an additional IP rights grant found at http://polymer.github.io/PATEN
TS.txt | |
8 --> | |
9 | |
10 <!-- | |
11 `sampler-scaffold` provides a responsive layout for elements sampler. | |
12 | |
13 Exampler: | |
14 | |
15 <sampler-scaffold label="HTML Input Elements"> | |
16 | |
17 <core-item label="String" url="demos/string.html"></core-item> | |
18 <core-item label="Checkbox" url="demos/checkbox.html"></core-item> | |
19 <core-item label="Radio" url="demos/radio.html"></core-item> | |
20 <core-item label="Range" url="demos/range.html"></core-item> | |
21 <core-item label="Color" url="demos/color.html"></core-item> | |
22 | |
23 </sampler-scaffold> | |
24 | |
25 Use `label` to set the sampler label and `responsiveWidth` to change the layout | |
26 of the scaffold. | |
27 | |
28 @element sampler-scaffold | |
29 @homepage github.io | |
30 --> | |
31 | |
32 <link rel="import" href="../core-toolbar/core-toolbar.html"> | |
33 <link rel="import" href="../core-drawer-panel/core-drawer-panel.html"> | |
34 <link rel="import" href="../core-header-panel/core-header-panel.html"> | |
35 <link rel="import" href="../core-item/core-item.html"> | |
36 <link rel="import" href="../core-menu/core-menu.html"> | |
37 <link rel="import" href="../core-menu/core-submenu.html"> | |
38 <link rel="import" href="../core-icon-button/core-icon-button.html"> | |
39 | |
40 <polymer-element name="sampler-scaffold" attributes="label responsiveWidth"> | |
41 <template> | |
42 | |
43 <link rel="stylesheet" href="sampler-scaffold.css"> | |
44 | |
45 <core-drawer-panel id="drawerPanel" narrow="{{narrow}}" drawerWidth="320px" re
sponsiveWidth="{{responsiveWidth}}"> | |
46 | |
47 <core-header-panel id="mainHeaderPanel" main mode="{{narrow ? 'waterfall' :
'cover'}}" shadow> | |
48 | |
49 <core-toolbar class="{{ {'medium-tall' : !narrow} | tokenList }}"> | |
50 <content select=".menuButton" on-tap="{{togglePanel}}"> | |
51 <core-icon-button class="menuButton fallback" icon="menu"></core-icon-
button> | |
52 </content> | |
53 <div hidden?="{{!narrow}}">{{item.label}}</div> | |
54 <content select=".sourceButton" on-tap="{{viewSourceAction}}"> | |
55 <core-icon-button class="sourceButton fallback" icon="launch"></core-i
con-button> | |
56 </content> | |
57 | |
58 </core-toolbar> | |
59 | |
60 <div id="card" on-transitionend="{{cardTransitionDone}}" hidden?="{{!item}
}"> | |
61 | |
62 <div class="element-label" hidden?="{{narrow}}">{{item.label}}</div> | |
63 | |
64 <div id="frameContainer"> | |
65 <iframe id="frame" on-load="{{frameLoaded}}"></iframe> | |
66 </div> | |
67 | |
68 </div> | |
69 | |
70 </core-header-panel> | |
71 | |
72 <core-header-panel drawer> | |
73 | |
74 <core-toolbar class="{{ {'medium-tall' : !narrow} | tokenList }}"> | |
75 <div class="bottom main-label fit">{{label}}</div> | |
76 </core-toolbar> | |
77 | |
78 <core-menu id="menu" on-core-select="{{menuSelect}}"> | |
79 <content></content> | |
80 </core-menu> | |
81 | |
82 </core-header-panel> | |
83 | |
84 </core-drawer-panel> | |
85 | |
86 </template> | |
87 <script> | |
88 | |
89 Polymer('sampler-scaffold', { | |
90 | |
91 /** | |
92 * When the browser window size is smaller than the `responsiveWidth`, | |
93 * `sampler-scaffold` changes to a narrow layout. In narrow layout, | |
94 * the drawer will be stacked on top of the main panel. | |
95 * | |
96 * @attribute responsiveWidth | |
97 * @type string | |
98 */ | |
99 responsiveWidth: '860px', | |
100 | |
101 /** | |
102 * Sampler label. | |
103 * | |
104 * @attribute label | |
105 * @type string | |
106 */ | |
107 | |
108 ready: function() { | |
109 this.boundResizeFrame = this.resizeFrame.bind(this); | |
110 window.addEventListener('resize', this.updateFrameHeight.bind(this)); | |
111 window.addEventListener('hashchange', this.parseLocationHash.bind(this)); | |
112 }, | |
113 | |
114 domReady: function() { | |
115 this.async(function() { | |
116 this.parseLocationHash(); | |
117 }, null, 300); | |
118 }, | |
119 | |
120 parseLocationHash: function() { | |
121 var route = window.location.hash.slice(1); | |
122 for (var i = 0, item; item = this.$.menu.items[i]; i++) { | |
123 if (item.getAttribute('tag') === route) { | |
124 this.$.menu.selected = i; | |
125 return; | |
126 } | |
127 } | |
128 this.$.menu.selected = this.$.menu.selected || 0; | |
129 }, | |
130 | |
131 menuSelect: function(e, detail) { | |
132 if (detail.isSelected) { | |
133 this.item = detail.item; | |
134 if (this.item.children.length) { | |
135 this.item.selected = 0; | |
136 } | |
137 this.item.tag = this.item.getAttribute('tag'); | |
138 var url = this.item.getAttribute('url'); | |
139 this.$.frame.contentWindow.location.replace(url); | |
140 window.location.hash = this.item.tag; | |
141 if (this.narrow) { | |
142 this.$.drawerPanel.closeDrawer(); | |
143 } else { | |
144 this.animateCard(); | |
145 } | |
146 } | |
147 }, | |
148 | |
149 animateCard: function() { | |
150 this.$.card.classList.remove('move-up'); | |
151 this.$.card.style.display = 'none'; | |
152 this.async(function() { | |
153 this.$.card.style.display = 'block'; | |
154 this.moveCard(this.$.mainHeaderPanel.offsetHeight); | |
155 this.async(function() { | |
156 this.$.card.classList.add('move-up'); | |
157 this.moveCard(null); | |
158 }, null, 300); | |
159 }); | |
160 }, | |
161 | |
162 moveCard: function(y) { | |
163 var s = this.$.card.style; | |
164 s.webkitTransform = s.transform = | |
165 y ? 'translate3d(0, ' + y + 'px,0)' : ''; | |
166 }, | |
167 | |
168 cardTransitionDone: function() { | |
169 if (this.$.card.classList.contains('move-up')) { | |
170 this.$.card.classList.remove('move-up'); | |
171 this.updateFrameHeight(); | |
172 } | |
173 }, | |
174 | |
175 togglePanel: function() { | |
176 this.$.drawerPanel.togglePanel(); | |
177 }, | |
178 | |
179 frameLoaded: function() { | |
180 if (!this.item) { | |
181 return; | |
182 } | |
183 this.$.frame.contentWindow.addEventListener('polymer-ready', function() { | |
184 setTimeout(this.updateFrameHeight.bind(this), 100); | |
185 this.$.frame.contentWindow.addEventListener('core-resize', | |
186 this.boundResizeFrame, false); | |
187 }.bind(this)); | |
188 }, | |
189 | |
190 resizeFrame: function() { | |
191 this.job('resizeFrame', function() { | |
192 this.updateFrameHeight(); | |
193 }); | |
194 }, | |
195 | |
196 updateFrameHeight: function() { | |
197 var frame = this.$.frame; | |
198 var doc = frame.contentDocument; | |
199 if (doc) { | |
200 var docElt = doc.documentElement; | |
201 // TODO(ffu); expose scroll info from header-panel | |
202 var pos = this.$.mainHeaderPanel.$.mainContainer.scrollTop; | |
203 frame.style.height = 'auto'; | |
204 frame.style.height = docElt.scrollHeight + 'px'; | |
205 if (doc.body) { | |
206 var s = doc.body.style; | |
207 s.overflow = 'hidden'; | |
208 // to avoid the 'blinking bug' | |
209 // https://code.google.com/p/chromium/issues/detail?id=332024 | |
210 s.webkitTransform = s.transform = 'translateZ(0)'; | |
211 } | |
212 this.$.mainHeaderPanel.$.mainContainer.scrollTop = pos; | |
213 } | |
214 }, | |
215 | |
216 viewSourceAction: function() { | |
217 window.open('view-source:' + this.$.frame.contentWindow.location.href, | |
218 this.item.tag); | |
219 } | |
220 | |
221 }); | |
222 | |
223 </script> | |
224 </polymer-element> | |
OLD | NEW |