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.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
12
<meta charset="utf-8">
13
<meta name="viewport" content="width=device-width, initial-scale=1">
14
<title>Platinum Service Worker Elements Demo</title>
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">
23
<template is="dom-bind" id="page-template">
24
<platinum-sw-register skip-waiting
28
<platinum-sw-cache default-cache-strategy="networkFirst"
29
precache="{{precacheList}}"></platinum-sw-cache>
30
</platinum-sw-register>
32
<h1>Platinum Service Worker Elements Demo</h1>
33
<p>This is a simple offline-capable eBook reader.</p>
35
On browsers that support service workers, this page itself and all the books are all
36
available offline, by virtue of the <code><platinum-sw-register></code> and
37
<code><platinum-sw-cache></code> elements.
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.
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>
53
<marked-element markdown="{{text}}"></marked-element>
57
var t = document.querySelector('#page-template');
61
url: 'https://cdn.rawgit.com/GITenberg/Don-Quixote_996/master/996.txt'
64
url: 'https://cdn.rawgit.com/GITenberg/Dubliners_2814/master/2814.txt'
66
title: 'Pride & Prejudice',
67
url: 'https://cdn.rawgit.com/GITenberg/Pride-and-Prejudice_1342/master/1342.txt'
70
t.precacheList = t.books.map(function(book) {
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) {
84
window.addEventListener('WebComponentsReady', function() {
85
// Explicitly call the register() method. We need to wait until the template's variables are
86
// all set first, since the configuration depends on bound variables.
87
document.querySelector('platinum-sw-register').register();