src/js/data.js
branchpopcorn-port
changeset 247 69bc26f879e6
parent 184 a4be54204b71
child 248 fc01dc03f135
equal deleted inserted replaced
246:533716922da5 247:69bc26f879e6
     2 
     2 
     3 IriSP.DataLoader = function() {
     3 IriSP.DataLoader = function() {
     4   this._cache = {};
     4   this._cache = {};
     5 };
     5 };
     6 
     6 
     7 IriSP.DataLoader.prototype.get = function(url, callback) {  
     7 IriSP.DataLoader.prototype.get = function(url, callback) {
       
     8 
       
     9   var base_url = url.split("&")[0]
     8   if (this._cache.hasOwnProperty(url)) {
    10   if (this._cache.hasOwnProperty(url)) {
     9     callback(this._cache[url]);
    11     callback(this._cache[base_url]);
    10   } else {
    12   } else {
    11     /* we need a closure because this gets lost when it's called back */
    13     /* we need a closure because this gets lost when it's called back */
    12     IriSP.jQuery.get(url, callback);  
    14     // uncomment you don't want to use caching.
    13     /*
    15     // IriSP.jQuery.get(url, callback);
       
    16     
    14     IriSP.jQuery.get(url, (function(obj) {      
    17     IriSP.jQuery.get(url, (function(obj) {      
    15                                return function(data) {
    18                                return function(data) {
    16                                   obj._cache[url] = data;      
    19                                   obj._cache[base_url] = data;      
    17                                   callback(obj._cache[url]);
    20                                   callback(obj._cache[base_url]);
    18                                 }; 
    21                                 }; 
    19                               })(this));
    22                               })(this));
    20     */
    23     
    21        
    24        
    22   }
    25   }
    23 }
    26 }
    24 
    27 
    25 /* the base abstract "class" */
    28 /* the base abstract "class" */