home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2008 April
/
PCWorld_2008-04_cd.bin
/
komunikace
/
maxthon
/
mx_2.0.8.1720.exe
/
template
/
Download
/
maxDownload.js
< prev
Wrap
Text File
|
2008-02-01
|
18KB
|
695 lines
var maxDownload={};
maxDownload.categoryIdList={"incomplete":"14","completed":"12","all":"10","deleted":"3","search":"10"};
maxDownload.defaultCategory="incomplete",maxDownload.updateFreq=1000;
maxDownload.fatalError=false;
maxDownload.taskList=[];
maxDownload.itemCount=0;
maxDownload.pageSize=12;
maxDownload.currentPage=1;
maxDownload.checkedIDList={};
maxDownload.checkedCount=0;
$langDefaultSection="Downloader";
maxDownload.init=function(){
document.title=$lang("title");
maxDownload.initObject();
maxDownload.buildTaskList();
maxDownload.adjustHeight();
window.onresize=maxDownload.adjustHeight;
var _1=$cookies("activePage");
if(maxDownload.categoryIdList[_1]){
maxDownload.defaultCategory=_1;
}
maxDownload.currentCategory=maxDownload.defaultCategory;
maxDownload.activateCategory(maxDownload.defaultCategory);
maxDownload.dataUpdater();
};
maxDownload.initObject=function(){
try{
maxDownload.objDownload=new ActiveXObject("MxDownloadServer.ThunderMx.1");
}
catch(e){
maxDownload.msgObjectError();
}
};
maxDownload.msgObjectError=function(){
maxDownload.fatalError=true;
var _2=$id("errorMessage");
_2.style.display="block";
_2.innerHTML=$lang("download_object_fail").$encodeHTML()+" "+"<a href=\"javascript:;\" onclick=\"maxDownload.reload()\">"+$lang("download_object_fail_retry").$encodeHTML()+"</a>";
};
maxDownload.reload=function(){
maxDownload.fatalError=false;
$id("errorMessage").style.display="none";
maxDownload.initObject();
maxDownload.dataUpdater();
};
maxDownload.showSettings=function(){
try{
maxDownload.objDownload.ShowSetting();
}
catch(e){
maxDownload.msgObjectError();
}
};
maxDownload.activateCategory=function(_3){
if(maxDownload.currentCategory=="search"){
maxDownload.resetSearch();
var _4=$id("searchButton");
_4.src="images/search.png";
_4.onclick=maxDownload.updateTaskList;
}
maxDownload.switchCategoryUI(_3);
if(_3!="search"&&_3!="deleted"){
$cookies("activePage",_3);
}
maxDownload.updateTaskList();
};
maxDownload.switchCategoryUI=function(_5){
if(!maxDownload.categoryIdList[_5]){
alert("maxDownload.activateCategory :: invalid type \""+_5+"\"");
}
var _6="";
var _7="buttons-active";
if(_5=="search"){
_7="label buttons-active";
}
if(maxDownload.currentCategory=="search"){
_6="label";
}
$id("page_"+maxDownload.currentCategory).className=_6;
$id("page_"+_5).className=_7;
if(_5!="search"){
$id("num_"+_5).className="";
}
if(_5=="search"||_5=="deleted"||_5=="completed"){
$id("ucontrol").style.display="none";
}else{
$id("ucontrol").style.display="inline";
}
maxDownload.currentCategory=_5;
maxDownload.currentPage=1;
};
maxDownload.resetSearch=function(_8){
$id("searchBar").value="";
};
maxDownload.dataUpdater=function(){
if(maxDownload.fatalError){
return;
}
var _9=$id("searchBar").value;
var _a=false;
_9=_9.$trim();
var _b=$id("searchButton");
if(_9!=""){
_b.src="images/reset.png";
_b.onclick=maxDownload.resetSearch;
maxDownload.switchCategoryUI("search");
}else{
_9=false;
if(maxDownload.currentCategory=="search"){
maxDownload.activateCategory(maxDownload.defaultCategory);
}
}
maxDownload.updateCounter();
maxDownload.updateTaskList(_9);
setTimeout(maxDownload.dataUpdater,maxDownload.updateFreq);
};
maxDownload.lastCounter=[-1,-1,-1,-1];
maxDownload.updateCounter=function(){
var _c=[];
try{
_c=maxDownload.objDownload.GetTaskCount2("14{\r\r*\r\r}12{\r\r*\r\r}10{\r\r*\r\r}3");
}
catch(e){
maxDownload.msgObjectError();
return;
}
_c=_c.split("{\r\r*\r\r}");
var _d=[];
for(var i=0;i<_c.length;i++){
var _f=_c[i];
if(_f.length<1){
continue;
}
_f=_f.split("{\r*\r}");
_d.push(_f[1]);
}
var _10=["num_incomplete","num_completed","num_all","num_deleted"];
for(var i=0;i<_d.length;i++){
if(_d[i]!=0){
$id(_10[i]).innerHTML="("+_d[i]+")";
}else{
$id(_10[i]).innerHTML="";
}
if(maxDownload.lastCounter[i]>-1){
if(_d[i]>maxDownload.lastCounter[i]){
$id(_10[i]).className="num-highlight";
}
}
}
maxDownload.lastCounter=_d;
};
maxDownload.buildTaskList=function(){
downloadTable=maxTable.create("downloadTable");
downloadTable.controlUI["delete"]=$lang("delete");
downloadTable.controlUI["cancel"]=$lang("cancel");
downloadTable.controlUI["checkbox"]="<img src=\"../_shared/images/btn_check.png\" />";
downloadTable.controlUI["checkbox_checked"]="<img src=\"../_shared/images/btn_check_checked.png\" />";
downloadTable.controlUI["move_up"]="<img src=\"../_shared/images/btn_up.png\" />";
downloadTable.controlUI["move_down"]="<img src=\"../_shared/images/btn_down.png\" />";
downloadTable.columns=[{title:"<div onclick=\"maxDownload.checkAll()\" style=\"cursor:pointer\"><img id=\"btnCheckAll\" src=\"../_shared/images/btn_check.png\" /></div>",name:"checked",type:"checkbox",width:18},{title:" ",name:"status",type:"custom",width:18,customBuilder:maxDownload.buildItemHTML},{title:$lang("filename"),name:"fileName",type:"custom",customBuilder:maxDownload.buildItemHTML},{title:$lang("size"),name:"size",type:"custom",width:100,customBuilder:maxDownload.buildItemHTML},{title:$lang("progress"),name:"percent",type:"custom",width:150,customBuilder:maxDownload.buildItemHTML},{title:$lang("time_used"),name:"timeUsed",type:"custom",width:120,customBuilder:maxDownload.buildItemHTML}];
downloadTable.dataType="object";
downloadTable.data=maxDownload.taskList;
downloadTable.showEditControl=false;
downloadTable.allowEditSeparator=false;
downloadTable.allowInsert=false;
downloadTable.confirmDelete=false;
downloadTable.tableTag=" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\"",downloadTable.editControl=[{type:"delete",hideOnNew:true},{type:"html",value:" | ",hideOnNew:true},{type:"cancel"}];
downloadTable.lang["delete_confirm"]=$lang("confirm_delete_task");
downloadTable.event["beforeDelete"]=maxDownload.deleteTask;
downloadTable.event["afterCheckboxClick"]=maxDownload.checkItem;
maxTable.init(downloadTable);
};
maxDownload.adjustHeight=function(){
var obj=$id("contentWrapper");
if(!obj){
return;
}
var _12=document.documentElement.clientHeight-160;
obj.style.height=_12-10;
};
maxDownload.buildItemHTML=function(_13,_14){
var _15=downloadTable.data[_13];
var _16="";
if(_14==1){
if(_15.status<2){
_16="<a href=\"javascript:;\" onclick=\"maxDownload.stopTask('"+_15.id+"')\"><img src=\"images/check.png\" alt=\""+$lang("status_check")+"\"/></a>";
}else{
if(_15.status==2){
_16="<a href=\"javascript:;\" onclick=\"maxDownload.stopTask('"+_15.id+"')\"><img src=\"images/run.png\" alt=\""+$lang("status_run")+"\" /></a>";
}else{
if(_15.status==10){
_16="<a href=\"javascript:;\" onclick=\"maxDownload.startTask('"+_15.id+"')\"><img src=\"images/pause.png\" alt=\""+$lang("status_pause")+"\" /></a>";
}else{
if(_15.status==11){
_16="<a href=\"javascript:;\" onclick=\"maxDownload.restartTask('"+_15.id+"')\"><img src=\"images/done.png\" alt=\""+$lang("status_done")+"\" /></a>";
}else{
_16="<a href=\"javascript:;\" onclick=\"maxDownload.startTask('"+_15.id+"')\"><img src=\"images/error.png\" alt=\""+$lang("status_error")+"\" /></a>";
}
}
}
}
}else{
if(_14==2){
if(downloadTable.inAction=="edit"&&downloadTable.inEditDataIndex==_13){
var _17=maxDownload.getTaskDetail(_15.id);
_16="<strong>"+_15.fileName.$encodeHTML()+"</strong>";
_16+=maxDownload.buildEditControlHTML();
}else{
_16+="<span style=\"float:right\">";
if(_15.status==11){
_16+="<a href=\"javascript:;\" onclick=\"maxDownload.openFile('"+_15.id+"');event.cancelBubble=true;\">"+$lang("open")+"</a> ";
}
_16+="<a href=\"javascript:;\" onclick=\"maxDownload.openTaskFolder('"+_15.id+"');event.cancelBubble=true;\">"+$lang("o_folder")+"</a>";
_16+="</span>";
_16+=_15.fileName.$encodeHTML().$cut(50);
}
}else{
if(_14==3){
_16=maxDownload.fileSizeString(_15.size);
}else{
if(_14==4){
var _18;
if(_15.status<2){
_18=" progressBarStop";
}else{
if(_15.status==2){
_18="";
}else{
if(_15.status==10){
_18=" progressBarStop";
}else{
if(_15.status==11){
_18=" progressBarDone";
}else{
_18=" progressBarError";
}
}
}
}
_16+="<div class=\"progressBarOuter\" style=\"width:100%\">";
if(_15.status==2){
_16+="<div class=\"speed\">"+maxDownload.speedString(_15.speed)+"</div>";
}
_16+="<div class=\"progressBar"+_18+"\" style=\"width:"+Math.floor(100*_15.progress)+"%;\"> "+maxDownload.progressString(_15.progress)+"</div>";
_16+="</div>";
}else{
if(_14==5){
var _19=maxDownload.timeString(_15.timeUsed);
if(_19==""){
_19="00:00:00";
}
var _1a=maxDownload.timeString(_15.timeLeft);
_16=_19+(_1a!=""?" <span class=\"timeLeft\">("+_1a+")</span>":"");
}
}
}
}
}
return _16;
};
maxDownload.fileSizeString=function(_1b){
var _1c=_1b;
if(isNaN(_1c)){
return "0";
}
if(_1c==0){
return "0";
}
var _1d="Bytes";
if((_1c/1073741824)>1){
_1c=(_1c/1073741824).toString();
_1d="GB";
}else{
if((_1c/1048576)>1){
_1c=(_1c/1048576).toString();
_1d="MB";
}else{
if((_1c/1024)>1){
_1c=(_1c/1024).toString();
_1d="KB";
}else{
_1c=_1c.toString();
_1d="Bytes";
}
}
}
if(_1c.indexOf(".")>-1){
_1c=_1c.substr(0,_1c.indexOf(".")+2);
}
return _1c+" "+_1d;
};
maxDownload.speedString=function(_1e){
var _1f=_1e;
if(isNaN(_1f)){
return "0";
}
if(_1f==0){
return "0";
}
var _20="Bytes";
if((_1f/1073741824)>1){
_1f=(_1f/1073741824).toString();
_20="GB/s";
}else{
if((_1f/1048576)>1){
_1f=(_1f/1048576).toString();
_20="MB/s";
}else{
if((_1f/1024)>1){
_1f=(_1f/1024).toString();
_20="KB/s";
}else{
_1f=_1f.toString();
_20="B/s";
}
}
}
if(_1f.indexOf(".")>-1){
_1f=_1f.substr(0,_1f.indexOf(".")+2);
}
return _1f+" "+_20;
};
maxDownload.progressString=function(_21){
var _22=_21;
if(isNaN(_22)){
return "0";
}
_22=(_22*100).toString();
if(_22.length>5){
_22=_22.substr(0,5);
}
_22+="%";
return _22;
};
maxDownload.timeString=function(_23){
if(_23<1){
return "";
}
var hr=Math.floor(_23/3600).toString();
if(hr.length==1){
hr="0"+hr;
}
var min=Math.floor((_23%3600)/60).toString();
if(min.length==1){
min="0"+min;
}
var sec=(_23%60).toString();
if(sec.length==1){
sec="0"+sec;
}
return hr+":"+min+":"+sec;
};
maxDownload.buildEditControlHTML=function(){
var _27=downloadTable.data[downloadTable.inEditDataIndex];
var _28="<p class=\"inline-control\">";
if(_27.status==10||_27.status==12){
_28+="<a href=\"javascript:;\" onclick=\"maxDownload.startTask('"+_27.id+"')\">"+$lang("start")+"</a> | ";
}
if(_27.status<=2){
_28+="<a href=\"javascript:;\" onclick=\"maxDownload.stopTask('"+_27.id+"')\">"+$lang("stop")+"</a> | ";
}
if(_27.status==11){
_28+="<a href=\"javascript:;\" onclick=\"maxDownload.openFile('"+_27.id+"')\">"+$lang("open_file")+"</a> | ";
}
_28+="<a href=\"javascript:;\" onclick=\"maxDownload.openTaskFolder('"+_27.id+"')\">"+$lang("open_folder")+"</a> | ";
_28+="<a href=\"javascript:;\" onclick=\"maxTable.action.deleteEdit("+downloadTable.objID+")\">"+downloadTable.controlUI["delete"]+"</a> | ";
if(_27.status==11){
_28+="<a href=\"javascript:;\" onclick=\"maxDownload.restartTask('"+_27.id+"')\">"+$lang("restart")+"</a> | ";
}
_28+="<a href=\"javascript:;\" onclick=\"maxDownload.showTaskProperties('"+_27.id+"')\">"+$lang("show_prop")+"</a> | ";
_28+="<a href=\"javascript:;\" onclick=\"maxTable.action.cancelEdit("+downloadTable.objID+")\">"+downloadTable.controlUI["cancel"]+"</a>";
_28+="</p>";
return _28;
};
maxDownload.loadTaskList=function(_29){
var _2a;
try{
if(_29){
_2a=maxDownload.objDownload.SearchTaskList("10="+_29,(maxDownload.currentPage-1)*maxDownload.pageSize,maxDownload.pageSize,0);
}else{
_2a=maxDownload.objDownload.GetTaskList(maxDownload.categoryIdList[maxDownload.currentCategory],(maxDownload.currentPage-1)*maxDownload.pageSize,maxDownload.pageSize,0);
}
}
catch(e){
maxDownload.msgObjectError();
return [];
}
_2a=_2a.split("{\r\r*\r\r}");
var _2b={};
var _2c=0;
var _2d=[];
for(var i=0;i<_2a.length;i++){
var _2f=_2a[i];
if(_2f.length<10){
continue;
}
_2f=_2f.split("{\r*\r}");
var _30={};
_30.id=_2f[1];
_30.tag=_2f[3];
_30.status=parseInt(_2f[4],10);
_30.speed=parseInt(_2f[5],10);
_30.progress=parseFloat(_2f[6]);
_30.size=parseInt(_2f[8],10);
_30.timeUsed=parseInt(_2f[9],10);
_30.timeLeft=parseInt(_2f[10],10);
_30.createDate=_2f[11];
_30.fileName=_2f[14];
_30.fileExtension=_2f[15];
_30.checked=(maxDownload.checkedIDList[_30.id]==true)?true:false;
if(_30.checked){
_2b[_30.id]=true;
_2c++;
}
_2d.push(_30);
}
var _31=parseInt(_2a[0],10);
if(isNaN(_31)){
_31=_2d.length;
}
maxDownload.itemCount=_31;
maxDownload.checkedIDList=_2b;
maxDownload.checkedCount=_2c;
return _2d;
};
maxDownload.getTaskDetail=function(id){
var _33={"url":"","referer":"","folder":""};
var _34;
try{
_34=maxDownload.objDownload.GetTaskInfo(id);
}
catch(e){
maxDownload.msgObjectError();
}
_34=_34.split("{\r*\r}");
_33.url=_34[3];
_33.referer=_34[3];
_33.folder=_34[7];
return _33;
};
maxDownload.updateTaskList=function(_35){
if(maxDownload.updatingTaskList){
return;
}
maxDownload.updatingTaskList=true;
var _36=maxDownload.loadTaskList(_35);
var _37=maxDownload.taskList;
var _38=_36.length;
var _39=_37.length;
var _3a=_38<_39?_38:_39;
var _3b="";
var _3c=-1;
var _3d=false;
if(downloadTable.inAction=="edit"||downloadTable.inAction=="add"){
var x=downloadTable.inEditDataIndex;
if(maxDownload.isEqualTask(_36[x],_37[x])){
_3d=false;
_3c=i;
}else{
if(_37[x]){
_3b=_37[x].id;
}
_3d=true;
}
}
for(var i=0;i<_3a;i++){
if(maxDownload.isEqualTask(_36[i],_37[i])==false){
_37[i]=_36[i];
maxTable.ui.updateRow(downloadTable,i);
}
}
if(_38>_39){
for(var i=_39;i<_38;i++){
maxTable.ui.addRow(downloadTable,false,_36[i]);
}
}
if(_38<_39){
for(var i=_38;i<_39;i++){
maxTable.ui.deleteRow(downloadTable,_38);
}
}
maxDownload.updateCheckAllUI();
maxDownload.updateStats();
maxDownload.updatePageLinks();
maxDownload.updatingTaskList=false;
};
maxDownload.isEqualTask=function(_40,_41){
if(!_40||!_41){
return false;
}
if(_40.checked!=_41.checked){
return false;
}
if(_40.id!=_41.id){
return false;
}
if(_40.status!=_41.status){
return false;
}
if(_40.speed!=_41.speed){
return false;
}
if(_40.progress!=_41.progress){
return false;
}
return true;
};
maxDownload.checkItem=function(_42,_43){
var _44=downloadTable.data[_42];
if(_44.checked){
maxDownload.checkedIDList[_44.id]=true;
maxDownload.checkedCount++;
}else{
maxDownload.checkedIDList[_44.id]=null;
maxDownload.checkedCount--;
}
maxDownload.updateCheckAllUI();
};
maxDownload.checkAll=function(){
var val=false;
if(downloadTable.data.length!=maxDownload.checkedCount){
val=true;
maxDownload.checkedCount=downloadTable.data.length;
}else{
maxDownload.checkedCount=0;
}
maxDownload.updateCheckAllUI();
for(var i=0;i<downloadTable.data.length;i++){
var _47=downloadTable.data[i];
if(_47.checked!=val){
maxDownload.checkedIDList[_47.id]=val;
maxTable.ui.doCheckbox(downloadTable,i,0,val);
}
}
};
maxDownload.updateCheckAllUI=function(){
if(downloadTable.data.length!=maxDownload.checkedCount||maxDownload.checkedCount==0){
$id("btnCheckAll").src="../_shared/images/btn_check.png";
}else{
$id("btnCheckAll").src="../_shared/images/btn_check_checked.png";
}
};
maxDownload.updateStats=function(){
$id("stats").innerHTML=$lang("item_count").replace("%i",maxDownload.itemCount);
};
maxDownload.updatePageLinks=function(){
var obj=$id("pagerWrapper");
var _49="";
if(maxDownload.oldItemCount==maxDownload.itemCount&&maxDownload.oldCurrentPage==maxDownload.currentPage){
return;
}
maxDownload.oldItemCount=maxDownload.itemCount;
maxDownload.oldCurrentPage=maxDownload.currentPage;
if(maxDownload.itemCount>maxDownload.pageSize){
var _4a={"separator":"","normal":"<a href=\"javascript:maxDownload.setPage(%page);\">%page</a>","active":"<a href=\"javascript:;\" class=\"active\">%page</a>","prev":"<a href=\"javascript:maxDownload.setPage(%page);\">‹</a>","next":"<a href=\"javascript:maxDownload.setPage(%page);\">›</a>","first":"<a href=\"javascript:maxDownload.setPage(%page);\">«</a>","last":"<a href=\"javascript:maxDownload.setPage(%page);\">»</a>"};
_49=$pageLinks(maxDownload.itemCount,maxDownload.pageSize,maxDownload.currentPage,10,_4a);
obj.innerHTML=_49;
obj.style.display="inline";
}else{
obj.style.display="none";
}
};
maxDownload.setPage=function(_4b){
maxTable.action.cancelEdit(downloadTable);
maxDownload.currentPage=_4b;
maxDownload.updateTaskList();
};
maxDownload.addTask=function(){
try{
maxDownload.objDownload.CallAddTask("","","",0,"","");
}
catch(e){
maxDownload.msgObjectError();
}
maxDownload.updateTaskList();
};
maxDownload.deleteTask=function(_4c){
var _4d;
try{
_4d=maxDownload.objDownload.DeleteTask(_4c.id,0);
}
catch(e){
maxDownload.msgObjectError();
}
if(_4d==0){
return true;
maxDownload.updateTaskList();
}else{
return false;
}
};
maxDownload.deleteSelected=function(){
var _4e="";
for(var i=0;i<downloadTable.data.length;i++){
var _50=downloadTable.data[i];
if(_50.checked!=true){
continue;
}
_4e+=_50.id+"{\r*\r}";
}
if(_4e==""){
return;
}
try{
maxDownload.objDownload.DeleteTask(_4e,0);
}
catch(e){
maxDownload.msgObjectError();
return;
}
maxDownload.updateTaskList();
};
maxDownload.startTask=function(id){
try{
maxDownload.objDownload.StartTask(id);
}
catch(e){
maxDownload.msgObjectError();
}
maxDownload.cancelEventBubble();
maxDownload.updateTaskList();
};
maxDownload.stopTask=function(id){
try{
maxDownload.objDownload.StopTask(id);
}
catch(e){
maxDownload.msgObjectError();
}
maxDownload.cancelEventBubble();
maxDownload.updateTaskList();
};
maxDownload.startAll=function(){
try{
maxDownload.objDownload.StartAll();
}
catch(e){
maxDownload.msgObjectError();
}
maxDownload.updateTaskList();
};
maxDownload.stopAll=function(){
try{
maxDownload.objDownload.StopAll();
}
catch(e){
maxDownload.msgObjectError();
}
maxDownload.updateTaskList();
};
maxDownload.restartTask=function(id){
if(confirm($lang("confirm_restart"))){
try{
maxDownload.objDownload.DownloadAgain(id,1);
}
catch(e){
maxDownload.msgObjectError();
}
maxDownload.updateTaskList();
}
maxDownload.cancelEventBubble();
};
maxDownload.showTaskProperties=function(id){
try{
maxDownload.objDownload.ShowTaskProp(id);
}
catch(e){
maxDownload.msgObjectError();
}
};
maxDownload.openFile=function(id){
try{
maxDownload.objDownload.OpenTaskFile(id);
}
catch(e){
maxDownload.msgObjectError();
}
};
maxDownload.openTaskFolder=function(id){
try{
maxDownload.objDownload.OpenTaskFolder(id);
}
catch(e){
maxDownload.msgObjectError();
}
};
maxDownload.cancelEventBubble=function(){
if(!window.event){
return;
}
window.event.cancelBubble=true;
window.event.returnValue=false;
};