OLD | NEW |
(Empty) | |
| 1 <!doctype html> |
| 2 <!-- |
| 3 Copyright (c) 2015 The Polymer Project Authors. All rights reserved. |
| 4 This code may only be used under the BSD style license found at http://polymer.g
ithub.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/CONTRI
BUTORS.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/PATEN
TS.txt |
| 9 --> |
| 10 <html> |
| 11 <head> |
| 12 <meta charset="utf-8"> |
| 13 <meta name="viewport" content="width=device-width, initial-scale=1"> |
| 14 <title>Platinum Service Worker Elements Demo</title> |
| 15 |
| 16 <script src="../../fetch/fetch.js"></script> |
| 17 <script src="../../webcomponentsjs/webcomponents-lite.min.js"></script> |
| 18 <link rel="import" href="../platinum-sw-elements.html"> |
| 19 <link rel="import" href="../../marked-element/marked-element.html"> |
| 20 </head> |
| 21 |
| 22 <body> |
| 23 <template is="dom-bind" id="page-template"> |
| 24 <platinum-sw-register skip-waiting |
| 25 clients-claim |
| 26 reload-on-install |
| 27 state="{{state}}"> |
| 28 <platinum-sw-cache default-cache-strategy="networkFirst" |
| 29 precache="{{precacheList}}"></platinum-sw-cache> |
| 30 </platinum-sw-register> |
| 31 |
| 32 <h1>Platinum Service Worker Elements Demo</h1> |
| 33 <p>This is a simple offline-capable eBook reader.</p> |
| 34 <p> |
| 35 On browsers that support service workers, this page itself and all the b
ooks are all |
| 36 available offline, by virtue of the <code><platinum-sw-register></cod
e> and |
| 37 <code><platinum-sw-cache></code> elements. |
| 38 </p> |
| 39 <p> |
| 40 Service workers are meant to be a progressive enhancement, and browsers
that lack service |
| 41 worker support will still have a functional (online-only) eBook reader. |
| 42 </p> |
| 43 |
| 44 <template is="dom-if" if="[[state]]"> |
| 45 <select on-change="selectBook"> |
| 46 <option disabled selected>Select a Book...</option> |
| 47 <template is="dom-repeat" id="books" items="[[books]]"> |
| 48 <option>{{item.title}}</option> |
| 49 </template> |
| 50 </select> |
| 51 </template> |
| 52 |
| 53 <marked-element markdown="{{text}}"></marked-element> |
| 54 </template> |
| 55 |
| 56 <script> |
| 57 var t = document.querySelector('#page-template'); |
| 58 |
| 59 t.books = [{ |
| 60 title: 'Don Quixote', |
| 61 url: 'https://cdn.rawgit.com/GITenberg/Don-Quixote_996/master/996.txt' |
| 62 }, { |
| 63 title: 'Dubliners', |
| 64 url: 'https://cdn.rawgit.com/GITenberg/Dubliners_2814/master/2814.txt' |
| 65 }, { |
| 66 title: 'Pride & Prejudice', |
| 67 url: 'https://cdn.rawgit.com/GITenberg/Pride-and-Prejudice_1342/master/1
342.txt' |
| 68 }]; |
| 69 |
| 70 t.precacheList = t.books.map(function(book) { |
| 71 return book.url; |
| 72 }); |
| 73 |
| 74 t.selectBook = function(e) { |
| 75 var books = document.querySelector('#books'); |
| 76 var selectedBook = books.itemForElement(e.target.selectedOptions[0]); |
| 77 window.fetch(selectedBook.url).then(function(response) { |
| 78 return response.text(); |
| 79 }).then(function(text) { |
| 80 t.text = text; |
| 81 }); |
| 82 }; |
| 83 |
| 84 window.addEventListener('WebComponentsReady', function() { |
| 85 // Explicitly call the register() method. We need to wait until the temp
late's variables are |
| 86 // all set first, since the configuration depends on bound variables. |
| 87 document.querySelector('platinum-sw-register').register(); |
| 88 }); |
| 89 </script> |
| 90 </body> |
| 91 </html> |
OLD | NEW |