1 // Copyright 2007, Google Inc.
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are met:
6 // 1. Redistributions of source code must retain the above copyright notice,
7 // this list of conditions and the following disclaimer.
8 // 2. Redistributions in binary form must reproduce the above copyright notice,
9 // this list of conditions and the following disclaimer in the documentation
10 // and/or other materials provided with the distribution.
11 // 3. Neither the name of Google Inc. nor the names of its contributors may be
12 // used to endorse or promote products derived from this software without
13 // specific prior written permission.
15 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
16 // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
17 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
18 // EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 // Change this to set the name of the managed resource store to create.
27 // You use the name with the createManagedStore, and removeManagedStore,
28 // and openManagedStore APIs. It isn't visible to the user.
29 var STORE_NAME = "my_offline_docset";
30 var DB_NAME = "mdl_offline_db";
32 // Change this to set the URL of tha manifest file, which describe which
33 // URLs to capture. It can be relative to the current page, or an
35 var MANIFEST_FILENAME = "offlinemanifest.json";
41 // Called onload to initialize local server, store variables, and local database
43 if (!window.google || !google.gears) {
44 textOut("NOTE: You must install Gears first.");
46 localServer = google.gears.factory.create("beta.localserver");
47 store = localServer.createManagedStore(STORE_NAME);
48 db = google.gears.factory.create('beta.database', '1.0');
49 textOut("Yeay, Gears is already installed.");
53 // Create the managed resource store
54 function createStore() {
55 if (!window.google || !google.gears) {
56 alert("You must install Gears first.");
60 store.manifestUrl = MANIFEST_FILENAME;
61 store.checkForUpdate();
63 var timerId = window.setInterval(function() {
64 // When the currentVersion property has a value, all of the resources
65 // listed in the manifest file for that version are captured. There is
66 // an open bug to surface this state change as an event.
67 if (store.currentVersion) {
68 window.clearInterval(timerId);
69 textOut("The documents are now available offline.\n" +
70 "With your browser offline, load the document at " +
71 "its normal online URL to see the locally stored " +
72 "version. The version stored is: " +
73 store.currentVersion);
74 } else if (store.updateStatus == 3) {
75 textOut("Error: " + store.lastErrorMessage);
80 // Remove the managed resource store.
81 function removeStore() {
82 if (!window.google || !google.gears) {
83 alert("You must install Gears first.");
87 localServer.removeManagedStore(STORE_NAME);
88 textOut("Done. The local store has been removed." +
89 "You will now see online versions of the documents.");
92 // Utility function to output some status text.
94 var elm = document.getElementById("textOut");
95 while (elm.firstChild) {
96 elm.removeChild(elm.firstChild);
98 elm.appendChild(document.createTextNode(s));