Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Updates for IE userdata adapter.

 - Call callback in init()
 - Use this.fn for callbacks.
 - Whitespace fixes.

Passes all unit tests in IE6+ except batch operations (currently unimplemented).
  • Loading branch information...
commit a556d717cc09b6eea922b5eba678aba1947bc695 1 parent ec66be5
Niall Smart niallsmart authored
Showing with 25 additions and 20 deletions.
  1. +25 −20 src/adapters/ie-userdata.js
45 src/adapters/ie-userdata.js
View
@@ -3,10 +3,12 @@
*
*/
Lawnchair.adapter('ie-userdata', {
- valid: function () {
- return typeof(document.body.addBehavior) != 'undefined';
- },
- init:function(){
+
+ valid: function () {
+ return typeof(document.body.addBehavior) != 'undefined';
+ },
+
+ init:function(options, callback){
var s = document.createElement('span');
s.style.behavior = 'url(\'#default#userData\')';
s.style.position = 'absolute';
@@ -14,17 +16,17 @@ Lawnchair.adapter('ie-userdata', {
document.body.appendChild(s);
this.storage = s;
this.storage.load('lawnchair');
+ this.fn(this.name, callback).call(this, this)
},
get:function(key, callback){
var obj = JSON.parse(this.storage.getAttribute(key) || 'null');
- if (obj) {
- obj.key = key;
-
- }
- if (callback)
- callback(obj);
+ if (obj) {
+ obj.key = key;
+ }
+ if (callback) this.lambda(callback).call(this, obj)
+ return this;
},
save:function(obj, callback){
@@ -32,10 +34,11 @@ Lawnchair.adapter('ie-userdata', {
delete obj.key;
this.storage.setAttribute(id, JSON.stringify(obj));
this.storage.save('lawnchair');
- if (callback){
- obj.key = id;
- callback(obj);
- }
+ obj.key = id;
+ if (callback) {
+ this.lambda(callback).call(this, obj)
+ }
+ return this;
},
all:function(callback){
@@ -51,16 +54,18 @@ Lawnchair.adapter('ie-userdata', {
yar.push(o);
}
}
- if (callback)
- callback(yar);
+ if (callback) this.fn(this.name, callback).call(this, yar)
+ return this;
},
+
remove:function(keyOrObj,callback) {
var key = (typeof keyOrObj == 'string') ? keyOrObj : keyOrObj.key;
this.storage.removeAttribute(key);
this.storage.save('lawnchair');
- if(callback)
- callback();
+ if (callback) this.lambda(callback).call(this)
+ return this;
},
+
nuke:function(callback) {
var that = this;
this.all(function(r){
@@ -68,8 +73,8 @@ Lawnchair.adapter('ie-userdata', {
if (r[i].key)
that.remove(r[i].key);
}
- if(callback)
- callback();
+ if (callback) that.lambda(callback).call(that)
});
+ return this;
}
});
Please sign in to comment.
Something went wrong with that request. Please try again.