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...
1 parent ec66be5 commit a556d717cc09b6eea922b5eba678aba1947bc695 Niall Smart committed Sep 23, 2011
Showing with 25 additions and 20 deletions.
  1. +25 −20 src/adapters/ie-userdata.js
View
45 src/adapters/ie-userdata.js
@@ -3,39 +3,42 @@
*
*/
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';
s.style.left = 10000;
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){
var id = obj.key || 'lc' + this.uuid();
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,25 +54,27 @@ 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){
for (var i = 0, l = r.length; i < l; i++) {
if (r[i].key)
that.remove(r[i].key);
}
- if(callback)
- callback();
+ if (callback) that.lambda(callback).call(that)
});
+ return this;
}
});

0 comments on commit a556d71

Please sign in to comment.