/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ define(['jquery', 'backbone'], function ($, Backbone) { var Images = { prefix: "images", getThumb: function (id) { var val = this._get(id); if(val.thumb !== "") return val.thumb; var response = $.ajax({ url: myManifest.Settings.DefaultURL + "/api/photo/thumbnail/" + id + "/1", type: 'GET', async: false }).responseText; val.thumb = response; this._set(id, val); return val.thumb; }, getMedium: function (id) { var val = this._get(id); if(val.medium !== "") return val.medium; var response = $.ajax({ url: myManifest.Settings.DefaultURL + "/api/photo/medium/" + id + "/1", type: 'GET', async: false }).responseText; val.medium = response; this._set(id, val); return val.medium; }, getFull: function (id) { var val = this._get(id); if(val.full !== "") return val.full; var response = $.ajax({ url: myManifest.Settings.DefaultURL + "/api/photo/" + id + "/1", type: 'GET', async: false }).responseText; val.full = response; this._set(id, val); return val.full; }, _set:function(id, item){ var list = JSON.parse(window.localStorage.getItem(this.prefix)); if(list !== null) { list[id] = item; window.localStorage.setItem(this.prefix, JSON.stringify(list)); } }, _get:function(id){ var ret = null; var item = JSON.parse(window.localStorage.getItem(this.prefix)); if(item === null){ item = {}; window.localStorage.setItem(this.prefix, JSON.stringify(item)); ret = { thumb: "", medium: "", full:""}; } else if(item[id] === undefined){ ret = { thumb: "", medium: "", full:""}; } else{ ret = item[id]; } return ret; } }; return Images; });