feature(dom) Cache -> Storage

This commit is contained in:
coderaiser 2013-11-20 09:41:20 +00:00
parent d13f610f16
commit 5511c6678c
8 changed files with 63 additions and 63 deletions

View file

@ -115,12 +115,12 @@ body {
transition: ease 0.1s;
}
.clear-cache {
.clear-storage {
margin-right: 6px;
margin-left: 7px;
background:url(/img/console_clear.png) -4px -4px no-repeat;
}
.clear-cache:active {
.clear-storage:active {
top:5px;
}

View file

@ -1 +1 @@
<li class=path><span class="path-icon clear-cache" id=clear-cache title="clear cache (Ctrl+D)"></span><span class="path-icon refresh-icon" title="refresh (Ctrl+R)"><a href="{{ link }}"></a></span><span>{{ path }}</span></li>
<li class=path><span class="path-icon clear-storage" id=clear-storage title="clear storage (Ctrl+D)"></span><span class="path-icon refresh-icon" title="refresh (Ctrl+R)"><a href="{{ link }}"></a></span><span>{{ path }}</span></li>

View file

@ -8,7 +8,7 @@ var Util, DOM, CloudFunc, CloudCmd;
'use strict';
var Key, Config, Modules, FileTemplate, PathTemplate, Listeners,
Cache = DOM.Cache;
Storage = DOM.Storage;
CloudCmd = {
LIBDIR : '/lib/',
@ -262,11 +262,11 @@ var Util, DOM, CloudFunc, CloudCmd;
CloudCmd.getConfig(function(config) {
var localStorage = config.localStorage;
/* устанавливаем переменную доступности кэша */
Cache.setAllowed(localStorage);
Storage.setAllowed(localStorage);
/* Устанавливаем кэш корневого каталога */
var lDirPath = DOM.getCurrentDirPath();
if (!Cache.get(lDirPath))
Cache.set(lDirPath, getJSONfromFileTable());
if (!Storage.get(lDirPath))
Storage.set(lDirPath, getJSONfromFileTable());
});
Util.exec(pCallBack);
@ -368,7 +368,7 @@ var Util, DOM, CloudFunc, CloudCmd;
*/
var lRet = pOptions.refresh;
if (!lRet) {
var lJSON = Cache.get(lCleanPath);
var lJSON = Storage.get(lCleanPath);
if (lJSON) {
lJSON = Util.parseJSON(lJSON);
@ -399,7 +399,7 @@ var Util, DOM, CloudFunc, CloudCmd;
/* если размер данных не очень бошьой *
* сохраняем их в кэше */
if (lJSON_s.length < 50000 )
Cache.set(lCleanPath, lJSON_s);
Storage.set(lCleanPath, lJSON_s);
}
});
};

View file

@ -570,21 +570,21 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
}
}
},
CacheProto = function() {
StorageProto = function() {
/* приватный переключатель возможности работы с кэшем */
var CacheAllowed;
var StorageAllowed;
/* функция проверяет возможно ли работать с кэшем каким-либо образом */
this.isAllowed = function() {
var lRet = CacheAllowed && !!window.localStorage;
var lRet = StorageAllowed && !!window.localStorage;
return lRet;
};
/**
* allow cache usage
* allow Storage usage
*/
this.setAllowed = function(pAllowd) {
CacheAllowed = pAllowd;
StorageAllowed = pAllowd;
return pAllowd;
};
@ -593,7 +593,7 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
this.remove = function(pItem) {
var lRet = this;
if (CacheAllowed)
if (StorageAllowed)
localStorage.removeItem(pItem);
return lRet;
@ -606,27 +606,27 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
this.set = function(pName, pData) {
var lRet = this;
if (CacheAllowed && pName && pData)
if (StorageAllowed && pName && pData)
localStorage.setItem(pName,pData);
return lRet;
},
/** Если доступен Cache принимаем из него данные*/
/** Если доступен Storage принимаем из него данные*/
this.get = function(pName) {
var lRet;
if (CacheAllowed)
if (StorageAllowed)
lRet = localStorage.getItem(pName);
return lRet;
},
/* get all cache from local storage */
/* get all Storage from local storage */
this.getAll = function() {
var lRet = null;
if (CacheAllowed)
if (StorageAllowed)
lRet = localStorage;
return lRet;
@ -636,7 +636,7 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
this.clear = function() {
var lRet = this;
if (CacheAllowed)
if (StorageAllowed)
localStorage.clear();
return lRet;
@ -1262,7 +1262,7 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
DOM.getCurrentDirPath()
);
Cache.remove(lDir);
Storage.remove(lDir);
}, lQuery);
return lCurrent;
@ -1486,7 +1486,7 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
lName += lExt;
}
DOM.saveDataToCache(lPath, pData);
DOM.saveDataToStorage(lPath, pData);
Util.exec(pCallBack, {
data: pData,
@ -1502,7 +1502,7 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
error : pCallBack.error
};
DOM.getDataFromCache(lPath, function(data) {
DOM.getDataFromStorage(lPath, function(data) {
if (data)
lFunc(data);
else
@ -1519,7 +1519,7 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
*/
this.saveCurrentData = function(pUrl, pData, pCallBack, pQuery) {
RESTful.save(pUrl, pData, function() {
DOM.saveDataToCache(pUrl, pData);
DOM.saveDataToStorage(pUrl, pData);
}, pQuery);
};
@ -1758,7 +1758,7 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
* @param data
* @param callback
*/
this.saveDataToCache = function(name, data, callback) {
this.saveDataToStorage = function(name, data, callback) {
CloudCmd.getConfig(function(config) {
var hash,
nameHash = name + '-hash',
@ -1768,14 +1768,14 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
if (!allowed)
Util.exec(callback);
else {
hash = Cache.get(name + '-hash');
hash = Storage.get(name + '-hash');
DOM.loadCurrentHash(function(pHash) {
var isContain = Util.isContainStr(hash, 'error');
if (!isContain && hash !== pHash) {
Cache.set(nameHash, pHash);
Cache.set(nameData, data);
Storage.set(nameHash, pHash);
Storage.set(nameData, data);
}
Util.exec(callback, hash);
@ -1791,7 +1791,7 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
* @param data
* @param callback
*/
this.getDataFromCache = function(name, callback) {
this.getDataFromStorage = function(name, callback) {
CloudCmd.getConfig(function(config) {
var hash, allowed = config.localStorage,
isDir = DOM.isCurrentIsDir();
@ -1799,7 +1799,7 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
if (!allowed || isDir)
Util.exec(callback);
else {
hash = Cache.get(name + '-hash');
hash = Storage.get(name + '-hash');
if (!hash)
Util.exec(callback);
@ -1809,7 +1809,7 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
isContain = Util.isContainStr(hash, 'error');
if (!isContain && hash === pHash)
data = Cache.get(name + '-data');
data = Storage.get(name + '-data');
Util.exec(callback, data);
});
@ -2108,7 +2108,7 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
Loader = Util.extendProto(LoaderProto),
Images = Util.extendProto(ImagesProto),
RESTful = Util.extendProto(RESTfulProto),
Cache = Util.extendProto(CacheProto);
Storage = Util.extendProto(StorageProto);
DOMProto = DOMFunc.prototype = new CmdProto();
@ -2120,7 +2120,7 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
Events : Events,
RESTful : RESTful,
Images : Images,
Cache : Cache,
Storage : Storage,
Notify : Notify,
Dialog : Dialog
}

View file

@ -303,10 +303,10 @@ var CloudCmd, Util, DOM;
case Key.D:
if (lCtrl) {
Util.log('<ctrl>+d pressed\n' +
'clearing cache...\n' +
'clearing Storage...\n' +
'press <alt>+q to remove all key-handlers');
DOM.Cache.clear();
DOM.Storage.clear();
DOM.preventDefault();
}
break;
@ -316,7 +316,7 @@ var CloudCmd, Util, DOM;
if (lAlt) {
Util.log('<alt>+q pressed\n' +
'<ctrl>+r reload key-handerl - removed' +
'<ctrl>+s clear cache key-handler - removed'+
'<ctrl>+s clear Storage key-handler - removed'+
'press <alt>+s to to set them');
Binded = false;
@ -334,7 +334,7 @@ var CloudCmd, Util, DOM;
Binded = true;
Util.log('<alt>+s pressed \n' +
'<ctrl>+r reload key-handerl - set \n' +
'<ctrl>+s clear cache key-handler - set \n' +
'<ctrl>+s clear Storage key-handler - set \n' +
'press <alt>+q to remove them');
DOM.preventDefault(pEvent);

View file

@ -6,7 +6,7 @@ var Util, DOM, CloudCmd;
CloudCmd.Listeners = new ListenersProto(CloudCmd, Util, DOM);
function ListenersProto(CloudCmd, Util, DOM){
var Cache = DOM.Cache,
var Storage = DOM.Storage,
Events = DOM.Events,
getConfig = CloudCmd.getConfig;
@ -29,7 +29,7 @@ var Util, DOM, CloudCmd;
};
this.init = function () {
appCache();
appStorage();
contextMenu();
dragndrop();
unload();
@ -80,8 +80,8 @@ var Util, DOM, CloudCmd;
*/
this.changeLinks = function(pPanelID) {
/* назначаем кнопку очистить кэш и показываем её */
var lClearcache = DOM.getById('clear-cache');
Events.addClick(Cache.clear, lClearcache);
var lClearStorage = DOM.getById('clear-storage');
Events.addClick(Storage.clear, lClearStorage);
/* меняем ссылки на ajax-запросы */
var lPanel = DOM.getById(pPanelID),
@ -191,19 +191,19 @@ var Util, DOM, CloudCmd;
}
};
function appCache() {
function appStorage() {
getConfig(function(config) {
var isAppCache = config.appCache,
appCache = window.applicationCache;
var isAppStorage = config.appStorage,
appStorage = window.applicationStorage;
if (isAppCache && appCache)
if (isAppStorage && appStorage)
Events.add('updateready', function() {
var ret = confirm('An update is available. Reload now?');
if (ret)
location.reload();
}, appCache);
}, appStorage);
});
}

View file

@ -214,25 +214,25 @@ var Util, DOM, jQuery;
}
if(!window.localStorage){
var Cache = function(){
var Storage = function(){
/* приватный переключатель возможности работы с кэшем */
var CacheAllowed,
var StorageAllowed,
Data = {};
/* функция проверяет возможно ли работать с кэшем каким-либо образом */
this.isAllowed = function(){
return CacheAllowed;
return StorageAllowed;
};
this.setAllowed = function(pAllowed){
CacheAllowed = pAllowed;
StorageAllowed = pAllowed;
return pAllowed;
};
/** remove element */
this.remove = function(pItem){
var lRet = this;
if(CacheAllowed)
if(StorageAllowed)
delete Data[pItem];
return lRet;
@ -245,27 +245,27 @@ var Util, DOM, jQuery;
this.set = function(pName, pData){
var lRet = this;
if(CacheAllowed && pName && pData)
if(StorageAllowed && pName && pData)
Data[pName] = pData;
return lRet;
},
/** Если доступен Cache принимаем из него данные*/
/** Если доступен Storage принимаем из него данные*/
this.get = function(pName){
var lRet = false;
if(CacheAllowed)
if(StorageAllowed)
lRet = Data[pName];
return lRet;
},
/* get all cache from local storage */
/* get all Storage from local storage */
this.getAll = function(){
var lRet = null;
if(CacheAllowed)
if(StorageAllowed)
lRet = Data;
return lRet;
@ -275,14 +275,14 @@ var Util, DOM, jQuery;
this.clear = function(){
var lRet = this;
if(CacheAllowed)
if(StorageAllowed)
Data = {};
return lRet;
};
};
DOM.Cache = new Cache();
DOM.Storage = new Storage();
}
})(Util, DOM, jQuery);

View file

@ -4,7 +4,7 @@ var CloudCmd, Util, DOM, $, Github, cb;
(function(CloudCmd, Util, DOM){
'use strict';
var Cache = DOM.Cache,
var Storage = DOM.Storage,
GithubLocal,
User,
GitHubStore = {};
@ -37,7 +37,7 @@ var CloudCmd, Util, DOM, $, Github, cb;
GitHubStore.autorize = function(pCallBack, pCode){
var lToken = Cache.get('token');
var lToken = Storage.get('token');
if(lToken){
GitHubStore.Login(lToken);
Util.exec(pCallBack);
@ -55,7 +55,7 @@ var CloudCmd, Util, DOM, $, Github, cb;
lToken = pData.token;
GitHubStore.Login(lToken);
Cache.set('token', lToken);
Storage.set('token', lToken);
Util.exec(pCallBack);
}
else
@ -77,7 +77,7 @@ var CloudCmd, Util, DOM, $, Github, cb;
Util.log('Hello ' + lName + ' :)!');
}
else
DOM.Cache.remove('token');
DOM.Storage.remove('token');
});
Util.exec(pCallBack);