📄 file_manager_general_revised.js
字号:
/*
/*
* author: Logan Cai
* Email: cailongqun [at] yahoo [dot] com [dot] cn
* Website: www.phpletter.com
* Created At: 21/April/2007
* Modified At: 1/June/2007
*/
// Returns true if the passed value is found in the
// array. Returns false if it is not.
Array.prototype.inArray = function (value,caseSensitive)
{
var i;
for (i=0; i < this.length; i++)
{
// use === to check for Matches. ie., identical (===),
if(caseSensitive){ //performs match even the string is case sensitive
if (this[i].toLowerCase() == value.toLowerCase())
{
return true;
}
}else
{
if (this[i] == value)
{
return true;
}
}
}
return false;
};
var dcTime=250; // doubleclick time
var dcDelay=100; // no clicks after doubleclick
var dcAt=0; // time of doubleclick
var savEvent=null; // save Event for handling doClick().
var savEvtTime=0; // save time of click event.
var savTO=null; // handle of click setTimeOut
var linkElem = null;
function hadDoubleClick()
{
var d = new Date();
var now = d.getTime();
if ((now - dcAt) < dcDelay)
{
return true;
}
return false;
};
/**
* enable left click to preview certain files
*/
function enablePreview(elem, num)
{
$(elem).each(
function()
{
$(this).click(function ()
{
//alert('single click');
var num = getNum(this.id);
var path = files[num].path;
//alert('now: ' + now + '; dcat: ' + dcAt + '; dcDelay: ' + dcDelay);
if (hadDoubleClick())
{
return false;
}else
{
linkElem = $('#a' + num).get(0);
}
d = new Date();
savEvtTime = d.getTime();
savTO = setTimeout(function()
{
if (savEvtTime - dcAt > 0)
{
//check if this file is previewable
var ext = getFileExtension(path);
var supportedExts = supporedPreviewExts.split(",");
var isSupportedExt = false;
for (i in supportedExts)
{
var typeOf = typeof(supportedExts[i]);
//alert(supportedExts[i]);
if(typeOf.toLowerCase() == 'string' && supportedExts[i].toLowerCase() == ext.toLowerCase())
{
isSupportedExt = true;
break;
}
}
if(isSupportedExt)
{
switch(files[num].cssClass)
{
case 'fileVideo':
case 'fileMusic':
case 'fileFlash':
$('#playGround').html('<a id="playGround' + num + '" href="' + files[num].path + '"><div id="player"> this is mine</div></a> ');
$('#playGround' + num).html('');
$('#playGround' + num).media({ width: 255, height: 210, autoplay: true });
//alert($('#playGround' + num).html());
showThickBox($('#a' + num).get(0), appendQueryString('#TB_inline', 'height=250' + '&width=256' + '&inlineId=winPlay&modal=true'));
break;
default:
showThickBox(linkElem, appendQueryString(path, 'KeepThis=true&TB_iframe=true&height=' + thickbox.height + '&width=' + thickbox.width));
}
}
}
return false;
}, dcTime);
return false;
});
$(this).dblclick(function()
{
var d = new Date();
dcAt = d.getTime();
if (savTO != null) {
clearTimeout( savTO ); // Clear pending Click
savTO = null;
}
if(typeof(selectFile) != 'undefined')
{
selectFile(files[num].url);
}else
generateDownloadIframe(appendQueryString(getUrl('download'), 'path=' + files[num].path, ['path'])); {
}
}
);
}
);
};
/**
* add over class to the specific table
*/
function tableRuler(element)
{
var rows = $(element);
$(rows).each(function(){
$(this).mouseover(function(){
$(this).addClass('over');
});
$(this).mouseout(function(){
$(this).removeClass('over');
});
});
};
function previewMedia(rowNum)
{
$('#preview' +rowNum).html('');
$('#preview' +rowNum).media({ width: 255, height: 210, autoplay: true });
return false;
};
function getFileExtension(filename)
{
if( filename.length == 0 ) return "";
var dot = filename.lastIndexOf(".");
if( dot == -1 ) return "";
var extension = filename.substr(dot + 1,filename.length);
return extension;
};
function closeWindow()
{
if(window.confirm(warningCloseWindow))
{
window.close();
}
return false;
};
/**
* return the url with query string
*/
function getUrl(index,limitNeeded , viewNeeded, searchNeeded)
{
var queryStr = '';
var excluded = new Array();
if(typeof(limitNeeded) == 'boolean' && limitNeeded)
{
var limit = document.getElementById('limit');
var typeLimit = typeof(limit);
if(typeLimit != 'undefined')
{
excluded[excluded.length] = 'limit';
queryStr += (queryStr == ''?'':'&') + 'limit=' + limit.options[limit.selectedIndex].value;
}
}
if(typeof(viewNeeded) == 'boolean' && viewNeeded)
{
queryStr += (queryStr == ''?'':'&') + 'view=' + getView();
excluded[excluded.length] = 'view';
}
if(typeof(searchNeeded) == 'boolean' && searchNeeded && searchRequired)
{
var search_recursively = 0;
$('input[@name=search_recursively][@checked]').each(
function()
{
search_recursively = this.value;
}
);
var searchFolder = document.getElementById('search_folder');
queryStr += (queryStr == ''?'':'&') + 'search=1&search_name=' + $('#search_name').val() + '&search_recursively=' + search_recursively + '&search_mtime_from=' + $('#search_mtime_from').val() + '&search_mtime_to=' + $('#search_mtime_to').val() + '&search_folder=' + searchFolder.options[searchFolder.selectedIndex].value;
excluded[excluded.length] = 'search';
excluded[excluded.length] = 'search_recursively';
excluded[excluded.length] = 'search_mtime_from';
excluded[excluded.length] = 'search_mtime_to';
excluded[excluded.length] = 'search_folder';
excluded[excluded.length] = 'search_name';
excluded[excluded.length] = 'search';
}
return appendQueryString(appendQueryString(urls[index], queryString), queryStr, excluded);
};
/**
* change view
*/
function changeView()
{
var url = getUrl('view', true, true);
$('#rightCol').empty();
ajaxStart('#rightCol');
$('#rightCol').load(url,
{},
function(){
ajaxStop('#rightCol img.ajaxLoadingImg');
urls.present = getUrl('home', true, true);
initAfterListingLoaded();
});
};
function goParentFolder()
{
searchRequired = false;
var url = appendQueryString(getUrl('view', true, true), 'path=' + parentFolder.path , ['path']);
$('#rightCol').empty();
ajaxStart('#rightCol');
$('#rightCol').load(url,
{},
function(){
urls.present = appendQueryString(getUrl('home', true, true), 'path=' + parentFolder.path , ['path']);
ajaxStop('#rightCol img.ajaxLoadingImg');
initAfterListingLoaded();
});
};
/**
* append Query string to the base url
* @param string baseUrl the base url
* @param string the query string
* @param array remove thost url variable from base url if any matches
*/
function appendQueryString(baseUrl, queryStr, excludedQueryStr)
{
if(typeof(excludedQueryStr) == 'object' && excludedQueryStr.length)
{
var isMatched = false;
var urlParts = baseUrl.split("?");
baseUrl = urlParts[0];
var count = 1;
if(typeof(urlParts[1]) != 'undefined' && urlParts[1] != '')
{//this is the query string parts
var queryStrParts = urlParts[1].split("&");
for(var i=0; i < queryStrParts.length; i++)
{
//split into query string variable name & value
var queryStrVariables = queryStrParts[i].split('=');
for(var j=0; j < excludedQueryStr.length; j++)
{
if(queryStrVariables[0] == excludedQueryStr[j])
{
isMatched = true;
}
}
if(!isMatched)
{
baseUrl += ((count==1?'?':'&') + queryStrVariables[0] + '=' + queryStrVariables[1]);
count++;
}
}
}
}
if(queryStr != '')
{
return (baseUrl.indexOf('?')> -1?baseUrl + '&' + queryStr:baseUrl + '?' + queryStr);
}else
{
return baseUrl;
}
};
/**
* initiate when the listing page is loaded
* add main features according to the view
*/
function initAfterListingLoaded()
{
parsePagination();
/* parseCurrentFolder();
var view = getView();
setDocInfo('root');
if(view != '')
{
switch(view)
{
case 'thumbnail':
//enableContextMenu('dl.thumbnailListing, dl.thumbnailListing dt, dl.thumbnailListing dd, dl.thumbnailListing a');
enableContextMenu('dl.thumbnailListing');
for(i in files)
{
if(files[i].type== 'folder')
{//this is foder item
enableFolderBrowsable(i);
}else
{//this is file item
switch(files[i].cssClass)
{
case 'filePicture':
//$('#a' + i).attr('rel', 'ajaxphotos');
//retrieveThumbnail(i);
break;
case 'fileFlash':
break;
case 'fileVideo':
break;
case 'fileMusic':
break;
default:
}
enablePreview('#dt' + i, i);
enablePreview('#thumbUrl' + i, i);
enablePreview('#a' + i, i);
}
enableShowDocInfo( i);
}
break;
case 'detail':
default:
enableContextMenu('#fileList tr');
for(i in files)
{
if(files[i].type== 'folder')
{//this is foder item
enableFolderBrowsable(i);
}else
{//this is file item
switch(files[i].cssClass)
{
case 'filePicture':
$('#row' + i + ' td a').attr('rel', 'ajaxphotos');
break;
case 'fileFlash':
break;
case 'fileVideo':
break;
case 'fileMusic':
break;
default:
};
enablePreview('#row' + i + ' td a', i);
}
enableShowDocInfo(i);
}
break;
}
}*/
};
function enableFolderBrowsable(num, debug)
{
switch(getView())
{
case 'thumbnail':
$('#dt'+ num + ' , #dd' + num + ' a').each(function()
{
/* if(typeof(debug) != 'undefined' && debug)
{
alert(this.tagName + ' ' + files[num].path);
}*/
doEnableFolderBrowsable(this, num);
}
);
break;
case 'detail':
default:
$('#row' + num + ' td[a]').each(function()
{
doEnableFolderBrowsable(this, num );
}
);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -