Skip to content

Commit

Permalink
Mod: update sticky.js to 2.9
Browse files Browse the repository at this point in the history
Old version, 2.8, doesn't work with latest Chrome version.
See #29
  • Loading branch information
eunomie committed Mar 18, 2013
1 parent fd9d984 commit 14fad21
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
2 changes: 1 addition & 1 deletion app/assets/javascripts/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
//= require jquery
//= require jquery_ujs
//= require jquery.cookie
//= require sticky-2.8
//= require sticky-2.9
//= require underscore
//= require backbone
//= require backbone-relational
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Sticky
*
* Version 2.8
* Version 2.9
* Copyright 2011 Alexander C. Mingoia
* MIT Licensed
*
Expand Down Expand Up @@ -388,13 +388,8 @@ StickyStore.prototype.adapters = {'indexedDB':{}, 'webSQL':{}, 'localStorage':{}
StickyStore.prototype.adapters.indexedDB.init = (function(callback) {
var store = this;

// backwards compatibility
if ('mozIndexedDB' in window) {
window.indexedDB = window.mozIndexedDB;
}
if ('webkitIndexedDB' in window) {
window.indexedDB = window.webkitIndexedDB;
window.IDBTransaction = window.webkitIDBTransaction;
if (window) {
StickyStore.prototype.IndexedDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB || window.msIndexedDB;
}

// Method to create objectStore
Expand All @@ -408,9 +403,9 @@ StickyStore.prototype.adapters.indexedDB.init = (function(callback) {
}
};

if (window.indexedDB) {
if (StickyStore.prototype.IndexedDB) {
// Request to open database
var request = window.indexedDB.open(store.options.name, 20);
var request = StickyStore.prototype.IndexedDB.open(store.options.name, 20);

request.onsuccess = function(event) {
// FF is event.target.result, Chrome is event.target.result.db
Expand Down Expand Up @@ -455,7 +450,7 @@ StickyStore.prototype.adapters.indexedDB.init = (function(callback) {

StickyStore.prototype.adapters.indexedDB.get = (function(key, callback) {
var store = this;
var tx = store.adapters.indexedDB.io.transaction([store.options.name], IDBTransaction.READ_ONLY);
var tx = store.adapters.indexedDB.io.transaction([store.options.name], "readonly");
var objStore = tx.objectStore(store.options.name);
var request = objStore.get(key);
request.onsuccess = function(event) {
Expand Down Expand Up @@ -486,7 +481,7 @@ StickyStore.prototype.adapters.indexedDB.get = (function(key, callback) {

StickyStore.prototype.adapters.indexedDB.set = (function(key, item, callback) {
var store = this;
var tx = store.adapters.indexedDB.io.transaction([store.options.name], IDBTransaction.READ_WRITE);
var tx = store.adapters.indexedDB.io.transaction([store.options.name], "readwrite");
var objStore = tx.objectStore(store.options.name);
var request = objStore.put({'key': key, 'data': item});
request.onsuccess = function(e) {
Expand All @@ -509,7 +504,7 @@ StickyStore.prototype.adapters.indexedDB.set = (function(key, item, callback) {

StickyStore.prototype.adapters.indexedDB.remove = (function(key, callback) {
var store = this;
var tx = store.adapters.indexedDB.io.transaction([store.options.name], IDBTransaction.READ_WRITE);
var tx = store.adapters.indexedDB.io.transaction([store.options.name], "readwrite");
var request = tx.objectStore(store.options.name)['delete'](key);
request.onsuccess = function(e) {
callback && callback.call(store, true);
Expand All @@ -529,7 +524,7 @@ StickyStore.prototype.adapters.indexedDB.remove = (function(key, callback) {

StickyStore.prototype.adapters.indexedDB.removeAll = (function(callback) {
var store = this;
var tx = store.adapters.indexedDB.io.transaction([store.options.name], IDBTransaction.READ_WRITE);
var tx = store.adapters.indexedDB.io.transaction([store.options.name], "readwrite");
var request = tx.objectStore(store.options.name).clear();
request.onsuccess = function(e) {
callback && callback.call(store, true);
Expand Down Expand Up @@ -868,7 +863,7 @@ StickyStore.prototype.adapters.cookie.get = (function(key, callback) {
this.trigger('error', 'Key cannot contain special characters when persisting to cookies. Only A-z, 0-9, and _ are allowed.', key);
}
if (item) {
item = this.unserialize(item);
item = this.unserialize(decodeURIComponent(item));
callback && callback.call(this, item);
return item;
}
Expand All @@ -891,7 +886,7 @@ StickyStore.prototype.adapters.cookie.get = (function(key, callback) {
*/

StickyStore.prototype.adapters.cookie.set = (function(key, item, callback) {
var value = this.serialize(item);
var value = encodeURIComponent(this.serialize(item));
if (((value.length + key.length) - 100) > 4000) {
this.trigger('error', 'Serialized value too large for cookie storage', key);
}
Expand Down

0 comments on commit 14fad21

Please sign in to comment.