src/js/data.js
branchpopcorn-port
changeset 842 4ae2247a59f4
parent 453 8568e47379a2
child 859 002a16ff171b
equal deleted inserted replaced
841:8da49ff273e0 842:4ae2247a59f4
    10     received yet.
    10     received yet.
    11   */
    11   */
    12   this._callbacks = {};
    12   this._callbacks = {};
    13 };
    13 };
    14 
    14 
    15 IriSP.DataLoader.prototype.get = function(url, callback) {
    15 IriSP.DataLoader.prototype.get = function(url, callback, force_reload) {
    16 
    16   var base_url = url.split("&")[0];
    17   var base_url = url.split("&")[0]
    17   if (typeof force_reload != "undefined" && force_reload && this._cache.hasOwnProperty(base_url)) {
       
    18       delete this._cache[base_url]
       
    19   }
    18   if (this._cache.hasOwnProperty(base_url)) {
    20   if (this._cache.hasOwnProperty(base_url)) {
    19     callback(this._cache[base_url]);
    21     callback(this._cache[base_url]);
    20   } else {  
    22   } else {  
    21     if (!this._callbacks.hasOwnProperty(base_url)) {
    23     if (!this._callbacks.hasOwnProperty(base_url)) {
    22       this._callbacks[base_url] = [];
    24       this._callbacks[base_url] = [callback];
    23       this._callbacks[base_url].push(callback);   
       
    24       /* we need a closure because this gets lost when it's called back */
    25       /* we need a closure because this gets lost when it's called back */
    25   
    26   
    26       // uncomment you don't want to use caching.
    27       // uncomment you don't want to use caching.
    27       // IriSP.jQuery.get(url, callback);
    28       // IriSP.jQuery.get(url, callback);
    28       
    29       
    31                   var i = 0;
    32                   var i = 0;
    32                   
    33                   
    33                   for (i = 0; i < this._callbacks[base_url].length; i++) {
    34                   for (i = 0; i < this._callbacks[base_url].length; i++) {
    34                     this._callbacks[base_url][i](this._cache[base_url]);                                  
    35                     this._callbacks[base_url][i](this._cache[base_url]);                                  
    35                   }
    36                   }
       
    37                   delete this._callbacks[base_url];
    36       };
    38       };
    37       
    39       
    38       /* automagically choose between json and jsonp */
    40       /* automagically choose between json and jsonp */
    39       if (url.indexOf(document.location.hostname) === -1 &&
    41       if (url.indexOf(document.location.hostname) === -1 &&
    40           url.indexOf("http://") !== -1 /* not a relative url */ ) {
    42           url.indexOf("http://") !== -1 /* not a relative url */ ) {
    68 IriSP.Serializer.prototype.deserialize = function(data) {};
    70 IriSP.Serializer.prototype.deserialize = function(data) {};
    69 
    71 
    70 IriSP.Serializer.prototype.currentMedia = function() {  
    72 IriSP.Serializer.prototype.currentMedia = function() {  
    71 };
    73 };
    72 
    74 
    73 IriSP.Serializer.prototype.sync = function(callback) {  
    75 IriSP.Serializer.prototype.getDuration = function() {  
    74   callback.call(this, this._data);  
    76 };
       
    77 
       
    78 IriSP.Serializer.prototype.sync = function(callback) {
       
    79   this._DataLoader.get(this._url, callback, force_refresh);
    75 };
    80 };
    76 
    81 
    77 IriSP.SerializerFactory = function(DataLoader) {
    82 IriSP.SerializerFactory = function(DataLoader) {
    78   this._dataloader = DataLoader;
    83   this._dataloader = DataLoader;
    79 };
    84 };