|
| 1 | +<!-- |
| 2 | +@license |
| 3 | +Copyright (c) 2016 The Polymer Project Authors. All rights reserved. |
| 4 | +This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt |
| 5 | +The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt |
| 6 | +The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt |
| 7 | +Code distributed by Google as part of the polymer project is also |
| 8 | +subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt |
| 9 | +--> |
| 10 | +<link rel="import" href="../bower_components/polymer/polymer.html"> |
| 11 | +<link rel="import" href="../bower_components/app-layout/app-drawer/app-drawer.html"> |
| 12 | +<link rel="import" href="../bower_components/app-layout/app-header/app-header.html"> |
| 13 | +<link rel="import" href="../bower_components/app-layout/helpers/helpers.html"> |
| 14 | +<link rel="import" href="../bower_components/carbon-route/carbon-location.html"> |
| 15 | +<link rel="import" href="../bower_components/carbon-route/carbon-route.html"> |
| 16 | +<link rel="import" href="../bower_components/iron-ajax/iron-ajax.html"> |
| 17 | +<link rel="import" href="../bower_components/iron-flex-layout/iron-flex-layout-classes.html"> |
| 18 | +<link rel="import" href="../bower_components/iron-selector/iron-selector.html"> |
| 19 | +<link rel="import" href="../bower_components/paper-icon-button/paper-icon-button.html"> |
| 20 | +<link rel="import" href="icons.html"> |
| 21 | + |
| 22 | +<dom-module id="pw-shell"> |
| 23 | + <style include="iron-flex iron-positioning"></style> |
| 24 | + <style> |
| 25 | + |
| 26 | + :host { |
| 27 | + display: block; |
| 28 | + margin-top: 64px; |
| 29 | + |
| 30 | + -moz-user-select: none; |
| 31 | + -ms-user-select: none; |
| 32 | + -webkit-user-select: none; |
| 33 | + |
| 34 | + --app-header-z-index: calc(1 + var(--base-z-index, 100)); |
| 35 | + --app-drawer-z-index: calc(2 + var(--base-z-index, 100)); |
| 36 | + } |
| 37 | + |
| 38 | + a { |
| 39 | + color: #999; |
| 40 | + text-decoration: none; |
| 41 | + } |
| 42 | + |
| 43 | + a.iron-selected { |
| 44 | + color: #333; |
| 45 | + } |
| 46 | + |
| 47 | + .drawer { |
| 48 | + display: none; |
| 49 | + z-index: var(--app-drawer-z-index); |
| 50 | + } |
| 51 | + |
| 52 | + .drawer-contents { |
| 53 | + height: 100%; |
| 54 | + overflow-y: auto; |
| 55 | + } |
| 56 | + |
| 57 | + .drawer-contents a, |
| 58 | + .drawer-contents img { |
| 59 | + display: block; |
| 60 | + padding: 16px; |
| 61 | + } |
| 62 | + |
| 63 | + .drawer-contents a.iron-selected { |
| 64 | + border-left: 4px solid #F22C5A; |
| 65 | + } |
| 66 | + |
| 67 | + .drawer-contents img { |
| 68 | + height: 24px; |
| 69 | + } |
| 70 | + |
| 71 | + .drawer-toggle { |
| 72 | + display: none; |
| 73 | + } |
| 74 | + |
| 75 | + .header { |
| 76 | + position: fixed; |
| 77 | + top: 0; |
| 78 | + right: 0; |
| 79 | + left: 0; |
| 80 | + background-color: #FFF; |
| 81 | + z-index: var(--app-header-z-index); |
| 82 | + } |
| 83 | + |
| 84 | + .header-toolbar { |
| 85 | + padding: 0 8px; |
| 86 | + } |
| 87 | + |
| 88 | + .header-toolbar .logo-link { |
| 89 | + padding: 16px 8px; |
| 90 | + height: 32px; |
| 91 | + } |
| 92 | + |
| 93 | + .header-toolbar .logo-link img { |
| 94 | + height: 32px; |
| 95 | + } |
| 96 | + |
| 97 | + .sections-tabs { |
| 98 | + height: 64px; |
| 99 | + padding: 0 8px; |
| 100 | + } |
| 101 | + |
| 102 | + .sections-tabs a { |
| 103 | + display: inline-block; |
| 104 | + margin: 0 12px; |
| 105 | + padding-top: 24px; |
| 106 | + height: 100%; |
| 107 | + box-sizing: border-box; |
| 108 | + } |
| 109 | + |
| 110 | + .sections-tabs a.iron-selected { |
| 111 | + border-bottom: 4px solid #F22C5A; |
| 112 | + } |
| 113 | + |
| 114 | + .search-box { |
| 115 | + width: 100%; |
| 116 | + height: 100%; |
| 117 | + padding: 0 12px; |
| 118 | + font-size: 16px; |
| 119 | + border: none; |
| 120 | + box-sizing: border-box; |
| 121 | + -webkit-transform: translate3d(100%, 0, 0); |
| 122 | + transform: translate3d(100%, 0, 0); |
| 123 | + transition: -webkit-transform 0.2s; |
| 124 | + transition: transform 0.2s; |
| 125 | + } |
| 126 | + |
| 127 | + .search-box:focus { |
| 128 | + -webkit-transform: translate3d(0, 0, 0); |
| 129 | + transform: translate3d(0, 0, 0); |
| 130 | + } |
| 131 | + |
| 132 | + /* Mobile viewports */ |
| 133 | + @media (max-width: 767px) { |
| 134 | + :host { |
| 135 | + margin-top: 56px; |
| 136 | + } |
| 137 | + |
| 138 | + .drawer { |
| 139 | + display: block; |
| 140 | + } |
| 141 | + |
| 142 | + .drawer-toggle { |
| 143 | + display: block; |
| 144 | + } |
| 145 | + |
| 146 | + .header-toolbar .logo-link { |
| 147 | + height: 24px; |
| 148 | + } |
| 149 | + |
| 150 | + .header-toolbar .logo-link img { |
| 151 | + height: 24px; |
| 152 | + } |
| 153 | + |
| 154 | + .sections-tabs { |
| 155 | + display: none; |
| 156 | + } |
| 157 | + } |
| 158 | + |
| 159 | + </style> |
| 160 | + |
| 161 | + <template> |
| 162 | + |
| 163 | + <carbon-location route="{{_sectionRoute}}"></carbon-location> |
| 164 | + <carbon-route route="{{_sectionRoute}}" pattern="/1.0/:section" data="{{_sectionData}}" tail="{{_subsectionRoute}}"></carbon-route> |
| 165 | + |
| 166 | + <!-- |
| 167 | + TODO: This will make a XHR request even for the first load, which we don't need since |
| 168 | + the light DOM will be pre-filled by the server-side templater (jinja) |
| 169 | + --> |
| 170 | + <iron-ajax url="[[_sectionRoute.path]]" handle-as="document" on-response="_handleResponse" auto></iron-ajax> |
| 171 | + |
| 172 | + <app-drawer id="drawer" class="drawer" swipe-open> |
| 173 | + <div class="drawer-contents"> |
| 174 | + <img src="../images/logos/p-logo.svg" alt="Polymer Logo"> |
| 175 | + |
| 176 | + <!-- |
| 177 | + TODO: Using iron-selector/carbon-route to highlight the current section may not work since |
| 178 | + sections may not follow this directory structure (e.g. start -> /1.0/docs/start/, but |
| 179 | + tools -> /1.0/tools/). The below links are hypothetical and will need to be changed. |
| 180 | + --> |
| 181 | + <iron-selector class="sections-list" attr-for-selected="name" activate-event="" selected="[[_sectionData.section]]" on-click="_closeDrawer"> |
| 182 | + <a href="/1.0/start/" name="start">Getting Started</a> |
| 183 | + <a href="/1.0/devguide/" name="devguide">Developer Guide</a> |
| 184 | + <a href="https://elements.polymer-project.org/" target="_blank" name="catalog">Element Catalog</a> |
| 185 | + <a href="/1.0/tools/" name="tools">Tools</a> |
| 186 | + <a href="/1.0/toolkits/" name="toolkits">Toolkits</a> |
| 187 | + <a href="/1.0/articles/" name="articles">Articles</a> |
| 188 | + </iron-selector> |
| 189 | + </div> |
| 190 | + </app-drawer> |
| 191 | + |
| 192 | + <app-header class="header" reveals snaps shadow> |
| 193 | + <div class="header-toolbar layout horizontal center"> |
| 194 | + <paper-icon-button class="drawer-toggle" icon="pw-icons:menu" on-click="_toggleDrawer"></paper-icon-button> |
| 195 | + |
| 196 | + <a href="/1.0/" class="logo-link"> |
| 197 | + <img src="../images/logos/p-logo.svg" alt="Polymer Logo"> |
| 198 | + </a> |
| 199 | + |
| 200 | + <div class="flex"></div> |
| 201 | + |
| 202 | + <iron-selector class="sections-tabs" attr-for-selected="name" activate-event="" selected="[[_sectionData.section]]"> |
| 203 | + <a href="/1.0/start/" name="start">Getting Started</a> |
| 204 | + <a href="/1.0/devguide/" name="devguide">Developer Guide</a> |
| 205 | + <a href="https://elements.polymer-project.org/" target="_blank" name="catalog">Element Catalog</a> |
| 206 | + <a href="/1.0/tools/" name="tools">Tools</a> |
| 207 | + <a href="/1.0/toolkits/" name="toolkits">Toolkits</a> |
| 208 | + <a href="/1.0/articles/" name="articles">Articles</a> |
| 209 | + </iron-selector> |
| 210 | + |
| 211 | + <paper-icon-button icon="pw-icons:search" on-click="_focusSearch" tabindex="-1"></paper-icon-button> |
| 212 | + </div> |
| 213 | + |
| 214 | + <input id="searchBox" type="search" class="search-box fit" placeholder="Search Polymer Site"> |
| 215 | + </app-header> |
| 216 | + |
| 217 | + <content></content> |
| 218 | + |
| 219 | + <footer> |
| 220 | + <div class="layout horizontal"> |
| 221 | + <div class="flex">© 2016 Polymer Authors.</div> |
| 222 | + <a href="#" on-click="_smoothScrollToTop">Back to Top</a> |
| 223 | + </div> |
| 224 | + </footer> |
| 225 | + </template> |
| 226 | + |
| 227 | + <script> |
| 228 | + Polymer({ |
| 229 | + is: 'pw-shell', |
| 230 | + |
| 231 | + _toggleDrawer: function() { |
| 232 | + this.$.drawer.toggle(); |
| 233 | + }, |
| 234 | + |
| 235 | + _closeDrawer: function() { |
| 236 | + this.$.drawer.close(); |
| 237 | + }, |
| 238 | + |
| 239 | + _focusSearch: function() { |
| 240 | + this.$.searchBox.focus(); |
| 241 | + }, |
| 242 | + |
| 243 | + _smoothScrollToTop: function() { |
| 244 | + Polymer.AppLayout.scroll({ behavior: 'smooth' }); |
| 245 | + }, |
| 246 | + |
| 247 | + _handleResponse: function(event) { |
| 248 | + var doc = event.detail.response; |
| 249 | + document.title = doc.title; |
| 250 | + Polymer.dom(this).innerHTML = doc.querySelector('pw-shell').innerHTML; |
| 251 | + this.async(this._resetScrollPosition); |
| 252 | + }, |
| 253 | + |
| 254 | + _resetScrollPosition: function() { |
| 255 | + // TODO: Need to scroll to element for hash links within the same page |
| 256 | + // (which don't cause a XHR). |
| 257 | + var hash = window.location.hash; |
| 258 | + if (hash) { |
| 259 | + var elem = document.querySelector(hash); |
| 260 | + if (elem) { |
| 261 | + elem.scrollIntoView(); |
| 262 | + return; |
| 263 | + } |
| 264 | + } |
| 265 | + |
| 266 | + Polymer.AppLayout.scroll(); |
| 267 | + } |
| 268 | + }); |
| 269 | + </script> |
| 270 | +</dom-module> |
0 commit comments