diff options
author | Matěj Cepl <mcepl@redhat.com> | 2010-01-13 00:21:23 +0100 |
---|---|---|
committer | Matěj Cepl <mcepl@redhat.com> | 2010-01-13 00:21:23 +0100 |
commit | 5333869aac2dbd71c91727dbca6aee1a46b3cdb1 (patch) | |
tree | fccd59b1c901393c13c63ab12db9c8db4dd7c113 /offline-submit/john-resig-offline-app-stub.js | |
parent | 7ae28278cf7f4920175058971dee2b06b0e331b8 (diff) | |
download | bugzilla-triage-5333869aac2dbd71c91727dbca6aee1a46b3cdb1.tar.gz |
Starting to work on the offline capabilities.
Diffstat (limited to 'offline-submit/john-resig-offline-app-stub.js')
-rw-r--r-- | offline-submit/john-resig-offline-app-stub.js | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/offline-submit/john-resig-offline-app-stub.js b/offline-submit/john-resig-offline-app-stub.js new file mode 100644 index 0000000..b9d6160 --- /dev/null +++ b/offline-submit/john-resig-offline-app-stub.js @@ -0,0 +1,43 @@ +// stub for the offline application in pseudocode +// from http://ejohn.org/blog/offline-events/ + +function saveData( item ){ + if ( navigator.onLine ) { + saveToServer( item ); + } else { + toSave.push( item ); + } +} + +function loadData( item ){ + if ( navigator.onLine ) { + return loadFromServer( item ); + } else { + var result = loadFromQueue( item ); + if ( !result ) { + displayError(); + toLoad.push( item ); + } + return result; + } +} + +setInterval(function(){ + if ( navigator.onLine ) { + var item = predictNextItemToBeLoaded(); + loadData( item ); + } +}, 5000); + +window.ononline = function(){ + toSave.forEach( saveData ); + toLoad.forEach( loadData ); +}; + +window.onload = function(){ + document.getElementById("myform").onsubmit = function(){ + saveData( this ); + return false; + }; +}; + |