34 IriSP.Serializer.prototype.currentMedia = function() { |
34 IriSP.Serializer.prototype.currentMedia = function() { |
35 }; |
35 }; |
36 |
36 |
37 IriSP.Serializer.prototype.sync = function(callback) { |
37 IriSP.Serializer.prototype.sync = function(callback) { |
38 callback.apply(this, []); |
38 callback.apply(this, []); |
39 }; |
|
40 |
|
41 IriSP.JSONSerializer = function(DataLoader, url) { |
|
42 IriSP.Serializer.call(this, DataLoader, url); |
|
43 }; |
|
44 |
|
45 IriSP.JSONSerializer.prototype = IriSP.Serializer; |
|
46 |
|
47 IriSP.JSONSerializer.prototype.serialize = function(data) { |
|
48 return JSON.stringify(data); |
|
49 }; |
|
50 |
|
51 IriSP.JSONSerializer.prototype.deserialize = function(data) { |
|
52 return JSON.parse(data); |
|
53 }; |
|
54 |
|
55 IriSP.JSONSerializer.prototype.sync = function(callback) { |
|
56 /* we don't have to do much because jQuery handles json for us */ |
|
57 |
|
58 /* a wrapper to get a closure because we lose this in callbacks */ |
|
59 var wrapper = function(obj) { |
|
60 return function(data) { |
|
61 obj._data = data; |
|
62 // sort the data too |
|
63 obj._data["annotations"].sort(function(a, b) |
|
64 { var a_begin = +a.begin; |
|
65 var b_begin = +b.begin; |
|
66 return a_begin - b_begin; |
|
67 }); |
|
68 callback(data); |
|
69 } |
|
70 }; |
|
71 |
|
72 this._DataLoader.get(this._url, wrapper(this)); |
|
73 }; |
|
74 |
|
75 IriSP.JSONSerializer.prototype.currentMedia = function() { |
|
76 return this._data.medias[0]; /* FIXME: don't hardcode it */ |
|
77 }; |
39 }; |
78 |
40 |
79 IriSP.SerializerFactory = function(DataLoader) { |
41 IriSP.SerializerFactory = function(DataLoader) { |
80 this._dataloader = DataLoader; |
42 this._dataloader = DataLoader; |
81 }; |
43 }; |