improved work with browsers history api

This commit is contained in:
coderaiser 2012-12-03 05:21:45 -05:00
parent e69fe2f8d9
commit d08d05d6d7
5 changed files with 63 additions and 29 deletions

View file

@ -140,6 +140,8 @@ Javascript dissabled.
* client.js and server.js moved to lib directory.
* Improved work with browsers history api.
2012.10.01, Version 0.1.7

View file

@ -59,7 +59,7 @@
/* меняем title */
lData = lData.replace('<title>Cloud Commander</title>',
'<title>' + CloudFunc.setTitle() + '</title>');
'<title>' + CloudFunc.getTitle() + '</title>');
if(!srv.Config.appcache)
lData = Util.removeStr(lData, ' manifest="/cloudcmd.appcache"');

View file

@ -3,7 +3,7 @@
* клиентский и серверный
*/
var Util, DOM, CloudCommander = (function(){
var Util, DOM, CloudFunc, CloudCommander = (function(){
"use strict";
/* Клиентский обьект, содержащий функциональную часть*/
@ -62,7 +62,7 @@ var CloudClient = {
var cloudcmd = CloudClient,
/* глобальные переменные */
CloudFunc, $, KeyBinding,
$, KeyBinding,
/* short names used all the time functions */
getByClass, getById;
@ -149,7 +149,7 @@ CloudClient._loadDir = function(pLink,pNeedRefresh){
lHref = lHref.replace(lSubstr+'/','');
/* загружаем содержимое каталога */
CloudClient._ajaxLoad(pLink, pNeedRefresh);
CloudClient._ajaxLoad(pLink, { refresh: pNeedRefresh });
/* получаем все элементы выделенной папки*/
/* при этом, если мы нажали обновить
@ -413,16 +413,18 @@ function baseInit(pCallBack){
Util.exec(lFunc);
};
}
/* меняем title
* если js включен - имена папок отображать необязательно...
* а может и обязательно при переходе, можно будет это сделать
*/
var lTitle = DOM.getByTag('title');
if(lTitle.length > 0)
lTitle[0].textContent = 'Cloud Commander';
/* загружаем общие функции для клиента и сервера */
DOM.jsload(cloudcmd.LIBDIR + 'cloudfunc.js',function(){
DOM.addListener("popstate", function(pEvent) {
var lPath = pEvent.state;
if(lPath)
cloudcmd._ajaxLoad(lPath, {nohistory: true});
return true;
});
/* берём из обьекта window общий с сервером функционал */
CloudFunc = window.CloudFunc;
@ -623,16 +625,19 @@ CloudClient._changeLinks = function(pPanelID){
* Функция загружает json-данные о Файловой Системе
* через ajax-запрос.
* @param path - каталог для чтения
* @param pNeedRefresh - необходимость обновить данные о каталоге
* @param pOptions
* { refresh, nohistory } - необходимость обновить данные о каталоге
*/
CloudClient._ajaxLoad = function(pFullPath, pNeedRefresh){
/* Отображаем красивые пути */
CloudClient._ajaxLoad = function(pFullPath, pOptions){
if(!pOptions)
pOptions = {};
/* Отображаем красивые пути */
/* added supporting of russian language */
pFullPath = decodeURI(pFullPath);
var lPath = pFullPath,
lFSPath,
lFSPath = pFullPath,
lFS_s = CloudFunc.FS,
lNoJS_s = CloudFunc.NOJS;
/*
@ -652,6 +657,12 @@ CloudClient._ajaxLoad = function(pFullPath, pNeedRefresh){
console.log ('reading dir: "' + lPath + '";');
if(!pOptions.nohistory)
DOM.setHistory(pFullPath, null, pFullPath);
DOM.setTitle( CloudFunc.getTitle(lPath) );
/* если доступен localStorage и
* в нём есть нужная нам директория -
* читаем данные с него и
@ -666,7 +677,7 @@ CloudClient._ajaxLoad = function(pFullPath, pNeedRefresh){
var lPanel = DOM.getPanel().id,
lError;
if(pNeedRefresh === undefined && lPanel){
if(!pOptions.refresh && lPanel){
var lJSON = DOM.Cache.get(lPath);
if (lJSON){
@ -682,7 +693,6 @@ CloudClient._ajaxLoad = function(pFullPath, pNeedRefresh){
CloudClient._createFileTable(lPanel, lJSON);
CloudClient._changeLinks(lPanel);
DOM.setHistory(lPath, 'Cloud Commander', pFullPath);
return;
}
@ -716,8 +726,6 @@ CloudClient._ajaxLoad = function(pFullPath, pNeedRefresh){
*/
if(lJSON_s.length < 50000 )
DOM.Cache.set(lPath, lJSON_s);
DOM.setHistory(lPath, 'Cloud Commander', pFullPath);
}
});
};

View file

@ -33,6 +33,7 @@ var CloudCommander, Util, DOM, CloudFunc;
/* private members */
var XMLHTTP,
Title,
LoadingImage,
ErrorImage,
@ -101,7 +102,7 @@ var CloudCommander, Util, DOM, CloudFunc;
DOM.addListener = function(pType, pListener, pUseCapture, pElement){
var lRet = this;
(pElement || document).addEventListener(
(pElement || window).addEventListener(
pType,
pListener,
pUseCapture || false
@ -810,6 +811,27 @@ var CloudCommander, Util, DOM, CloudFunc;
return CloudCommander.KeysPanel[pKey].onclick = pFunc;
};
/**
* set title with pName
* create title element
* if it absent
* @param pName
*/
DOM.setTitle = function(pName){
if(!Title)
Title = DOM.getByTag('title')[0] ||
DOM.anyload({
name:'title',
parentElement: document.head,
innerHTML: pName
});
if(Title)
Title.textContent = pName;
return Title;
};
/**
* current file check
*

View file

@ -44,13 +44,15 @@ var CloudFunc, exports;
else return pPath;
};
/* Функция возвращает заголовок веб страницы */
CloudFunc.setTitle = function(){
return CloudFunc.Path==='' ? CloudFunc.NAME:
CloudFunc.Path +
' - ' +
CloudFunc.NAME;
/** Функция возвращает заголовок веб страницы
* @pPath
*/
CloudFunc.getTitle = function(pPath){
if(!CloudFunc.Path)
CloudFunc.Path = '/';
return CloudFunc.NAME + ' - ' + (pPath || CloudFunc.Path);
};
/**
* Функция переводит права из цыфрового вида в символьный