Permalink
Browse files

cleaned up for demo

  • Loading branch information...
1 parent ad89b4e commit 219cf650603d601ad9840dffa4193b29d29e209e @p-m-p committed Feb 11, 2012
Showing with 78 additions and 17 deletions.
  1. +12 −0 css/style.css
  2. +25 −11 index.php
  3. +29 −6 js/sync.js
  4. +12 −0 sync.appcache:
View
@@ -45,3 +45,15 @@ li a {
background: url(images/sync.png);
display: none;
}
+
+#no-support {
+ background-color: red;
+ padding: 6px 0;
+ text-align: center;
+ color: white;
+ display: none;
+}
+
+#no-support a {
+ color: white;
+}
View
@@ -6,6 +6,12 @@
</head>
<body>
+ <div id="no-support">
+ Your browser doesn't support this demo, you'll need to
+ grab the latest version of <a href="http://www.google.co.uk/chrome">
+ Google Chrome</a> to be sure it will work.
+ </div>
+
<ol id="dir-tree">
<?php include 'file-list.php'; ?>
@@ -16,17 +22,25 @@
<script src="js/sync.js"></script>
<script>
- window.requestFileSystem || (
- window.requestFileSystem = window.webkitRequestFileSystem
- );
- window.webkitStorageInfo.requestQuota(PERSISTENT, 5*1024*1024, function(gb) {
- window.requestFileSystem(
- window.PERSISTENT
- , gb
- , fileSync.init
- , fileSync.err
- );
- }, fileSync.err);
+ (function (w) {
+
+ if (typeof w.webkitRequestFileSystem === 'undefined') {
+
+ document.getElemntById('no-support').style.display = 'block';
+ return;
+
+ }
+
+ w.webkitStorageInfo.requestQuota(w.PERSISTENT, 5*1024*1024, function(gb) {
+ w.webkitRequestFileSystem(
+ w.PERSISTENT
+ , gb
+ , fileSync.init
+ , fileSync.err
+ );
+ }, fileSync.err);
+
+ })(window);
</script>
</html>
View
@@ -29,6 +29,7 @@ window.fileSync = (function (w) {
};
+ // get the latest list of files from the server
api.refreshFiles = function () {
var xhr = new XMLHttpRequest;
@@ -104,7 +105,15 @@ window.fileSync = (function (w) {
}
else if (t.className.indexOf('open') !== -1) {
- api.open(name);
+
+ if (t.className.indexOf('synced') === -1) {
+ api.pull(t.href, name, true);
+ }
+
+ else {
+ api.open(name);
+ }
+
}
ev.preventDefault();
@@ -115,7 +124,7 @@ window.fileSync = (function (w) {
// pull file down into local
- api.pull = function (url, name) {
+ api.pull = function (url, name, open) {
var xhr = new XMLHttpRequest;
@@ -132,7 +141,13 @@ window.fileSync = (function (w) {
var bb = new w.WebKitBlobBuilder;
writer.onwriteend = function () {
- api.flagSynced(fe)
+
+ api.flagSynced(fe);
+
+ if (open) {
+ api.open(name);
+ }
+
}
writer.onerror = api.err;
@@ -152,11 +167,19 @@ window.fileSync = (function (w) {
api.open = function (name) {
- root.getFile(name, {}, function (fe) {
+ if (typeof name === 'string') {
+
+ root.getFile(name, {}, function (fe) {
- w.location = fe.toURL();
+ w.location = fe.toURL();
- }, api.err);
+ }, api.err);
+
+ }
+
+ else {
+ w.location = name.toURL();
+ }
};
View
@@ -0,0 +1,12 @@
+CACHE MANIFEST
+
+
+NETWORK:
+file-list.php
+/demos/fs
+
+CACHE:
+index.php
+css/style.css
+css/images/sync.png
+js/sync.js

0 comments on commit 219cf65

Please sign in to comment.