提交 58ce3fd2 编写于 作者: C Catouse

* added methods to manage storage data of page to store.js.

上级 6c42b6e9
......@@ -10,13 +10,14 @@
if (typeof jQuery === "undefined") { throw new Error("ZUI requires jQuery") }
/* Store */
+function(window)
+function(window, $)
{
"use strict";
var lsName = 'localStorage';
var storage = window[lsName],
old = window['store'];
old = window['store'],
pageName = 'page_' + window.location.pathname;
/* The Store object */
var Store = function()
......@@ -24,6 +25,50 @@ if (typeof jQuery === "undefined") { throw new Error("ZUI requires jQuery") }
this.slience = true;
this.disabled = (lsName in window) && window[lsName] && window[lsName]['setItem'];
this.storage = storage;
var self = this;
this.page = this.get(pageName, {});
};
/* Save page data */
Store.prototype.savePage = function()
{
if($.isEmptyObject(this.page))
{
this.remove(pageName);
}
else
{
this.set(pageName, this.page);
}
};
/* Clear page data */
Store.prototype.clearPage = function()
{
this.page = {};
this.savePage();
};
/* Get page data */
Store.prototype.getPage = function(key, defaultValue)
{
var val = this.page[key];
return (defaultValue !== undefined && val === null) ? defaultValue : val;
};
/* Set page data */
Store.prototype.setPage = function(objOrKey, val)
{
if($.isPlanObject(objOrKey))
{
$.extend(true, this.page, objOrKey);
}
else
{
this.page[this.serialize(objOrKey)] = val;
}
this.savePage();
};
/* Check disabled status */
......@@ -155,7 +200,7 @@ if (typeof jQuery === "undefined") { throw new Error("ZUI requires jQuery") }
window.store = old;
return store;
}
}(window);
}(window, jQuery);
/*
* jQuery Hotkeys Plugin
......
......@@ -10,13 +10,14 @@
if (typeof jQuery === "undefined") { throw new Error("ZUI requires jQuery") }
/* Store */
+function(window)
+function(window, $)
{
"use strict";
var lsName = 'localStorage';
var storage = window[lsName],
old = window['store'];
old = window['store'],
pageName = 'page_' + window.location.pathname;
/* The Store object */
var Store = function()
......@@ -24,6 +25,50 @@ if (typeof jQuery === "undefined") { throw new Error("ZUI requires jQuery") }
this.slience = true;
this.disabled = (lsName in window) && window[lsName] && window[lsName]['setItem'];
this.storage = storage;
var self = this;
this.page = this.get(pageName, {});
};
/* Save page data */
Store.prototype.savePage = function()
{
if($.isEmptyObject(this.page))
{
this.remove(pageName);
}
else
{
this.set(pageName, this.page);
}
};
/* Clear page data */
Store.prototype.clearPage = function()
{
this.page = {};
this.savePage();
};
/* Get page data */
Store.prototype.getPage = function(key, defaultValue)
{
var val = this.page[key];
return (defaultValue !== undefined && val === null) ? defaultValue : val;
};
/* Set page data */
Store.prototype.setPage = function(objOrKey, val)
{
if($.isPlanObject(objOrKey))
{
$.extend(true, this.page, objOrKey);
}
else
{
this.page[this.serialize(objOrKey)] = val;
}
this.savePage();
};
/* Check disabled status */
......@@ -155,7 +200,7 @@ if (typeof jQuery === "undefined") { throw new Error("ZUI requires jQuery") }
window.store = old;
return store;
}
}(window);
}(window, jQuery);
/**
* Format string
......
此差异已折叠。
此差异已折叠。
/* Store */
+function(window)
+function(window, $)
{
"use strict";
var lsName = 'localStorage';
var storage = window[lsName],
old = window['store'];
old = window['store'],
pageName = 'page_' + window.location.pathname;
/* The Store object */
var Store = function()
......@@ -13,6 +14,50 @@
this.slience = true;
this.disabled = (lsName in window) && window[lsName] && window[lsName]['setItem'];
this.storage = storage;
var self = this;
this.page = this.get(pageName, {});
};
/* Save page data */
Store.prototype.savePage = function()
{
if($.isEmptyObject(this.page))
{
this.remove(pageName);
}
else
{
this.set(pageName, this.page);
}
};
/* Clear page data */
Store.prototype.clearPage = function()
{
this.page = {};
this.savePage();
};
/* Get page data */
Store.prototype.getPage = function(key, defaultValue)
{
var val = this.page[key];
return (defaultValue !== undefined && val === null) ? defaultValue : val;
};
/* Set page data */
Store.prototype.setPage = function(objOrKey, val)
{
if($.isPlanObject(objOrKey))
{
$.extend(true, this.page, objOrKey);
}
else
{
this.page[this.serialize(objOrKey)] = val;
}
this.savePage();
};
/* Check disabled status */
......@@ -144,4 +189,4 @@
window.store = old;
return store;
}
}(window);
}(window, jQuery);
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册