').appendTo(j).html(c.caption);return j}})(jQuery);
//media.js end
//ajaxfileupload start
jQuery.extend({ createUploadIframe: function(id, uri)
{ var frameId = 'jUploadFrame' + id; if(window.ActiveXObject) { var io = document.createElement('
'); if(typeof uri== 'boolean'){ io.src = 'javascript:false';}
else if(typeof uri== 'string'){ io.src = uri;}
}
else { var io = document.createElement('iframe'); io.id = frameId; io.name = frameId;}
io.style.position = 'absolute'; io.style.top = '-1000px'; io.style.left = '-1000px'; document.body.appendChild(io); return io;}, createUploadForm: function(id, fileElementId)
{ var formId = 'jUploadForm' + id; var fileId = 'jUploadFile' + id; var form = jQuery('
'); var oldElement = jQuery('#' + fileElementId); var newElement = jQuery(oldElement).clone(); jQuery(oldElement).attr('id', fileId); jQuery(oldElement).before(newElement); jQuery(oldElement).appendTo(form); jQuery(form).css('position', 'absolute'); jQuery(form).css('top', '-1200px'); jQuery(form).css('left', '-1200px'); jQuery(form).appendTo('body'); return form;}, ajaxFileUpload: function(s) { s = jQuery.extend({}, jQuery.ajaxSettings, s); var id = s.fileElementId; var form = jQuery.createUploadForm(id, s.fileElementId); var io = jQuery.createUploadIframe(id, s.secureuri); var frameId = 'jUploadFrame' + id; var formId = 'jUploadForm' + id; if( s.global && ! jQuery.active++ )
{ jQuery.event.trigger( "ajaxStart" );}
var requestDone = false; var xml = {}; if( s.global )
{ jQuery.event.trigger("ajaxSend", [xml, s]);}
var uploadCallback = function(isTimeout)
{ var io = document.getElementById(frameId); try
{ if(io.contentWindow)
{ xml.responseText = io.contentWindow.document.body?io.contentWindow.document.body.innerHTML:null; xml.responseXML = io.contentWindow.document.XMLDocument?io.contentWindow.document.XMLDocument:io.contentWindow.document;}else if(io.contentDocument)
{ xml.responseText = io.contentDocument.document.body?io.contentDocument.document.body.innerHTML:null; xml.responseXML = io.contentDocument.document.XMLDocument?io.contentDocument.document.XMLDocument:io.contentDocument.document;}
}catch(e)
{ jQuery.handleError(s, xml, null, e);}
if( xml || isTimeout == "timeout")
{ requestDone = true; var status; try { status = isTimeout != "timeout" ? "success" : "error"; if( status != "error" )
{ var data = jQuery.uploadHttpData( xml, s.dataType ); if( s.success )
{ s.success( data, status );}; if( s.global )
{ jQuery.event.trigger( "ajaxSuccess", [xml, s] );};} else
{ jQuery.handleError(s, xml, status);}
} catch(e)
{ status = "error"; jQuery.handleError(s, xml, status, e);}; if( s.global )
{ jQuery.event.trigger( "ajaxComplete", [xml, s] );}; if(s.global && ! --jQuery.active)
{ jQuery.event.trigger("ajaxStop");}; if(s.complete)
{ s.complete(xml, status);} ; jQuery(io).unbind(); setTimeout(function()
{ try
{ jQuery(io).remove(); jQuery(form).remove();} catch(e)
{ jQuery.handleError(s, xml, null, e);}
}, 100); xml = null;};}
if( s.timeout > 0 )
{ setTimeout(function(){ if( !requestDone )
{ uploadCallback( "timeout" );}
}, s.timeout);}
try
{ var form = jQuery('#' + formId); jQuery(form).attr('action', s.url); jQuery(form).attr('method', 'POST'); jQuery(form).attr('target', frameId); if(form.encoding)
{ form.encoding = 'multipart/form-data';}
else
{ form.enctype = 'multipart/form-data';}
jQuery(form).submit();} catch(e)
{ jQuery.handleError(s, xml, null, e);}
if(window.attachEvent){ document.getElementById(frameId).attachEvent('onload', uploadCallback);}
else{ document.getElementById(frameId).addEventListener('load', uploadCallback, false);}
return {abort: function () {}};}, uploadHttpData: function( r, type ) { var data = !type; data = type == "xml" || data ? r.responseXML : r.responseText; if( type == "script" )
{ jQuery.globalEval( data );}
if( type == "json" )
{ eval( "data = " + data );}
if( type == "html" )
{ jQuery("
").html(data).evalScripts();}
return data;}
});
//ajaxfileupload end
//ajaxfilemanager general start
Array.prototype.inArray = function (value,caseSensitive)
{ var i; for (i=0; i < this.length; i++)
{ if(caseSensitive){ if (this[i].toLowerCase() == value.toLowerCase())
{ return true;}
}else
{ if (this[i] == value)
{ return true;}
}
}
return false;}; var dcTime=250; var dcDelay=100; var dcAt=0; var savEvent=null; var savEvtTime=0; var savTO=null; var linkElem = null; function hadDoubleClick()
{ var d = new Date(); var now = d.getTime(); if ((now - dcAt) < dcDelay)
{ return true;}
return false;}; function enablePreview(elem, num)
{ $(elem).each( function()
{ $(this).click(function ()
{ var num = getNum(this.id); var path = files[num].path; if (hadDoubleClick())
{ return false;}else
{ linkElem = $('#a' + num).get(0);}
d = new Date(); savEvtTime = d.getTime(); savTO = setTimeout(function()
{ if (savEvtTime - dcAt > 0)
{ var ext = getFileExtension(path); var supportedExts = supporedPreviewExts.split(","); var isSupportedExt = false; for (i in supportedExts)
{ var typeOf = typeof(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('
this is mine
'); $('#playGround' + num).html(''); $('#playGround' + num).media({ width: 255, height: 210, autoplay: true }); 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 ); savTO = null;}
if(typeof(selectFile) != 'undefined')
{ selectFile(files[num].url);}else
generateDownloadIframe(appendQueryString(getUrl('download'), 'path=' + files[num].path, ['path'])); { }
} );} );}; 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;}; 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' && limit )
{ 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);}; 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();});}; 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] != '')
{ var queryStrParts = urlParts[1].split("&"); for(var i=0; i < queryStrParts.length; i++)
{ 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;}
}; function initAfterListingLoaded()
{ parsePagination(); parseCurrentFolder(); var view = getView(); setDocInfo('root'); if(view != '')
{ switch(view)
{ case 'thumbnail':
enableContextMenu('dl.thumbnailListing'); for(i in files)
{ if(files[i].type== 'folder')
{ enableFolderBrowsable(i);}else
{ switch(files[i].cssClass)
{ case 'filePicture':
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')
{ enableFolderBrowsable(i);}else
{ 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()
{ doEnableFolderBrowsable(this, num);} ); break; case 'detail':
default:
$('#row' + num + ' td[a]').each(function()
{ doEnableFolderBrowsable(this, num );} );}
}; function doEnableFolderBrowsable(elem, num)
{ $(elem).click(function()
{ { searchRequired = false; var typeNum = typeof(num); if(typeNum.toUpperCase() == 'STRING')
{ var fpath = (num.indexOf(urls.view) >=0?num:files[num].path);}else
{ var fpath = files[num].path;}
var url = appendQueryString(getUrl('view', true, true), 'path=' + fpath, ['path']); $('#rightCol').empty(); ajaxStart('#rightCol'); $('#rightCol').load(url, {}, function(){ urls.present = appendQueryString(getUrl('home', true, true), 'path=' + fpath, ['path']); ajaxStop('#rightCol img.ajaxLoadingImg'); initAfterListingLoaded();});}; return false;} );}; function ajaxStart(destinationSelector, id, selectorOfAnimation)
{ if(typeof(selectorOfAnimation) == 'undefined')
{ selectorOfAnimation = '#ajaxLoading img';}
if(typeof(id) != 'undefined')
{ $(selectorOfAnimation).clone().attr('id', id).appendTo(destinationSelector);}else
{ $(selectorOfAnimation).clone(true).appendTo(destinationSelector);}
}; function ajaxStop(selectorOfAnimation)
{ $(selectorOfAnimation).remove();}; function changePaginationLimit(elem)
{ var url = getUrl('view', true, true, true); $('#rightCol').empty(); ajaxStart('#rightCol'); $('#rightCol').load(url, {}, function(){ urls.present = appendQueryString(getUrl('home', true, true), 'path=' + parentFolder.path , ['path'])
ajaxStop('#rightCol img.ajaxLoadingImg'); initAfterListingLoaded();});}; function getUrlVarValue(url, index)
{ if(url != '' && index != '')
{ var urlParts = url.split("?"); baseUrl = urlParts[0]; var count = 1; if(typeof(urlParts[1]) != 'undefined' && urlParts[1] != '')
{ var queryStrParts = urlParts[1].split("&"); for(var i=0; i < queryStrParts.length; i++)
{ var queryStrVariables = queryStrParts[i].split('='); if(queryStrVariables[0] == index)
{ return queryStrVariables[1];}
}
}
}
return '';}; function parseCurrentFolder()
{ var folders = currentFolder.friendly_path.split('/'); var str = ''; var url = getUrl('view', true, true); var parentPath = ''; for(var i = 0; i < folders.length; i++)
{ if(i == 0)
{ parentPath += paths.root; str += '/
' + paths.root_title + ' '
}else
{ if(folders[i] != '')
{ parentPath += folders[i] + '/'; str += '/
' + folders[i] + ' ';}
}
}
$('#currentFolderPath').empty().append(str); $('#currentFolderPath a').each( function()
{ doEnableFolderBrowsable(this, $(this).attr('href'));} );}; function parsePagination()
{ $('p.pagination a[@id!=pagination_parent_link]').each(function ()
{ $(this).click( function()
{ var page = getUrlVarValue($(this).attr('href'), 'page'); var url = appendQueryString(getUrl('view', true, true, searchRequired),'page=' + page, ['page']); $('#rightCol').empty(); ajaxStart('#rightCol'); $('#rightCol').load(url, {}, function(){ urls.present = appendQueryString(getUrl('home', true, true, searchRequired),'page=' + page, ['page']); ajaxStop('#rightCol img.ajaxLoadingImg'); initAfterListingLoaded();}); return false;} );} );}; function getView()
{ var view = $('input[@name=view][@checked]').get(0); if(typeof(view) != 'undefined')
{ return view.value;}else
{ return '';}
}; function getNum(elemId)
{ if(typeof(elemId) != 'undefined' && elemId != '')
{ var r = elemId.match(/[\d\.]+/g); if(typeof(r) != 'undefined' && r && typeof(r[0]) != 'undefined')
{ return r[0];}
}
return 0;}; function enableContextMenu(jquerySelectors)
{ $(jquerySelectors).contextMenu('contextMenu', { bindings:
{ 'menuSelect':function(t)
{ var num = (getNum($(t).attr('id'))); selectFile(files[num].url);}, 'menuPlay':function(t)
{ var num = (getNum($(t).attr('id'))); $('#playGround').html('
this is mine
'); $('#playGround' + num).html(''); $('#playGround' + num).media({ width: 255, height: 210, autoplay: true }); showThickBox($('#a' + num).get(0), appendQueryString('#TB_inline', 'height=250' + '&width=258' + '&inlineId=winPlay&modal=true'));}, 'menuPreview':function(t)
{ var num = (getNum($(t).attr('id'))); $('#a' + num).click();}, 'menuDownload':function(t)
{ var num = (getNum($(t).attr('id'))); generateDownloadIframe(appendQueryString(getUrl('download', false, false), 'path=' + files[num].path, ['path']));}, 'menuRename':function(t)
{ var num = (getNum($(t).attr('id'))); showThickBox($('#a' + num).get(0), appendQueryString('#TB_inline', 'height=100' + '&width=350' + '&inlineId=winRename&modal=true')); $('div#TB_window #renameName').val(files[num].name); $('div#TB_window #original_path').val(files[num].path); $('div#TB_window #renameNum').val(num);}, 'menuEdit':function(t)
{ var num = (getNum($(t).attr('id'))); var url = ''; switch(files[num].cssClass)
{ case 'filePicture':
url = getUrl('image_editor'); break; default:
url = getUrl('text_editor');}
var param = "status=yes,menubar=no,resizable=yes,scrollbars=yes,location=no,toolbar=no"; param += ",height=" + screen.height + ",width=" + screen.width; if(typeof(window.screenX) != 'undefined')
{ param += ",screenX = 0,screenY=0";}else if(typeof(window.screenTop) != 'undefined' )
{ param += ",left = 0,top=0" ;}
var newWindow = window.open(url + ((url.lastIndexOf("?") > - 1)?"&":"?") + "path=" + files[num].path,'', param); newWindow.focus( );}, 'menuCut':function(t)
{ }, 'menuCopy':function(t)
{ }, 'menuPaste':function(t)
{ }, 'menuDelete':function(t)
{ var num = (getNum($(t).attr('id'))); if(window.confirm(warningDelete))
{ $.getJSON(appendQueryString(getUrl('delete', false,false), 'delete=' + files[num].path, ['delete']), function(data)
{ if(typeof(data.error) == 'undefined')
{ alert('Unexpected Error.');}
else if(data.error != '')
{ alert(data.error);}else
{ switch(getView())
{ case 'thumbnail': $('#dl' + num ).remove(); break; case 'detail':
default:
$('#row' + num).remove();}
files[num] = null;}
} );}
}
}, onContextMenu:function(events)
{ return true;}, onShowMenu:function(events, menu)
{ switch(getView())
{ case 'thumbnail':
var num = getNum(events.target.id); break; case 'detail':
default:
switch(events.target.tagName.toLowerCase())
{ case 'span':
if($(events.target).parent().get(0).tagName.toLowerCase() == 'a')
{ var num = getNum($(events.target).parent().parent().parent().attr('id'));}else
{ var num = getNum($(events.target).parent().parent().parent().parent().attr('id'));}
break; case 'td':
var num = getNum($(events.target).parent().attr('id')); break; case 'a':
case 'input':
var num = getNum($(events.target).parent().parent().attr('id')); break;}
}
var menusToRemove = new Array; if(typeof(selectFile) == 'undefined')
{ menusToRemove[menusToRemove.length] = '#menuSelect';}
menusToRemove[menusToRemove.length] = '#menuCut'; menusToRemove[menusToRemove.length] = '#menuCopy'; menusToRemove[menusToRemove.length] = '#menuPaste'; switch(files[num].type)
{ case 'folder':
if(numFiles < 1)
{ menusToRemove[menusToRemove.length] = '#menuPaste';}
menusToRemove[menusToRemove.length] = '#menuPreview'; menusToRemove[menusToRemove.length] = '#menuDownload'; menusToRemove[menusToRemove.length] = '#menuEdit'; menusToRemove[menusToRemove.length] = '#menuPlay'; menusToRemove[menusToRemove.length] = '#menuDownload'; break; default:
var isSupportedExt = false; if(permits.edit)
{ var ext = getFileExtension(files[num].path); var supportedExts = supporedPreviewExts.split(","); for(var i = 0; i < supportedExts.length; i++)
{ if(typeof(supportedExts[i]) != 'undefined' && typeof(supportedExts[i]).toLowerCase() == 'string' && supportedExts[i].toLowerCase() == ext.toLowerCase())
{ isSupportedExt = true; break;}
}
}
if(!isSupportedExt || permits.view_only)
{ menusToRemove[menusToRemove.length] = '#menuEdit';}
switch(files[num].cssClass)
{ case 'filePicture':
menusToRemove[menusToRemove.length] = '#menuPlay'; break; case 'fileCode':
menusToRemove[menusToRemove.length] = '#menuPlay'; break; case 'fileVideo':
case 'fileFlash':
case 'fileMusic':
menusToRemove[menusToRemove.length] = '#menuPreview'; menusToRemove[menusToRemove.length] = '#menuEdit'; break; default:
menusToRemove[menusToRemove.length] = '#menuPreview'; menusToRemove[menusToRemove.length] = '#menuPlay';}
menusToRemove[menusToRemove.length] = '#menuPaste';}
if(!permits.edit|| permits.view_only)
{ menusToRemove[menusToRemove.length] = '#menuEdit';}
if(!permits.del || permits.view_only)
{ menusToRemove[menusToRemove.length] = '#menuDelete';}
if(!permits.cut || permits.view_only)
{ menusToRemove[menusToRemove.length] = '#menuCut';}
if(!permits.copy || permits.view_only)
{ menusToRemove[menusToRemove.length] = '#menuCopy';}
if((!permits.cut && !permits.copy) || permits.view_only)
{ menusToRemove[menusToRemove.length] = '#menuPaste';}
if(!permits.rename || permits.view_only)
{ menusToRemove[menusToRemove.length] = '#menuRename';}
var txt = ''; for(var t in menu)
{ }
$(menu).children().children().children().each( function()
{ if(menusToRemove.inArray('#' + this.id))
{ $(this).parent().remove();}
}
)
return menu;}
} );}; var fileUploadElemIds = new Array(); function addMoreFile()
{ var newFileUpload = $($('div#TB_window #fileUploadBody tr').get(0)).clone(); do
{ var elementId = 'upload' + generateUniqueId(10);}while(fileUploadElemIds.inArray(elementId)); fileUploadElemIds[fileUploadElemIds.length] = elementId; $(newFileUpload).appendTo('div#TB_window #fileUploadBody'); $('input[@type=file]', newFileUpload).attr('id', elementId); $('span.uploadProcessing', newFileUpload).attr('id', 'ajax' + elementId); $('input[@type=button]', newFileUpload).click( function()
{ uploadFile(elementId);} ); $('a', newFileUpload).show().click( function()
{ cancelFileUpload(elementId);} ); $(newFileUpload).show(); return false;}; function cancelFileUpload(elementId)
{ $('div#TB_window #' + elementId).parent().parent().remove(); while($('div#TB_window #fileUploadBody tr').length < 2)
{ addMoreFile();}
return false;}; function uploadFile(elementId)
{ var ext = getFileExtension($('#' + elementId).val()); if(ext == '')
{ alert(noFileSelected ); return false;}
var supportedExts = supportedUploadExts.split(","); var isSupportedExt = false; for (i in supportedExts)
{ if(typeof(supportedExts[i]) == 'string')
{ isSupportedExt = true; break;}
}
if(!isSupportedExt)
{ alert(msgInvalidExt); return false;}
$('#ajax' + elementId).hide(); $('#ajax' + elementId).show(); $.ajaxFileUpload
( { url:appendQueryString(getUrl('upload', false, false), 'folder=' + currentFolder.path, ['folder']), secureuri:false, fileElementId:elementId, dataType: 'json', success: function (data, status)
{ if(typeof(data.error) != 'undefined')
{ if(data.error != '')
{ alert(data.error); $('#ajax' + elementId).hide();}else
{ cancelFileUpload(elementId); numRows++; files[numRows] = {}; for(var i in data)
{ if(i != 'error')
{ files[numRows][i] = data[i];}
}
addDocumentHtml(numRows);}
}
}, error: function (data, status, e)
{ $('#ajax' + elementId).hide(); alert(e);}
}
)
return false;}; function generateUniqueId(leng)
{ var idLength = leng || 32; var chars = "0123456789abcdefghijklmnopqurstuvwxyzABCDEFGHIJKLMNOPQURSTUVWXYZ"; var id = ''; for(var i = 0; i <= idLength; i++)
{ id += chars.substr( Math.floor(Math.random() * 62), 1 );}
return (id );}; function generateDownloadIframe(url)
{ var frameId = 'ajaxDownloadIframe'; $('#' + frameId).remove(); if(window.ActiveXObject) { var io = document.createElement('
');}
else { var io = document.createElement('iframe'); io.id = frameId; io.name = frameId;}
io.style.position = 'absolute'; io.style.top = '-1000px'; io.style.left = '-1000px'; io.src = url; document.body.appendChild(io);}; function showThickBox(linkElem, url)
{ $(linkElem).attr('href', url); var t = linkElem.title || linkElem.name || null; var a = linkElem.href || linkElem.alt; var g = linkElem.rel || false; tb_show(t,a,g); linkElem.blur(); return false;}; function uploadFileWin(linkElem)
{ showThickBox(linkElem, appendQueryString('#TB_inline', 'height=200' + '&width=450' + '&inlineId=winUpload&modal=true')); addMoreFile();}; function newFolderWin(linkElem)
{ showThickBox(linkElem, appendQueryString('#TB_inline', 'height=100' + '&width=250' + '&inlineId=winNewFolder&modal=true')); return false;}; function doCreateFolder()
{ $('div#TB_window #currentNewfolderPath').val(currentFolder.path); var pattern=/^[A-Za-z0-9_ \-]+$/i; var folder = $('div#TB_window #new_folder'); if(!pattern.test($(folder).val()))
{ alert(msgInvalidFolderName);}else
{ var options = { dataType: 'json', url:getUrl('create_folder'), error: function (data, status, e)
{ alert(e);}, success: function(data)
{ if(data.error != '')
{ alert(data.error);}else
{ numRows++; files[numRows] = {}; for(var i in data)
{ if(i != 'error')
{ files[numRows][i] = data[i];}
}
addDocumentHtml(numRows); tb_remove();}
}
}; $('div#TB_window #formNewFolder').ajaxSubmit(options);}
return false;}; function deleteDocuments(msgNoDocSelected, msgUnableToDelete, msgWarning, elements)
{ if(!window.confirm(warningDel))
{ return false;}
switch(getView())
{ case 'thumbnail':
var selectedDoc = $('#rightCol dl.thumbnailListing input[@type=checkbox][@checked]'); break; case 'detail':
default:
var selectedDoc = $('#fileList input[@type=checkbox][@checked]');}
var hiddenSelectedDoc = document.getElementById('selectedDoc'); var selectedOptions; var isSelected = false; $(hiddenSelectedDoc).removeOption(/./); $(selectedDoc).each(function(i){ $(hiddenSelectedDoc).addOption($(this).val(), getNum($(this).attr('id')), true); isSelected = true;}); if(!isSelected)
{ alert(msgNoDocSelected);}
else
{ var options = { dataType: 'json', url:getUrl('delete'), error: function (data, status, e)
{ alert(e);}, success: function(data)
{ if(typeof(data.error) == 'undefined')
{ alert('Unexpected error.');}else if(data.error != '')
{ alert(data.error);}else
{ for(var i =0; i < hiddenSelectedDoc.options.length; i++)
{ switch(getView())
{ case 'thumbnail':
$('#dl' + hiddenSelectedDoc.options[i].text).remove(); break; case 'detail':
default:
$('#row' + hiddenSelectedDoc.options[i].text).remove();}
}
}
}
}; $('#formAction').ajaxSubmit(options);}
return false;}; function doRename()
{ var num = $('div#TB_window #renameNum').val(); if(files[num].fileType == 'folder')
{ var pattern=/^[A-Za-z0-9_ \-]+$/i;}else
{ var pattern=/^[A-Za-z0-9_ \-\.]+$/i;}
if(!pattern.test($('div#TB_window #renameName').val()))
{ if(files[num].fileType == 'folder')
{ alert(msgInvalidFolderName);}else
{ alert(msgInvalidFileName);}
}else
{ var options = { dataType: 'json', url:getUrl('rename'), error: function (data, status, e)
{ alert(e);}, success: function(data)
{ if(data.error != '')
{ alert(data.error);}else
{ var info = ''; for(var i in data)
{ if(i != 'error')
{ files[num][i] = data[i];}
}
switch(getView())
{ case 'thumbnail':
$('#thumbUrl' + num).attr('href', files[num].path); $('#thumbImg' + num).attr('src', appendQueryString(getUrl('thumbnail'), 'path=' + files[num].path, ['path'])); $('#cb' + num).val(files[num].path); $('#a' + num).attr('href', files[num].path).text(files[num].name); break; case 'detail':
default:
$('#check' + num).val(files[num].path); $('#a' + num).attr('href', files[num].path); $('#tdnd' + num).text(files[num].name); $('#tdth' + num).text(files[num].name);}
tb_remove();}
}
}; $('div#TB_window #formRename').ajaxSubmit(options);}
}; function windowRefresh()
{ document.location.href = urls.present;}; function infoWin(linkElem)
{ showThickBox(linkElem, appendQueryString('#TB_inline', 'height=180' + '&width=500'+ '&inlineId=winInfo&modal=true'));}; function checkAll(checkbox)
{ if($(checkbox).attr('class') == "check_all")
{ $('#tickAll, #actionSelectAll').attr('class', 'uncheck_all'); $('#tickAll, #actionSelectAll').attr('title', unselectAllText); $('#actionSelectAll span').html(unselectAllText); switch(getView())
{ case 'thumbnail':
$('#rightCol dl.thumbnailListing input[@type=checkbox]').each(function(i){ $(this).attr("checked", 'checked');}) ; break; case 'detail':
default:
$("#fileList tr[@id^=row] input[@type=checkbox]").each(function(i){ $(this).attr("checked", 'checked');}) ;}
}else
{ $('#tickAll, #actionSelectAll').attr('class', 'check_all'); $('#tickAll, #actionSelectAll').attr('title', selectAllText); $('#actionSelectAll span').html( selectAllText); switch(getView())
{ case 'thumbnail':
$('#rightCol dl.thumbnailListing input[@type=checkbox]').each(function(i){ $(this).removeAttr("checked");}) ; break; case 'detail':
default:
$("#fileList tr[@id^=row] input[@type=checkbox]").each(function(i){ $(this).removeAttr("checked");}) ;}
}
return false;}; function cutDocuments(msgNoDocSelected)
{ repositionDocuments(msgNoDocSelected, getUrl('cut'), 'cut'); return false;}; function copyDocuments(msgNoDocSelected)
{ repositionDocuments(msgNoDocSelected, getUrl('copy'), 'copy'); return false;}; function repositionDocuments(msgNoDocSelected, formActionUrl, actionVal)
{ switch(getView())
{ case 'thumbnail':
var selectedDoc = $('#rightCol dl.thumbnailListing input[@type=checkbox][@checked]'); break; case 'detail':
default:
var selectedDoc = $('#fileList input[@type=checkbox][@checked]');}
var hiddenSelectedDoc = document.getElementById('selectedDoc'); var selectedOptions; var isSelected = false; $(hiddenSelectedDoc).removeOption(/./); $(selectedDoc).each(function(i){ $(hiddenSelectedDoc).addOption($(this).val(), getNum($(this).attr('id')), true); isSelected = true;}); if(!isSelected)
{ alert(msgNoDocSelected);}
else
{ var formAction = document.formAction; var actionElem = $('#action_value'); formAction.action = formActionUrl; $('#currentFolderPathVal').val(currentFolder.path); $(actionElem).val(actionVal); var options = { dataType: 'json', error: function (data, status, e)
{ alert(e);}, success: function(data)
{ if(typeof(data.error) == 'undefined')
{ alert('Unexpected Error');}
else if(data.error != '')
{ alert(data.error);}else
{ numFiles = parseInt(data.num); var flag = (actionVal == 'copy'?'copyFlag':'cutFlag'); action = actionVal; for(var i = 1; i < numRows; i++)
{ $('#flag' + i).attr('class', 'noFlag');}
for(var i =0; i < hiddenSelectedDoc.options.length; i++)
{ $('#flag' + hiddenSelectedDoc.options[i].text).attr('class', flag);}
}
}
}; $(formAction).ajaxSubmit(options);}
return false;}; function pasteDocuments(msgNoDocSelected)
{ if(numFiles)
{ var warningMsg = (action == 'copy'?warningCopyPaste:warningCutPaste); if(window.confirm(warningMsg))
{ $.getJSON(appendQueryString(getUrl('paste'), 'current_folder_path='+ currentFolder.path, ['current_folder_path']), function(json)
{ if(typeof(json.error) == 'undefined')
{ alert('Unexpected Error.');}
{ if(json.error != '')
{ alert(json.error);}
for(var j in json.files)
{ numRows++; files[numRows] = {}; for(var i in json.files[j])
{ files[numRows][i] = json.files[j][i];}
addDocumentHtml(numRows);}
numFiles = parseInt(json.unmoved_files);}
} );}
}else
{ alert(msgNoDocSelected);}
return false;}; function addDocumentHtml(num)
{ var strDisabled = ""; if(!files[num].is_writable)
{ strDisabled = "disabled";}
switch(getView())
{ case 'thumbnail':
$( '
' + (typeof(files[num].short_name) != 'undefined'?files[num].short_name:files[num].name) + ' ').appendTo('#content'); if(files[num].type== 'folder')
{ enableFolderBrowsable(num);}else
{ switch(files[num].cssClass)
{ case 'filePicture':
$('
').appendTo('#dt' + num); break; case 'fileFlash':
break; case 'fileVideo':
break; case 'fileMusic':
break; default:
}
enablePreview('#dl' + num + ' a', [num]);}
enableContextMenu('#dl' + num); enableShowDocInfo( num); break; case 'detail':
default:
var cssRow = (num % 2?"even":"odd"); $('
' + (typeof(files[num].short_name) != 'undefined'?files[num].short_name:files[num].name) + ' ' + files[num].size +' ' + files[num].mtime +' ').appendTo('#fileList'); if(files[num].type== 'folder')
{ enableFolderBrowsable(num);}else
{ switch(files[num].cssClass)
{ case 'filePicture':
break; case 'fileFlash':
break; case 'fileVideo':
break; case 'fileMusic':
break; default:
}
enablePreview('#row' + num + ' td a', num);}
enableContextMenu('#row' + num); enableShowDocInfo(num); break;}
}; function enableShowDocInfo(num)
{ $('#cb' + num).click( function()
{ setDocInfo('doc', num);} );}; function setDocInfo(type, num)
{ var info = {}; if(type == 'root')
{ info = currentFolder;}else
{ info = files[num];}
if(info.type=="folder")
{ $('#folderPath').text(info.name); $('#folderFile').text(info.file); $('#folderSubdir').text(info.subdir); $('#folderCtime').text(info.ctime); $('#folderMtime').text(info.mtime); if(info.is_readable == '1')
{ $('#folderReadable').html("
");}else
{ $('#folderReadable').html("
");}
if(info.is_writable == '1')
{ $('#folderWritable').html("
");}else
{ $('#folderWritable').html("
");}
$('#folderFieldSet').css('display', ''); $('#fileFieldSet').css('display', 'none');}else
{ $('#fileName').text(info.name); $('#fileSize').text(info.size); $('#fileType').text(info.fileType); $('#fileCtime').text(info.ctime); $('#fileMtime').text(info.mtime); if(info.is_readable == '1')
{ $('#fileReadable').html("
");}else
{ $('#fileReadable').html("
");}
if(info.is_writable == '1')
{ $('#fileWritable').html("
");}else
{ $('#fileWritable').html("
");}
$('#folderFieldSet').css('display', 'none'); $('#fileFieldSet').css('display', ''); if(typeof(selectFile) != 'undefined')
{ $('#selectCurrentUrl').unbind('click').click( function()
{ selectFile(info.url);} ); $('#returnCurrentUrl').show();}else
{ $('#returnCurrentUrl').hide();}
}
}; function search()
{ searchRequired = true; var url = getUrl('view', true, true, true); $('#rightCol').empty(); ajaxStart('#rightCol'); $('#rightCol').load(url, {}, function(){ ajaxStop('#rightCol img.ajaxLoadingImg'); initAfterListingLoaded();}); return false;}; function closeWinPlay()
{ tb_remove(); $('#playGround').empty();}; function closeWindow(msg)
{ if(window.confirm(msg))
{ window.close();}else
{ return false;}
};
//ajaxfilemanager general end