Skip to content

Commit

Permalink
update owl to work with 0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
sheppard committed Sep 16, 2015
1 parent 490b461 commit 7827f44
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
46 changes: 42 additions & 4 deletions js/wq/owl.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* https://wq.io/license
*/

define(['wq/store', 'jquery', 'jquery.mobile'],
function(ds, $) {
define(['jquery', 'jquery.mobile'],
function($) {

var _referer = document.referrer;

Expand Down Expand Up @@ -48,7 +48,41 @@ function owl(action, data, path) {
}

owl.config = {};
owl.ds = ds.getStore('owl');
owl.ds = {
'ls': (function() {
var store;
try {
store = window.localStorage;
store.setItem('owltest', '1');
if (store.getItem('owltest') != '1') {
store = {};
}
} catch(e) {
store = {};
}
return store;
})(),
'get': function(key) {
var val = this.ls['owl_' + key];
return val && JSON.parse(val);
},
'set': function(key, val) {
if (val === null) {
delete this.ls['owl_' + key];
} else {
this.ls['owl_' + key] = JSON.stringify(val);
}
},
'keys': function() {
var keys = [];
for (var key in this.ls) {
if (key.match(/^owl_/)) {
keys.push(key.replace(/^owl_/, ''));
}
}
return keys;
}
};

// Initiallize configuration and set up event listeners
owl.init = function init(config) {
Expand Down Expand Up @@ -101,6 +135,10 @@ owl.init = function init(config) {
}
};

// wq/app.js plugin compat
owl.name = 'owl';
owl.run = function() {};

// Sync log to server (with logic to handle errors & prevent simultaneous sync)
var _syncing = {};
var _waiting = {};
Expand Down Expand Up @@ -149,6 +187,7 @@ owl.sync = function sync(key, forceSync) {
queue.forEach(function(d) {
d.client_key = key;
});
owl.ds.set(key, queue);

var async = !forceSync;

Expand Down Expand Up @@ -244,7 +283,6 @@ owl.stats = function() {
'scroll': owl.events.scrollstop(),

// Cache status
'localstorage': ds.localStorageUsage(),
'appcache': (
window.applicationCache ? window.applicationCache.status : null
)
Expand Down
5 changes: 3 additions & 2 deletions tests/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ requirejs.config({
}
});

require(['wq/app', 'wq/map', 'app/config', 'leaflet.draw'],
function(app, map, config) {
require(['wq/app', 'wq/map', 'wq/owl', 'app/config', 'leaflet.draw'],
function(app, map, owl, config) {
config.jqmInit = true;
app.use(map);
app.use(owl);
app.init(config);
});

0 comments on commit 7827f44

Please sign in to comment.