fix: 修复v1.6.0-beta手机版无法加载的BUG

This commit is contained in:
ronggang 2018-09-06 16:51:22 +08:00
parent 73160d73a9
commit d2e2fd185e
3 changed files with 52 additions and 48 deletions

View File

@ -3,14 +3,13 @@
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
<meta http-equiv="pragma" content="no-cache" />
<link rel='shortcut icon' href='favicon.ico' type='image/x-icon'/ >
<title>Transmission Web Control Mobile</title>
<!-- Style sheet -->
<link rel="stylesheet" type="text/css" href="tr-web-control/style/base.mobile.css?v=20171015.1" />
<link rel="stylesheet" type="text/css" href="tr-web-control/style/base.mobile.css?v=20180906" />
<link rel="stylesheet" type="text/css" href="tr-web-control/script/jquery/mobile/jquery.mobile-1.4.5.min.css?v=20170426"/>
<!-- Base class library -->
<script type="text/javascript" src="tr-web-control/script/jquery/jquery-1.12.4.min.js"></script>
@ -20,12 +19,11 @@
<script type="text/javascript" src="tr-web-control/script/jquery/mobile/jquery.mobile-1.4.5.min.js?v=20170426"></script>
<!-- -->
<!-- System class library -->
<script type="text/javascript" src="tr-web-control/script/min/public.min.js?v=20171015.1"></script>
<script type="text/javascript" src="tr-web-control/script/min/cookies.min.js?v=20171015.1"></script>
<script type="text/javascript" src="tr-web-control/script/min/public.min.js?v=20180906"></script>
<script type="text/javascript" src="tr-web-control/script/min/ua-parser.min.js?v=20170522"></script>
<script type="text/javascript" src="tr-web-control/script/min/transmission.min.js?v=20171015.1"></script>
<script type="text/javascript" src="tr-web-control/script/min/transmission.torrents.min.js?v=20171015.1"></script>
<script type="text/javascript" src="tr-web-control/script/min/system.mobile.min.js?v=20171015.1"></script>
<script type="text/javascript" src="tr-web-control/script/min/transmission.min.js?v=20180906"></script>
<script type="text/javascript" src="tr-web-control/script/min/transmission.torrents.min.js?v=20180906"></script>
<script type="text/javascript" src="tr-web-control/script/min/system.mobile.min.js?v=20180906"></script>
</head>
<body>
<!-- Home -->

View File

@ -1,31 +1,27 @@
var system={version:"1.4.0",rootPath:"tr-web-control/",codeupdate:"20171108",configHead:"transmission-web-control",config:{autoReload:true,reloadStep:5E3,pageSize:30,defaultSelectNode:null},lang:null,reloading:false,autoReloadTimer:null,downloadDir:"",islocal:false,B64:new Base64,currentTorrentId:0,currentContentPage:"home",currentContentConfig:null,control:{tree:null,torrentlist:null},serverConfig:null,serverSessionStats:null,torrentListChecked:false,debug:function(label,text){if(window.console)if(window.console.log)window.console.log(label,
text)},setlang:function(lang,callback){if(!lang)if(this.config.defaultLang)lang=this.config.defaultLang;else lang=navigator.language||navigator.browserLanguage;if(!lang)lang="zh-CN";if(lang.indexOf("-")!=-1)lang=lang.split("-")[0].toLocaleLowerCase()+"-"+lang.split("-")[1].toLocaleUpperCase();if(!this.languages[lang])lang="en";$.getScript(system.rootPath+"lang/"+lang+".js",function(){system.lang=$.extend(true,system.defaultLang,system.lang);system.resetLangText();if(callback)callback()})},resetLangText:function(){var items=
$("*[system-lang]");$.each(items,function(key,item){var name=$(item).attr("system-lang");$(item).html(eval("system.lang."+name))})},init:function(lang,islocal){this.readConfig();transmission.options.getFolders=false;if(this.lang==null)this.setlang(lang,function(){system.initdata()});else this.initdata()},initdata:function(){$(document).attr("title",this.lang.system.title+" "+this.version);this.control.torrentlist=$("#torrent-list");this.connect()},readConfig:function(){var config=this.getStorageData(this.configHead+
".system");if(config)this.config=$.extend(this.config,JSON.parse(config))},saveConfig:function(){this.setStorageData(this.configHead+".system",JSON.stringify(this.config))},getStorageData:function(key,defaultValue){return window.localStorage[key]==null?defaultValue:window.localStorage[key]},setStorageData:function(key,value){window.localStorage[key]=value},connect:function(){transmission.on.torrentCountChange=function(){system.reloadTorrentBaseInfos()};transmission.on.postError=function(){};transmission.init({islocal:true},
function(){system.reloadSession(true);system.getServerStatus()})},reloadSession:function(isinit){transmission.getSession(function(result){system.serverConfig=result;if(result["alt-speed-enabled"]==true)$("#status_alt_speed").show();else $("#status_alt_speed").hide();system.downloadDir=result["download-dir"];if(parseInt(system.serverConfig["rpc-version"])>=15)transmission.getFreeSpace(system.downloadDir,function(result){system.serverConfig["download-dir-free-space"]=result.arguments["size-bytes"];
system.showFreeSpace(result.arguments["size-bytes"])});else system.showFreeSpace(system.serverConfig["download-dir-free-space"])})},showFreeSpace:function(size){var tmp=size;if(tmp==-1)tmp=system.lang["public"]["text-unknown"];else tmp=formatSize(tmp);$("#status_freespace").text(tmp)},getServerStatus:function(){if(this.reloading)return;clearTimeout(this.autoReloadTimer);this.reloading=true;transmission.getStatus(function(data){system.reloading=false;$("#status_downloadspeed").html(formatSize(data["downloadSpeed"],
false,"speed"));$("#status_uploadspeed").html(formatSize(data["uploadSpeed"],false,"speed"));system.serverSessionStats=data})},reloadTorrentBaseInfos:function(ids){if(this.reloading)return;clearTimeout(this.autoReloadTimer);this.reloading=true;var oldInfos={trackers:transmission.trackers,folders:transmission.torrents.folders};transmission.torrents.getallids(function(resultTorrents){var ignore=new Array;for(var index in resultTorrents){var item=resultTorrents[index];ignore.push(item.id)}var errorIds=
transmission.torrents.getErrorIds(ignore,true);if(errorIds.length>0)transmission.torrents.getallids(function(){system.resetTorrentInfos(oldInfos)},errorIds);else system.resetTorrentInfos(oldInfos)},ids)},resetTorrentInfos:function(oldInfos){var currentTorrentId=this.currentTorrentId;if(transmission.torrents.status[transmission._status.stopped])this.updateCount("paused",transmission.torrents.status[transmission._status.stopped].length);else this.updateCount("paused",0);if(transmission.torrents.status[transmission._status.seed])this.updateCount("sending",
transmission.torrents.status[transmission._status.seed].length);else this.updateCount("sending",0);if(transmission.torrents.status[transmission._status.check])this.updateCount("check",transmission.torrents.status[transmission._status.check].length);else this.updateCount("check",0);if(transmission.torrents.status[transmission._status.download])this.updateCount("downloading",transmission.torrents.status[transmission._status.download].length);else this.updateCount("downloading",0);this.updateCount("actively",
transmission.torrents.actively.length);this.updateCount("error",transmission.torrents.error.length);this.updateCount("warning",transmission.torrents.warning.length);system.reloading=false;if(system.config.autoReload)system.autoReloadTimer=setTimeout(function(){system.reloadData()},system.config.reloadStep);this.updateCount("all",transmission.torrents.count);if(this.currentContentPage=="torrent-list"){var _config=this.currentContentConfig;_config.reload=true;this.showContent(_config)}},updateCount:function(nodeId,
count){var item=$("#count-"+nodeId);item.text(count);if(count==0)item.hide();else item.show()},reloadData:function(){this.reloadSession();this.reloading=false;this.getServerStatus();this.reloading=false;this.reloadTorrentBaseInfos()},showContent:function(target){var _default={page:"",type:"",data:"",title:this.lang.system.title,reload:false,callback:null};var config=null;if(typeof target=="string"){_default.page=target;config=_default}else config=jQuery.extend(_default,target);if(config.page==this.currentContentPage&&
!config.reload)return;$("#content-"+config.page).show();if(config.page!=this.currentContentPage){$("#content-"+this.currentContentPage).hide();this.control.torrentlist.find("input:checked").prop("checked",false).checkboxradio("refresh");this.torrentListChecked=false}$("#torrent-page-bar").hide();if(!this.torrentListChecked)$("#torrent-toolbar").hide();this.currentContentPage=config.page;switch(config.type){case "torrent-list":config.title=this.lang.tree[config.data];this.loadTorrentToList({target:config.data});
break}$("#page-title").text(config.title);config.reload=false;this.currentContentConfig=config;if(config.callback)config.callback()},getTorrentFromType:function(type){var torrents=null;switch(type){case "torrent-all":case "all":case "servers":torrents=transmission.torrents.all;break;case "paused":torrents=transmission.torrents.status[transmission._status.stopped];break;case "sending":torrents=transmission.torrents.status[transmission._status.seed];break;case "seedwait":torrents=transmission.torrents.status[transmission._status.seedwait];
break;case "check":torrents=transmission.torrents.status[transmission._status.check];break;case "checkwait":torrents=transmission.torrents.status[transmission._status.checkwait];break;case "downloading":torrents=transmission.torrents.status[transmission._status.download];break;case "downloadwait":torrents=transmission.torrents.status[transmission._status.downloadwait];break;case "actively":torrents=transmission.torrents.actively;break;case "error":torrents=transmission.torrents.error;break;case "warning":torrents=
transmission.torrents.warning;break;case "search-result":torrents=transmission.torrents.searchResult;break;default:break}return torrents},loadTorrentToList:function(config){if(this.torrentListChecked)return;if(!transmission.torrents.all)return;var def={node:null,page:1,target:"all"};jQuery.extend(def,config);if(!config.target)return;var torrents=this.getTorrentFromType(config.target);this.config.defaultSelectNode=config.target;this.saveConfig();var datas=new Array;this.control.torrentlist.empty();
for(var index in torrents){if(!torrents[index])continue;var percentDone=parseFloat(torrents[index].percentDone*100).toFixed(2);var status=this.lang.torrent["status-text"][torrents[index].status];if(torrents[index].error!=0)status="\x3cspan class\x3d'text-status-error'\x3e"+status+"\x3c/span\x3e";else if(torrents[index].warning)status="\x3cspan class\x3d'text-status-warning' title\x3d'"+torrents[index].warning+"'\x3e"+status+"\x3c/span\x3e";var data={id:torrents[index].id,name:this.getTorrentNameBar(torrents[index]),
totalSize:torrents[index].totalSize,percentDone:this.getTorrentProgressBar(percentDone,torrents[index]),percentDoneNumber:percentDone,status:status,addedDate:formatLongTime(torrents[index].addedDate),completeSize:torrents[index].totalSize-torrents[index].leftUntilDone,rateDownload:torrents[index].rateDownload,rateUpload:torrents[index].rateUpload,leecherCount:torrents[index].leecher,seederCount:torrents[index].seeder,uploadRatio:torrents[index].uploadRatio,uploadedEver:torrents[index].uploadedEver};
datas.push(data)}if(datas.length==0){setTimeout(function(){system.showContent("home")},100);return}if(this.torrentPager.onGotoPage==null)this.torrentPager.onGotoPage=function(datas){system.control.torrentlist.empty();$("#torrent-toolbar").hide();for(var key in datas)system.appendTorrentToList(datas[key]);$(system.control.torrentlist).listview("refresh").find("input[type\x3d'checkbox']").click(function(){system.changeTorrentToolbar(this,data);if(system.torrentListChecked)system.control.torrentlist.find("a[name\x3d'torrent']").css("marginLeft",
"0px");else system.control.torrentlist.find("a[name\x3d'torrent']").css("marginLeft","0px")}).checkboxradio()};this.torrentPager.setDatas(datas,config.target)},appendTorrentToList:function(data){var replaces={id:data.id,name:data.name,rateDownload:formatSize(data.rateDownload,false,"speed"),rateUpload:formatSize(data.rateUpload,false,"speed"),completeSize:formatSize(data.completeSize),totalSize:formatSize(data.totalSize),percentDone:data.percentDone};var templates="\x3cli id\x3d'li-torrent-$id$' torrentid\x3d'$id$' style\x3d'padding:0px;'\x3e\x3ca name\x3d'torrent' style\x3d'padding:0px;margin-left:0px;'\x3e"+
"\x3clabel data-corners\x3d'false' style\x3d'margin:0px;border:0px;padding:0px;'\x3e"+"\x3cinput type\x3d'checkbox' id\x3d'torrent-$id$'/\x3e\x3clabel for\x3d'torrent-$id$'\x3e"+"\x3ch3 style\x3d'margin:0px;'\x3e$name$\x3c/h3\x3e"+"\x3cdiv style\x3d'padding:0px 10px 5px 0px;'\x3e$percentDone$\x3c/div\x3e"+"\x3cp class\x3d'torrent-list-infos'\x3e\u2193$rateDownload$ \u2191$rateUpload$|$completeSize$/$totalSize$\x3c/p\x3e"+"\x3c/label\x3e\x3c/label\x3e\x3c/a\x3e"+"\x3ca class\x3d'more'\x3e\x3c/a\x3e";
templates=templates.replace(/\$([^\$]*)\$/g,function(string,key){return replaces[key]});var li=$(templates);li.on("swiperight",function(event){system.control.torrentlist.find("a[name\x3d'torrent']").css("marginLeft","0px")});li.on("swipeleft",function(event){system.control.torrentlist.find("a[name\x3d'torrent']").css("marginLeft","0px")});li.appendTo(this.control.torrentlist)},getTorrentNameBar:function(torrent){var className="";var tip=torrent.name;switch(torrent.status){case transmission._status.stopped:className=
"iconlabel icon-pause-small";break;case transmission._status.check:className="iconlabel icon-checking";break;case transmission._status.download:className="iconlabel icon-down";break;case transmission._status.seed:className="iconlabel icon-up";break;case transmission._status.seedwait:case transmission._status.downloadwait:case transmission._status.checkwait:className="iconlabel icon-wait";break}if(torrent.warning){className="iconlabel icon-warning-type1";tip+="\n\n"+this.lang["public"]["text-info"]+
": "+torrent.warning}if(torrent.error!=0){className="iconlabel icon-exclamation";tip+="\n\n"+this.lang["public"]["text-info"]+": "+torrent.errorString}return'\x3cspan class\x3d"'+className+'" title\x3d"'+tip+'"\x3e'+torrent.name+"\x3c/span\x3e"},getTorrentProgressBar:function(progress,torrent){progress=progress+"%";var className="";switch(torrent.status){case transmission._status.stopped:className="torrent-progress-stop";break;case transmission._status.checkwait:case transmission._status.check:className=
"torrent-progress-check";break;case transmission._status.downloadwait:case transmission._status.download:className="torrent-progress-download";break;case transmission._status.seedwait:case transmission._status.seed:className="torrent-progress-seed";break}if(torrent.warning)className="torrent-progress-warning";if(torrent.error!=0)className="torrent-progress-error";return'\x3cdiv class\x3d"torrent-progress" title\x3d"'+progress+'"\x3e\x3cdiv class\x3d"torrent-progress-text"\x3e'+progress+'\x3c/div\x3e\x3cdiv class\x3d"torrent-progress-bar '+
className+'" style\x3d"width:'+progress+';"\x3e\x3c/div\x3e\x3c/div\x3e'},changeTorrentToolbar:function(source,item){var checked=this.control.torrentlist.find("input:checked");$("#torrent-checked-count").html(checked.length);if(checked.length>0){this.torrentListChecked=true;$("#torrent-toolbar").show()}else{this.torrentListChecked=false;$("#torrent-toolbar").hide()}if(item)this.currentTorrentId=item.id},torrentPager:{datas:null,pageSize:30,pageNumber:0,pageCount:0,count:0,onGotoPage:null,currentDatas:null,
pageBar:null,controls:{prev:null,next:null,number:null},head:"",init:function(datas){this.pageBar=$("#torrent-page-bar");this.controls.next=this.pageBar.find("#page-next");this.controls.next.click(function(){system.torrentPager.gotoPage("next")});this.controls.prev=this.pageBar.find("#page-prev");this.controls.prev.click(function(){system.torrentPager.gotoPage("prev")});this.controls.number=this.pageBar.find("#page-number");if(datas)this.setDatas(datas)},setDatas:function(datas,head){if(!this.datas)this.init();
this.datas=datas;this.pageBar.show();this.count=this.datas.length;this.pageCount=parseInt(this.count/this.pageSize);if(this.count%this.pageSize>0)this.pageCount++;if(this.pageCount==1)this.pageBar.hide();if(this.head==head)this.gotoPage();else this.gotoPage(1);this.head=head},gotoPage:function(page){if(typeof page=="number")this.pageNumber=page;else switch(page){case "next":this.pageNumber++;break;case "prev":this.pageNumber--;break}if(this.pageNumber>this.pageCount)this.pageNumber=this.pageCount;
if(this.pageNumber<1)this.pageNumber=1;var start=(this.pageNumber-1)*parseInt(this.pageSize);var end=start+parseInt(this.pageSize);this.currentDatas=this.datas.slice(start,end);this.controls.number.text(this.pageNumber+"/"+this.pageCount);if(this.pageNumber>1)this.controls.prev.show();else this.controls.prev.hide();if(this.pageNumber<this.pageCount)this.controls.next.show();else this.controls.next.hide();if(this.onGotoPage)this.onGotoPage(this.currentDatas)}},changeSelectedTorrentStatus:function(status,
button,options){var items=this.control.torrentlist.find("input:checked");var ids=new Array;if(!status)status="start";for(var i=0;i<items.length;i++)ids.push(parseInt(items[i].id.replace("torrent-","")));if(ids.length>0){var arguments={ids:ids};switch(status){case "remove":arguments["delete-local-data"]=options.removeData;break;case "verify":if(ids.length==1){var torrent=transmission.torrents.all[ids[0]];if(torrent.percentDone>0)if(confirm(system.lang.toolbar.tip["recheck-confirm"])==false)return}else if(confirm(system.lang.toolbar.tip["recheck-confirm"])==
false)return;break}button=$(button);button.attr("disabled",true);transmission.exec({method:"torrent-"+status,arguments:arguments},function(data){button.attr("disabled",false);system.reloadTorrentBaseInfos()});this.torrentListChecked=false}},addTorrentsToServer:function(urls,count,autostart,savepath,callback){var index=count-urls.length;var url=urls.shift();if(!url){this.showStatus(this.lang.system.status.queuefinish);this.getServerStatus();if(callback)callback();return}this.showStatus(this.lang.system.status.queue,
count-index+1);transmission.addTorrentFromUrl(url,savepath,autostart,function(data){system.addTorrentsToServer(urls,count,autostart,savepath,callback)})},showStatus:function(msg,count){if(!msg){$("#status").hide();return}$("#status").show();$("#status-msg").html(msg);if($.isNumeric(count))$("#status-count").html(count).show();else $("#status-count").hide()}};$(document).ready(function(){$.getScript(system.rootPath+"lang/default.js");$.getScript(system.rootPath+"lang/_languages.js",function(){system.init(location.search.getQueryString("lang"))})});
var system={version:"1.6.0 beta",rootPath:"tr-web-control/",codeupdate:"20180906",configHead:"transmission-web-control",config:{autoReload:true,reloadStep:5E3,pageSize:30,defaultSelectNode:null},lang:null,reloading:false,autoReloadTimer:null,downloadDir:"",islocal:false,B64:new Base64,currentTorrentId:0,currentContentPage:"home",currentContentConfig:null,control:{tree:null,torrentlist:null},serverConfig:null,serverSessionStats:null,torrentListChecked:false,debug:function(a,b){window.console&&window.console.log&&
window.console.log(a,b)},setlang:function(a,b){a||(a=this.config.defaultLang?this.config.defaultLang:navigator.language||navigator.browserLanguage);a||(a="zh-CN");if(a.indexOf("-")!=-1)a=a.split("-")[0].toLocaleLowerCase()+"-"+a.split("-")[1].toLocaleUpperCase();this.languages[a]||(a="en");a=a.replace("-","_");$.getJSON(system.rootPath+"i18n/"+a+".json",function(c){if(c)system.lang=$.extend(true,system.defaultLang,c);system.resetLangText();b&&b()})},resetLangText:function(){var a=$("*[system-lang]");
$.each(a,function(b,c){var d=$(c).attr("system-lang");$(c).html(eval("system.lang."+d))})},init:function(a){this.readConfig();transmission.options.getFolders=false;this.lang==null?this.setlang(a,function(){system.initdata()}):this.initdata()},initdata:function(){$(document).attr("title",this.lang.system.title+" "+this.version);this.control.torrentlist=$("#torrent-list");this.connect()},readConfig:function(){var a=this.getStorageData(this.configHead+".system");if(a)this.config=$.extend(this.config,
JSON.parse(a))},saveConfig:function(){this.setStorageData(this.configHead+".system",JSON.stringify(this.config))},getStorageData:function(a,b){return window.localStorage[a]==null?b:window.localStorage[a]},setStorageData:function(a,b){window.localStorage[a]=b},connect:function(){transmission.on.torrentCountChange=function(){system.reloadTorrentBaseInfos()};transmission.on.postError=function(){};transmission.init({islocal:true},function(){system.reloadSession(true);system.getServerStatus()})},reloadSession:function(){transmission.getSession(function(a){system.serverConfig=
a;a["alt-speed-enabled"]==true?$("#status_alt_speed").show():$("#status_alt_speed").hide();system.downloadDir=a["download-dir"];parseInt(system.serverConfig["rpc-version"])>=15?transmission.getFreeSpace(system.downloadDir,function(b){system.serverConfig["download-dir-free-space"]=b.arguments["size-bytes"];system.showFreeSpace(b.arguments["size-bytes"])}):system.showFreeSpace(system.serverConfig["download-dir-free-space"])})},showFreeSpace:function(a){a=a;a=a==-1?system.lang["public"]["text-unknown"]:
formatSize(a);$("#status_freespace").text(a)},getServerStatus:function(){if(!this.reloading){clearTimeout(this.autoReloadTimer);this.reloading=true;transmission.getStatus(function(a){system.reloading=false;$("#status_downloadspeed").html(formatSize(a.downloadSpeed,false,"speed"));$("#status_uploadspeed").html(formatSize(a.uploadSpeed,false,"speed"));system.serverSessionStats=a})}},reloadTorrentBaseInfos:function(a){if(!this.reloading){clearTimeout(this.autoReloadTimer);this.reloading=true;var b={trackers:transmission.trackers,
folders:transmission.torrents.folders};transmission.torrents.getallids(function(c){var d=[],e;for(e in c)d.push(c[e].id);c=transmission.torrents.getErrorIds(d,true);c.length>0?transmission.torrents.getallids(function(){system.resetTorrentInfos(b)},c):system.resetTorrentInfos(b)},a)}},resetTorrentInfos:function(){transmission.torrents.status[transmission._status.stopped]?this.updateCount("paused",transmission.torrents.status[transmission._status.stopped].length):this.updateCount("paused",0);transmission.torrents.status[transmission._status.seed]?
this.updateCount("sending",transmission.torrents.status[transmission._status.seed].length):this.updateCount("sending",0);transmission.torrents.status[transmission._status.check]?this.updateCount("check",transmission.torrents.status[transmission._status.check].length):this.updateCount("check",0);transmission.torrents.status[transmission._status.download]?this.updateCount("downloading",transmission.torrents.status[transmission._status.download].length):this.updateCount("downloading",0);this.updateCount("actively",
transmission.torrents.actively.length);this.updateCount("error",transmission.torrents.error.length);this.updateCount("warning",transmission.torrents.warning.length);system.reloading=false;if(system.config.autoReload)system.autoReloadTimer=setTimeout(function(){system.reloadData()},system.config.reloadStep);this.updateCount("all",transmission.torrents.count);if(this.currentContentPage=="torrent-list"){var a=this.currentContentConfig;a.reload=true;this.showContent(a)}},updateCount:function(a,b){var c=
$("#count-"+a);c.text(b);b==0?c.hide():c.show()},reloadData:function(){this.reloadSession();this.reloading=false;this.getServerStatus();this.reloading=false;this.reloadTorrentBaseInfos()},showContent:function(a){var b={page:"",type:"",data:"",title:this.lang.system.title,reload:false,callback:null},c=null;if(typeof a=="string"){b.page=a;c=b}else c=jQuery.extend(b,a);if(!(c.page==this.currentContentPage&&!c.reload)){$("#content-"+c.page).show();if(c.page!=this.currentContentPage){$("#content-"+this.currentContentPage).hide();
this.control.torrentlist.find("input:checked").prop("checked",false).checkboxradio("refresh");this.torrentListChecked=false}$("#torrent-page-bar").hide();this.torrentListChecked||$("#torrent-toolbar").hide();this.currentContentPage=c.page;switch(c.type){case "torrent-list":c.title=this.lang.tree[c.data];this.loadTorrentToList({target:c.data})}$("#page-title").text(c.title);c.reload=false;this.currentContentConfig=c;c.callback&&c.callback()}},getTorrentFromType:function(a){var b=null;switch(a){case "torrent-all":case "all":case "servers":b=
transmission.torrents.all;break;case "paused":b=transmission.torrents.status[transmission._status.stopped];break;case "sending":b=transmission.torrents.status[transmission._status.seed];break;case "seedwait":b=transmission.torrents.status[transmission._status.seedwait];break;case "check":b=transmission.torrents.status[transmission._status.check];break;case "checkwait":b=transmission.torrents.status[transmission._status.checkwait];break;case "downloading":b=transmission.torrents.status[transmission._status.download];
break;case "downloadwait":b=transmission.torrents.status[transmission._status.downloadwait];break;case "actively":b=transmission.torrents.actively;break;case "error":b=transmission.torrents.error;break;case "warning":b=transmission.torrents.warning;break;case "search-result":b=transmission.torrents.searchResult}return b},loadTorrentToList:function(a){if(!this.torrentListChecked)if(transmission.torrents.all){jQuery.extend({node:null,page:1,target:"all"},a);if(a.target){var b=this.getTorrentFromType(a.target);
this.config.defaultSelectNode=a.target;this.saveConfig();var c=[];this.control.torrentlist.empty();for(var d in b)if(b[d]){var e=parseFloat(b[d].percentDone*100).toFixed(2),f=this.lang.torrent["status-text"][b[d].status];if(b[d].error!=0)f="<span class='text-status-error'>"+f+"</span>";else if(b[d].warning)f="<span class='text-status-warning' title='"+b[d].warning+"'>"+f+"</span>";var g={id:b[d].id,name:this.getTorrentNameBar(b[d]),totalSize:b[d].totalSize,percentDone:this.getTorrentProgressBar(e,
b[d]),percentDoneNumber:e,status:f,addedDate:formatLongTime(b[d].addedDate),completeSize:b[d].totalSize-b[d].leftUntilDone,rateDownload:b[d].rateDownload,rateUpload:b[d].rateUpload,leecherCount:b[d].leecher,seederCount:b[d].seeder,uploadRatio:b[d].uploadRatio,uploadedEver:b[d].uploadedEver};c.push(g)}if(c.length==0)setTimeout(function(){system.showContent("home")},100);else{if(this.torrentPager.onGotoPage==null)this.torrentPager.onGotoPage=function(h){system.control.torrentlist.empty();$("#torrent-toolbar").hide();
for(var i in h)system.appendTorrentToList(h[i]);$(system.control.torrentlist).listview("refresh").find("input[type='checkbox']").click(function(){system.changeTorrentToolbar(this,g);system.control.torrentlist.find("a[name='torrent']").css("marginLeft","0px")}).checkboxradio()};this.torrentPager.setDatas(c,a.target)}}}},appendTorrentToList:function(a){var b={id:a.id,name:a.name,rateDownload:formatSize(a.rateDownload,false,"speed"),rateUpload:formatSize(a.rateUpload,false,"speed"),completeSize:formatSize(a.completeSize),
totalSize:formatSize(a.totalSize),percentDone:a.percentDone};a="<li id='li-torrent-$id$' torrentid='$id$' style='padding:0px;'><a name='torrent' style='padding:0px;margin-left:0px;'><label data-corners='false' style='margin:0px;border:0px;padding:0px;'><input type='checkbox' id='torrent-$id$'/><label for='torrent-$id$'><h3 style='margin:0px;'>$name$</h3><div style='padding:0px 10px 5px 0px;'>$percentDone$</div><p class='torrent-list-infos'>↓$rateDownload$ ↑$rateUpload$|$completeSize$/$totalSize$</p></label></label></a><a class='more'></a>";
a=a.replace(/\$([^\$]*)\$/g,function(c,d){return b[d]});a=$(a);a.on("swiperight",function(){system.control.torrentlist.find("a[name='torrent']").css("marginLeft","0px")});a.on("swipeleft",function(){system.control.torrentlist.find("a[name='torrent']").css("marginLeft","0px")});a.appendTo(this.control.torrentlist)},getTorrentNameBar:function(a){var b="",c=a.name;switch(a.status){case transmission._status.stopped:b="iconlabel icon-pause-small";break;case transmission._status.check:b="iconlabel icon-checking";
break;case transmission._status.download:b="iconlabel icon-down";break;case transmission._status.seed:b="iconlabel icon-up";break;case transmission._status.seedwait:case transmission._status.downloadwait:case transmission._status.checkwait:b="iconlabel icon-wait"}if(a.warning){b="iconlabel icon-warning-type1";c+="\n\n"+this.lang["public"]["text-info"]+": "+a.warning}if(a.error!=0){b="iconlabel icon-exclamation";c+="\n\n"+this.lang["public"]["text-info"]+": "+a.errorString}return'<span class="'+b+
'" title="'+c+'">'+a.name+"</span>"},getTorrentProgressBar:function(a,b){a+="%";var c="";switch(b.status){case transmission._status.stopped:c="torrent-progress-stop";break;case transmission._status.checkwait:case transmission._status.check:c="torrent-progress-check";break;case transmission._status.downloadwait:case transmission._status.download:c="torrent-progress-download";break;case transmission._status.seedwait:case transmission._status.seed:c="torrent-progress-seed"}if(b.warning)c="torrent-progress-warning";
if(b.error!=0)c="torrent-progress-error";return'<div class="torrent-progress" title="'+a+'"><div class="torrent-progress-text">'+a+'</div><div class="torrent-progress-bar '+c+'" style="width:'+a+';"></div></div>'},changeTorrentToolbar:function(a,b){var c=this.control.torrentlist.find("input:checked");$("#torrent-checked-count").html(c.length);if(c.length>0){this.torrentListChecked=true;$("#torrent-toolbar").show()}else{this.torrentListChecked=false;$("#torrent-toolbar").hide()}if(b)this.currentTorrentId=
b.id},torrentPager:{datas:null,pageSize:30,pageNumber:0,pageCount:0,count:0,onGotoPage:null,currentDatas:null,pageBar:null,controls:{prev:null,next:null,number:null},head:"",init:function(a){this.pageBar=$("#torrent-page-bar");this.controls.next=this.pageBar.find("#page-next");this.controls.next.click(function(){system.torrentPager.gotoPage("next")});this.controls.prev=this.pageBar.find("#page-prev");this.controls.prev.click(function(){system.torrentPager.gotoPage("prev")});this.controls.number=this.pageBar.find("#page-number");
a&&this.setDatas(a)},setDatas:function(a,b){this.datas||this.init();this.datas=a;this.pageBar.show();this.count=this.datas.length;this.pageCount=parseInt(this.count/this.pageSize);this.count%this.pageSize>0&&this.pageCount++;this.pageCount==1&&this.pageBar.hide();this.head==b?this.gotoPage():this.gotoPage(1);this.head=b},gotoPage:function(a){if(typeof a=="number")this.pageNumber=a;else switch(a){case "next":this.pageNumber++;break;case "prev":this.pageNumber--}if(this.pageNumber>this.pageCount)this.pageNumber=
this.pageCount;if(this.pageNumber<1)this.pageNumber=1;a=(this.pageNumber-1)*parseInt(this.pageSize);var b=a+parseInt(this.pageSize);this.currentDatas=this.datas.slice(a,b);this.controls.number.text(this.pageNumber+"/"+this.pageCount);this.pageNumber>1?this.controls.prev.show():this.controls.prev.hide();this.pageNumber<this.pageCount?this.controls.next.show():this.controls.next.hide();this.onGotoPage&&this.onGotoPage(this.currentDatas)}},changeSelectedTorrentStatus:function(a,b,c){var d=this.control.torrentlist.find("input:checked"),
e=[];a||(a="start");for(var f=0;f<d.length;f++)e.push(parseInt(d[f].id.replace("torrent-","")));if(e.length>0){arguments={ids:e};switch(a){case "remove":arguments["delete-local-data"]=c.removeData;break;case "verify":if(e.length==1){if(transmission.torrents.all[e[0]].percentDone>0)if(confirm(system.lang.toolbar.tip["recheck-confirm"])==false)return}else if(confirm(system.lang.toolbar.tip["recheck-confirm"])==false)return}b=$(b);b.attr("disabled",true);transmission.exec({method:"torrent-"+a,arguments:arguments},
function(){b.attr("disabled",false);system.reloadTorrentBaseInfos()});this.torrentListChecked=false}},addTorrentsToServer:function(a,b,c,d,e){var f=b-a.length,g=a.shift();if(g){this.showStatus(this.lang.system.status.queue,b-f+1);transmission.addTorrentFromUrl(g,d,c,function(){system.addTorrentsToServer(a,b,c,d,e)})}else{this.showStatus(this.lang.system.status.queuefinish);this.getServerStatus();e&&e()}},showStatus:function(a,b){if(a){$("#status").show();$("#status-msg").html(a);$.isNumeric(b)?$("#status-count").html(b).show():
$("#status-count").hide()}else $("#status").hide()}};$(document).ready(function(){$.getJSON(system.rootPath+"i18n/en.json").done(function(a){system.defaultLang=a});$.getJSON(system.rootPath+"i18n.json").done(function(a){system.languages=a;system.init(location.search.getQueryString("lang"),location.search.getQueryString("local"))})});

View File

@ -2,9 +2,9 @@
移动版
*/
var system = {
version: "1.4.0",
version: "1.6.0 beta",
rootPath: "tr-web-control/",
codeupdate: "20171108",
codeupdate: "20180906",
configHead: "transmission-web-control",
config: {
autoReload: true,
@ -59,8 +59,14 @@ var system = {
lang = "en";
}
$.getScript(system.rootPath + "lang/" + lang + ".js", function () {
system.lang = $.extend(true, system.defaultLang, system.lang);
// 统一使用 _ 替代 -
lang = lang.replace("-", "_");
$.getJSON(system.rootPath + "i18n/" + lang + ".json", function (result) {
if (result) {
system.lang = $.extend(true, system.defaultLang, result);
}
system.resetLangText();
if (callback)
callback();
@ -759,10 +765,14 @@ var system = {
};
$(document).ready(function () {
// 加载默认语言内容
$.getScript(system.rootPath+"lang/default.js");
// 加载可用的语言列表
$.getScript(system.rootPath+"lang/_languages.js",function(){
system.init(location.search.getQueryString("lang"));
// Loads the default language content
$.getJSON(system.rootPath + "i18n/en.json").done(function (result) {
system.defaultLang = result;
});
// Loads a list of available languages
$.getJSON(system.rootPath + "i18n.json").done(function (result) {
system.languages = result;
system.init(location.search.getQueryString("lang"), location.search.getQueryString("local"));
});
});