Commit c72fbd99 authored by Ivan Tyagov's avatar Ivan Tyagov

Remove dependency on jStorage for RenderJs and use directly localStorage.

Add documentation link.
parent e2f63b29
/*global console, require, $, localStorage, document */
/*
* RenderJs - Generic Gadget library renderer.
* http://www.renderjs.org/documentation
*/
// by default RenderJs will render all gadgets when page is loaded
// still it's possible to override this and use explicit gadget rendering
var RENDERJS_ENABLE_IMPLICIT_GADGET_RENDERING = true;
// Add required by RenderJs jstorage library only if used HTML application
// uses requirejs
if (typeof require !== 'undefined') {
require(["../../../../lib/jstorage/jstorage.js"], function (util) {
});
// example of how we can use requirejs to load external libraries
//require(["../../../../lib/jstorage/jstorage.js"], function (util) {
//});
}
// fallback for IE
if (typeof console === "undefined" || typeof console.log === "undefined") {
console = {};
console.log = function () {};
console = {};
console.log = function () {};
}
/*
* Generic Gadget library renderer
*/
var RenderJs = (function () {
// a variable indicating if current gadget loading is over or not
var is_ready = false;
......@@ -281,12 +282,17 @@ var RenderJs = (function () {
return {
get: function (cache_id, default_value) {
/* Get cache key value */
return $.jStorage.get(cache_id, default_value);
if (cache_id in localStorage) {
return JSON.parse(localStorage.getItem(cache_id));
}
else {
return default_value;
}
},
set: function (cache_id, data) {
/* Set cache key value */
$.jStorage.set(cache_id, data);
localStorage.setItem(cache_id, JSON.stringify(data));
}
};
}()),
......
......@@ -23,6 +23,8 @@ function setupRenderJSTest(){
data = {'gg':1};
RenderJs.Cache.set(cache_id, data);
deepEqual(data, RenderJs.Cache.get(cache_id));
// test return default value if key is missing works
equal("no such key", RenderJs.Cache.get("no_such_key", "no such key"));
});
module("GadgetIndex");
......@@ -73,7 +75,7 @@ function setupRenderJSTest(){
cleanUp();
RenderJs.addGadget("qunit-fixture", "interactions/index.html", "", "");
stop();
// we need to wait for all gadgets loading ...
window.setTimeout(function () {
RenderJs.InteractionGadget.bind($("#main-interactor"));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment