From c439318c0a38f7222b87cc86eae76c2be1a181bc Mon Sep 17 00:00:00 2001 From: coderaiser Date: Mon, 23 Jul 2012 09:28:49 -0400 Subject: [PATCH] added function getShortedName --- lib/cloudfunc.js | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/lib/cloudfunc.js b/lib/cloudfunc.js index fac98396..8afc9094 100644 --- a/lib/cloudfunc.js +++ b/lib/cloudfunc.js @@ -5,21 +5,24 @@ var CloudFunc={ /* Путь с которым мы сейчас работаем */ - Path :'', + Path :'', /* КОНСТАНТЫ (общие для клиента и сервера)*/ /* название программы */ - NAME :'Cloud Commander', + NAME :'Cloud Commander', /* если в ссылке будет эта строка - * в браузере js отключен */ - NOJS : '/no-js', - FS : '/fs', + NOJS : '/no-js', + FS : '/fs', /* название css-класа кнопки обновления файловой структуры*/ - REFRESHICON : 'refresh-icon', + REFRESHICON : 'refresh-icon', /* id панелей с файлами */ - LEFTPANEL : 'left', - RIGHTPANEL : 'right' - /* name of direcotory with libs */ + LEFTPANEL : 'left', + RIGHTPANEL : 'right', + /* length of longest + * file name + */ + SHORTNAMELENGTH : 16 }; /* @@ -144,7 +147,7 @@ CloudFunc.convertPermissionsToNumberic= function(pPerm_s){ * гигайбайты и терабайты * @pSize - размер в байтах */ -CloudFunc.getShortedSize=function(pSize){ +CloudFunc.getShortedSize = function(pSize){ /* if pSize=0 - return it */ if (pSize != pSize-0) return pSize; @@ -167,6 +170,19 @@ CloudFunc.getShortedSize=function(pSize){ return lShorted; }; +/* Function gets file name and + * if it's bigger the 16 chars + * cut it and adds '..' + * @pName - file name + * @pPutInTegs - boolean says add some tegs or not + */ +CloudFunc.getShortedName = function(pName, pPutInTegs){ + return (pName.length > CloudFunc.SHORTNAMELENGTH ? + (pName.substr(pName,16) + '..'): + pName); +}; + + /* Функция парсит uid и имена пользователей * из переданного в строке вычитаного файла /etc/passwd * и возвращает массив обьектов имён и uid пользователей @@ -404,10 +420,9 @@ CloudFunc.buildFromJSON=function(pJSON,pKeyBinded) * отрезаем лишнее, оставляя лишь 16, * и добавляем две точки и тайтл */ - (files[i].name.length>16? - ' title="'+files[i].name+'">' + - files[i].name.substr( - files[i].name,16)+ + (files[i].name.length > CloudFunc.SHORTNAMELENGTH? + ' title="' + files[i].name + '">' + + CloudFunc.getShortedName(files[i].name) + '..':'>'+files[i].name) + "" + '';