﻿(function($){$.filebrowser={version:'1.0'};$.fn.filebrowser=function(dynamics){dynamics=$.extend({_object:'#filebrowser',_width:0,_height:'',_color:0,_root:'',_requestedFolder:'',_selectedFolder:'',_selectedFile:'',_folderSequence:0,_browserHistory:''},dynamics);var browser={initialize:function(){var e=$(dynamics._object);$(dynamics._object).css({width:(dynamics._width-2)+'px',height:(dynamics._height-2)+'px','border-color':'#'+dynamics._color,'border-style':'solid','border-width':'1px','background-color':'#ffffff'});$(dynamics._object).append('<div class="longFolderNameBox"></div>');$('.longFolderNameBox').css({opacity:0}).hide();$(dynamics._object).append('<div class="toolbar"></div>');$('.toolbar').css({width:(dynamics._width-6)+'px',padding:'3px'});var toolbarButtons=new String();toolbarButtons=toolbarButtons+'<li class="lastFolderDisabled" style="display:none;"></li>';toolbarButtons=toolbarButtons+'<li class="upFolderDisabled" style="display:none;"></li>';toolbarButtons=toolbarButtons+'<li class="addressBarHeader"></li>';toolbarButtons=toolbarButtons+'<li class="addressBar"></li>';toolbarButtons=toolbarButtons+'<li class="addressBarRefresh"></li>';$('.toolbar').html(toolbarButtons);$('.addressBar').css({width:(dynamics._width-91)+'px'}).html('<span folder="ogBrowser_files" folderSequence="0">'+dynamics._root+' /</span> ');$(dynamics._object).append('<div class="browserScreen"></div>');$('.browserScreen').css({width:(dynamics._width-22)+'px',height:(dynamics._height-45)+'px'});toTopLevel();}};function toBack(){var history=new Array();var historyFolders=new Array();history=dynamics._browserHistory.split('|||');historyFolders=history[history.length-2].split(',,');targetFolder=historyFolders[0];targetSequence=historyFolders[1];var x=history.length-2;delete history[history[x]];dynamics._requestedFolder=targetFolder;dynamics._folderSequence=targetSequence;toFolder();}function toUpLevel(){var currentFolder=new Array();currentFolder=dynamics._requestedFolder.split('/');finalPath='';folderSequence=0;for(i=0;i<currentFolder.length-1;i++){finalPath=finalPath==''?(currentFolder[i]):(finalPath+"/"+currentFolder[i]);folderSequence++;}dynamics._requestedFolder=finalPath;dynamics._folderSequence=folderSequence;toFolder();}function toTopLevel(){dynamics._requestedFolder='ogBrowser_files';dynamics._folderSequence=0;dynamics._browserHistory=dynamics._browserHistory==''?('ogBrowser_files'+',,'+'0'):(dynamics._browserHistory+'|||'+'ogBrowser_files'+',,'+'0');toFolder();}function toFolder(){folder=dynamics._requestedFolder;if(dynamics._folderSequence>0){$('li.upFolderEnabled').click(function(){toUpLevel();});$('li.upFolderDisabled').removeClass('upFolderDisabled').addClass('upFolderEnabled');}else{$('li.upFolderEnabled').removeClass('upFolderEnabled').addClass('upFolderDisabled');}if(dynamics._browserHistory!==''){$('li.lastFolderEnabled').click(function(){toBack();});$('li.lastFolderDisabled').removeClass('lastFolderDisabled').addClass('lastFolderEnabled');}else{$('li.lastFolderEnabled').removeClass('lastFolderEnabled').addClass('lastFolderDisabled');}$('.addressBar span').each(function(){if($(this).attr('folderSequence')>dynamics._folderSequence){$(this).remove();}});$.post('process.asp',{folder:''+folder+''},function(data){var dataArray=new Array();var folderArray=new Array();var fileArray=new Array();dataArray=data.split('///');folderArray=dataArray[0].split('||');fileArray=dataArray[1].split('||');$('.browserScreen').html('');if(folderArray.length>1){for(i=0;i<folderArray.length;i++){var wordLength=folderArray[i].length;totalWordLength=wordLength>12?(10):(wordLength);var folderName=new String();folderName=folderArray[i].substring(0,totalWordLength);folderName=wordLength>12?(folderName+'...'):(folderName);var folderID=new Number();folderID=Math.round(Math.random()*99999999);$('.browserScreen').append('<li class="browserFolder" folderName="'+folderArray[i]+'" id="'+folderID+'" path="'+folderArray[i+2]+'"><div class="folder"></div><div class="name">'+folderName+'</div></li>');i++;i++;}}if(fileArray.length>1){for(i=1;i<fileArray.length;i++){var wordLength=fileArray[i].length;totalWordLength=wordLength>12?(10):(wordLength);var fileName=new String();fileName=fileArray[i].substring(0,totalWordLength);fileName=wordLength>12?(fileName+'...'):(fileName);var fileID=new Number();fileID=Math.round(Math.random()*99999999);$('.browserScreen').append('<li class="browserFile" fileName="'+fileArray[i]+'" id="'+fileID+'" path="'+fileArray[i+2]+'" size="'+fileArray[i+1]+'"><div class="file"></div><div class="name">'+fileName+'</div></li>');$('li.browserFile[id='+fileID+'] div.file').css({'background-image':'url(images/'+fileArray[i+3]+'.png)','background-repeat':'no-repeat','background-position':'center'});i++;i++;i++;}}$('.browserFile').mouseover(function(e){var wordLength=$(this).attr('fileName').length;if(dynamics._selectedFile!==$(this).attr('id')){$(this).css({'background-image':'url(images/bg_2.png)'});if(wordLength>12){$('.longFolderNameBox').html($(this).attr('fileName')).stop().show().animate({opacity:1},300,"linear");$('.longFolderNameBox').css({top:(e.pageY+15)+"px",left:(e.pageX+15)+"px"});}}}).mousemove(function(e){var wordLength=$(this).attr('fileName').length;if(dynamics._selectedFile!==$(this).attr('id')){$(this).css({'background-image':'url(images/bg_2.png)'});$('.longFolderNameBox').html($(this).attr('fileName')+' / <b>'+$(this).attr('size')+' KB</b>').stop().show().animate({opacity:1},300,"linear");$('.longFolderNameBox').css({top:(e.pageY+15)+"px",left:(e.pageX+15)+"px"});}}).mouseout(function(){var wordLength=$(this).attr('fileName').length;if(dynamics._selectedFile!==$(this).attr('id')){$(this).css({'background-image':''});$('.longFolderNameBox').stop().animate({opacity:0},300,"linear",function(){$('.longFolderNameBox').hide();});}}).click(function(){$('.browserFile').css({'background-image':''});$('.longFolderNameBox').css({opacity:0}).hide();if(dynamics._selectedFile!==$(this).attr('id')){$(this).css({'background-image':'url(images/bg.png)'});dynamics._selectedFile=$(this).attr('id');}}).dblclick(function(){window.open(dynamics._requestedFolder+'/'+$(this).attr('fileName'),"_blank");});$('.browserFolder').mouseover(function(e){var wordLength=$(this).attr('folderName').length;if(dynamics._selectedFolder!==$(this).attr('id')){$(this).css({'background-image':'url(images/bg_2.png)'});if(wordLength>12){$('.longFolderNameBox').html($(this).attr('folderName')).stop().show().animate({opacity:1},300,"linear");$('.longFolderNameBox').css({top:(e.pageY+15)+"px",left:(e.pageX+15)+"px"});}}}).mousemove(function(e){var wordLength=$(this).attr('folderName').length;if(dynamics._selectedFolder!==$(this).attr('id')){$(this).css({'background-image':'url(images/bg_2.png)'});if(wordLength>12){$('.longFolderNameBox').html($(this).attr('folderName')).stop().show().animate({opacity:1},300,"linear");$('.longFolderNameBox').css({top:(e.pageY+15)+"px",left:(e.pageX+15)+"px"});}}}).mouseout(function(){var wordLength=$(this).attr('folderName').length;if(dynamics._selectedFolder!==$(this).attr('id')){$(this).css({'background-image':''});if(wordLength>12){$('.longFolderNameBox').stop().animate({opacity:0},300,"linear",function(){$('.longFolderNameBox').hide();});}}}).click(function(){$('.browserFolder').css({'background-image':''});$('.longFolderNameBox').css({opacity:0}).hide();if(dynamics._selectedFolder!==$(this).attr('id')){$(this).css({'background-image':'url(images/bg.png)'});dynamics._selectedFolder=$(this).attr('id');}}).dblclick(function(){var path=new String($(this).attr('path'));var pathArray=new Array();var getpath=new Boolean();getpath=false;pathArray=path.split('//');finalPath='';folderSequence=0;for(i=0;i<pathArray.length;i++){if(pathArray[i]=='ogBrowser_files'){getpath=true;}if(getpath){finalPath=finalPath==''?(pathArray[i]):(finalPath+"/"+pathArray[i]);folderSequence++;}}dynamics._browserHistory=dynamics._browserHistory==''?(finalPath+',,'+folderSequence):(dynamics._browserHistory+'|||'+finalPath+',,'+folderSequence);$('.addressBar').html($('.addressBar').html()+'<span folder="'+finalPath+'" folderSequence="'+folderSequence+'">'+$(this).attr('folderName')+' /</span> ');$('.addressBar span').click(function(){folder=$(this).attr('folder');folderSequence=$(this).attr('folderSequence');dynamics._requestedFolder=folder;dynamics._folderSequence=folderSequence;toFolder();});dynamics._requestedFolder=finalPath;dynamics._folderSequence=folderSequence;toFolder();});});}browser.initialize();};})(jQuery);
