Changeset 11202
- Timestamp:
- Sep 12, 2010, 2:07:43 AM (12 years ago)
- Location:
- trunk/web/javascript
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/web/javascript/formatter.js
r11201 r11202 64 64 { 65 65 if( bytes < mem_K ) 66 return bytes + ' ' + mem_B_str;66 return [ bytes, mem_B_str ].join(' '); 67 67 68 68 var convertedSize; … … 91 91 92 92 // try to have at least 3 digits and at least 1 decimal 93 return convertedSize <= 9.995 ? convertedSize.toTruncFixed(2) + ' ' + unit94 : convertedSize.toTruncFixed(1) + ' ' + unit;93 return convertedSize <= 9.995 ? [ convertedSize.toTruncFixed(2), unit ].join(' ') 94 : [ convertedSize.toTruncFixed(1), unit ].join(' '); 95 95 }, 96 96 … … 103 103 { 104 104 if( bytes < size_K ) 105 return bytes + ' ' + size_B_str;105 return [ bytes, size_B_str ].join(' '); 106 106 107 107 var convertedSize; … … 130 130 131 131 // try to have at least 3 digits and at least 1 decimal 132 return convertedSize <= 9.995 ? convertedSize.toTruncFixed(2) + ' ' + unit133 : convertedSize.toTruncFixed(1) + ' ' + unit;132 return convertedSize <= 9.995 ? [ convertedSize.toTruncFixed(2), unit ].join(' ') 133 : [ convertedSize.toTruncFixed(1), unit ].join(' '); 134 134 }, 135 135 … … 149 149 150 150 if (speed <= 999.95) // 0 KBps to 999.9 K 151 return speed.toTruncFixed(1) + ' ' + speed_K_str;151 return [ speed.toTruncFixed(1), speed_K_str ].join(' '); 152 152 153 153 speed /= speed_K; 154 154 155 155 if (speed <= 99.995) // 1 M to 99.99 M 156 return speed.toTruncFixed(2) + ' ' + speed_M_str;156 return [ speed.toTruncFixed(2), speed_M_str ].join(' '); 157 157 if (speed <= 999.95) // 100 M to 999.9 M 158 return speed.toTruncFixed(1) + ' ' + speed_M_str;158 return [ speed.toTruncFixed(1), speed_M_str ].join(' '); 159 159 160 160 // insane speeds 161 161 speed /= speed_K; 162 return speed.toTruncFixed(2) + ' ' + speed_G_str;162 return [ speed.toTruncFixed(2), speed_G_str ].join(' '); 163 163 }, 164 164 … … 172 172 173 173 if (days > 0 && hours == 0) 174 result = days + ' days';174 result = [ days, 'days' ]; 175 175 else if (days > 0 && hours > 0) 176 result = days + ' days ' + hours + ' hr';176 result = [ days, 'days', hours, 'hr' ]; 177 177 else if (hours > 0 && minutes == 0) 178 result = hours + ' hr';178 result = [ hours, 'hr' ]; 179 179 else if (hours > 0 && minutes > 0) 180 result = hours + ' hr ' + minutes + ' min';180 result = [ hours,'hr', minutes, 'min' ]; 181 181 else if (minutes > 0 && seconds == 0) 182 result = minutes + ' min';182 result = [ minutes, 'min' ]; 183 183 else if (minutes > 0 && seconds > 0) 184 result = minutes + ' min ' + seconds + ' seconds';185 else 186 result = seconds + ' seconds';187 188 return result ;184 result = [ minutes, 'min', seconds, 'seconds' ]; 185 else 186 result = [ seconds, 'seconds' ]; 187 188 return result.join(' '); 189 189 }, 190 190 … … 240 240 241 241 return [date, time, period].join(' '); 242 }, 243 244 plural: function( i, word ) 245 { 246 return [ i, ' ', word, (word==1?'':'s') ].join(''); 242 247 } 243 248 } -
trunk/web/javascript/torrent.js
r11201 r11202 459 459 460 460 case Torrent._StatusDownloading: 461 if(compact_mode){ 462 c = this.formatDL(); 463 c += ' '; 464 c += this.formatUL(); 465 } else { 466 // 'Downloading from 36 of 40 peers - DL: 60.2 KiB/s UL: 4.3 KiB/s' 467 c = 'Downloading from '; 468 c += this.peersSendingToUs(); 469 c += ' of '; 470 c += this._peers_connected; 471 c += ' peers - '; 472 c = this.formatDL(); 473 c += ' '; 474 c += this.formatUL(); 475 } 461 var a = [ ]; 462 if(!compact_mode) 463 a.push( 'Downloading from', this.peersSendingToUs(), 'of', this._peers_connected, 'peers', '-' ); 464 a.push( this.formatDL(), this.formatUL() ); 465 c = a.join(' '); 476 466 break; 477 467 … … 481 471 } else { 482 472 // 'Seeding to 13 of 22 peers - UL: 36.2 KiB/s' 483 c = 'Seeding to '; 484 c += this.peersGettingFromUs(); 485 c += ' of '; 486 c += this._peers_connected; 487 c += ' peers - '; 488 c += this.formatUL(); 473 c = [ 'Seeding to', this.peersGettingFromUs(), 'of', this._peers_connected, 'peers', '-', this.formatUL() ].join(' '); 489 474 } 490 475 break; … … 492 477 case Torrent._StatusChecking: 493 478 // 'Verifying local data (40% tested)' 494 c = 'Verifying local data ('; 495 c += Transmission.fmt.percentString( 100.0 * this._recheckProgress ); 496 c += '% tested)'; 479 c = [ 'Verifying local data (', Transmission.fmt.percentString( 100.0 * this._recheckProgress ), '% tested)' ].join(''); 497 480 break; 498 481 } -
trunk/web/javascript/transmission.js
r11201 r11202 925 925 926 926 updateTurtleButton: function() { 927 var t; 927 928 var w = $('#turtle_button'); 928 var t;929 929 if ( this[Prefs._TurtleState] ) { 930 930 w.addClass('turtleEnabled'); 931 931 w.removeClass('turtleDisabled'); 932 t = "Click to disable Temporary Speed Limits";932 t = [ 'Click to disable Temporary Speed Limits' ]; 933 933 } else { 934 934 w.removeClass('turtleEnabled'); 935 935 w.addClass('turtleDisabled'); 936 t = "Click to enable Temporary Speed Limits";937 } 938 t += " (" + Transmission.fmt.speed(this._prefs[RPC._TurtleUpSpeedLimit]) + " up, "939 + Transmission.fmt.speed(this._prefs[RPC._TurtleDownSpeedLimit]) + " down)";940 w.attr( 'title', t );936 t = [ 'Click to enable Temporary Speed Limits' ]; 937 } 938 t.push( '(', Transmission.fmt.speed(this._prefs[RPC._TurtleUpSpeedLimit]), 'up,', 939 Transmission.fmt.speed(this._prefs[RPC._TurtleDownSpeedLimit]), 'down)' ); 940 w.attr( 'title', t.join(' ') ); 941 941 }, 942 942 … … 1007 1007 if (!iPhone) 1008 1008 { 1009 setInnerHTML( $('#limited_download_rate')[0], 'Limit (' + Transmission.fmt.speed(dn_limit_k) + ')');1009 setInnerHTML( $('#limited_download_rate')[0], [ 'Limit (', Transmission.fmt.speed(dn_limit_k), ')' ].join('') ); 1010 1010 var key = dn_limited ? '#limited_download_rate' 1011 1011 : '#unlimited_download_rate'; 1012 1012 $(key).deselectMenuSiblings().selectMenuItem(); 1013 1013 1014 setInnerHTML( $('#limited_upload_rate')[0], 'Limit (' + Transmission.fmt.speed(up_limit_k) + ')');1014 setInnerHTML( $('#limited_upload_rate')[0], [ 'Limit (', Transmission.fmt.speed(up_limit_k), ')' ].join('') ); 1015 1015 key = up_limited ? '#limited_upload_rate' 1016 1016 : '#unlimited_upload_rate'; … … 1126 1126 var rate_str = ($element[0].innerHTML).replace(/[^0-9]/ig, ''); 1127 1127 var rate_val = parseInt( rate_str ); 1128 setInnerHTML( $('#limited_download_rate')[0], 'Limit (' + Transmission.fmt.speed(rate_val) + ')');1128 setInnerHTML( $('#limited_download_rate')[0], [ 'Limit (', Transmission.fmt.speed(rate_val), ')' ].join('') ); 1129 1129 $('#limited_download_rate').deselectMenuSiblings().selectMenuItem(); 1130 1130 $('div.preference input#download_rate')[0].value = rate_str; … … 1145 1145 var rate_str = ($element[0].innerHTML).replace(/[^0-9]/ig, ''); 1146 1146 var rate_val = parseInt( rate_str ); 1147 setInnerHTML( $('#limited_upload_rate')[0], 'Limit (' + Transmission.fmt.speed(rate_val) + ')');1147 setInnerHTML( $('#limited_upload_rate')[0], [ 'Limit (', Transmission.fmt.speed(rate_val), ')' ].join('') ); 1148 1148 $('#limited_upload_rate').deselectMenuSiblings().selectMenuItem(); 1149 1149 $('div.preference input#upload_rate')[0].value = rate_str; … … 1284 1284 1285 1285 hash = t.hash(); 1286 pieces = t._pieceCount + ' pieces @ ' + Transmission.fmt.mem(t._pieceSize);1286 pieces = [ t._pieceCount, 'pieces @', Transmission.fmt.mem(t._pieceSize) ].join(' '); 1287 1287 date_created = Transmission.fmt.timestamp( t._creator_date ); 1288 1288 } … … 1366 1366 updatePeersLists: function() { 1367 1367 var tr = this; 1368 var html = '';1368 var html = [ ]; 1369 1369 var torrents = this.getSelectedTorrents( ); 1370 1370 if( $(this._inspector_peers_list).is(':visible') ) { 1371 1371 for( var k=0, torrent; torrent=torrents[k]; ++k ) { 1372 html += '<div class="inspector_group">';1372 html.push( '<div class="inspector_group">' ); 1373 1373 if( torrents.length > 1 ) { 1374 html += '<div class="inspector_torrent_label">'; 1375 html += torrent._name + '</div>'; 1374 html.push( '<div class="inspector_torrent_label">', torrent._name, '</div>' ); 1376 1375 } 1377 1376 if( torrent._peers.length == 0 ) { 1378 html += '<br></div>'; // firefox won't paint the top border if the div is empty1377 html.push( '<br></div>' ); // firefox won't paint the top border if the div is empty 1379 1378 continue; 1380 1379 } 1381 html += '<table class="peer_list">';1382 html += '<tr class="inspector_peer_entry even">';1383 html += '<th class="encryptedCol"></th>';1384 html += '<th class="upCol">Up</th>';1385 html += '<th class="downCol">Down</th>';1386 html += '<th class="percentCol">%</th>';1387 html += '<th class="statusCol">Status</th>';1388 html += '<th class="addressCol">Address</th>';1389 html += '<th class="clientCol">Client</th>';1390 html += '</tr>';1380 html.push( '<table class="peer_list">', 1381 '<tr class="inspector_peer_entry even">', 1382 '<th class="encryptedCol"></th>', 1383 '<th class="upCol">Up</th>', 1384 '<th class="downCol">Down</th>', 1385 '<th class="percentCol">%</th>', 1386 '<th class="statusCol">Status</th>', 1387 '<th class="addressCol">Address</th>', 1388 '<th class="clientCol">Client</th>', 1389 '</tr>' ); 1391 1390 for( var i=0, peer; peer=torrent._peers[i]; ++i ) { 1392 1391 var parity = ((i+1) % 2 == 0 ? 'even' : 'odd'); 1393 html += '<tr class="inspector_peer_entry ' + parity + '">';1394 html += '<td>' + (peer.isEncrypted ? '<img src="images/graphics/lock_icon.png" alt="Encrypted"/>' : '') + '</td>';1395 html += '<td>' + ( peer.rateToPeer ? Transmission.fmt.speedBps(peer.rateToPeer) : '' ) + '</td>';1396 html += '<td>' + ( peer.rateToClient ? Transmission.fmt.speedBps(peer.rateToClient) : '' ) + '</td>';1397 html += '<td class="percentCol">' + Math.floor(peer.progress*100) + '%' + '</td>';1398 html += '<td>' + peer.flagStr + '</td>';1399 html += '<td>' + peer.address + '</td>';1400 html += '<td class="clientCol">' + peer.clientName + '</td>';1401 html += '</tr>';1392 html.push( '<tr class="inspector_peer_entry ', parity, '">', 1393 '<td>', (peer.isEncrypted ? '<img src="images/graphics/lock_icon.png" alt="Encrypted"/>' : ''), '</td>', 1394 '<td>', ( peer.rateToPeer ? Transmission.fmt.speedBps(peer.rateToPeer) : '' ), '</td>', 1395 '<td>', ( peer.rateToClient ? Transmission.fmt.speedBps(peer.rateToClient) : '' ), '</td>', 1396 '<td class="percentCol">', Math.floor(peer.progress*100), '%', '</td>', 1397 '<td>', peer.flagStr, '</td>', 1398 '<td>', peer.address, '</td>', 1399 '<td class="clientCol">', peer.clientName, '</td>', 1400 '</tr>' ); 1402 1401 } 1403 html += '</table></div>';1402 html.push( '</table></div>' ); 1404 1403 } 1405 1404 } 1406 setInnerHTML(this._inspector_peers_list, html );1405 setInnerHTML(this._inspector_peers_list, html.join('') ); 1407 1406 }, 1408 1407 … … 1411 1410 // turn this into a DOM tree, this is a fast operation. 1412 1411 var tr = this; 1413 var html = '';1412 var html = [ ]; 1414 1413 var na = 'N/A'; 1415 1414 var torrents = this.getSelectedTorrents( ); 1416 1415 if( $(this._inspector_trackers_list).is(':visible') ) { 1417 1416 for( var k=0, torrent; torrent = torrents[k]; ++k ) { 1418 html += '<div class="inspector_group">';1417 html.push( '<div class="inspector_group">' ); 1419 1418 if( torrents.length > 1 ) { 1420 html += '<div class="inspector_torrent_label">'; 1421 html += torrent._name + '</div>'; 1419 html.push( '<div class="inspector_torrent_label">', torrent._name, '</div>' ); 1422 1420 } 1423 1421 for( var i=0, tier; tier=torrent._trackerStats[i]; ++i ) { 1424 html += '<div class="inspector_group_label">';1425 html += 'Tier ' + (i + 1) + '</div>';1426 html += '<ul class="tier_list">';1422 html.push( '<div class="inspector_group_label">', 1423 'Tier ', (i + 1), '</div>', 1424 '<ul class="tier_list">' ); 1427 1425 for( var j=0, tracker; tracker=tier[j]; ++j ) { 1428 1426 var lastAnnounceStatusHash = tr.lastAnnounceStatus(tracker); … … 1432 1430 // Display construction 1433 1431 var parity = ((j+1) % 2 == 0 ? 'even' : 'odd'); 1434 html += '<li class="inspector_tracker_entry ' + parity + '"><div class="tracker_host" title="' + tracker.announce + '">';1435 html += tracker.host + '</div>';1436 html += '<div class="tracker_activity">';1437 html += '<div>' + lastAnnounceStatusHash['label'] + ': ' + lastAnnounceStatusHash['value'] + '</div>';1438 html += '<div>' + announceState + '</div>';1439 html += '<div>' + lastScrapeStatusHash['label'] + ': ' + lastScrapeStatusHash['value'] + '</div>';1440 html += '</div><table class="tracker_stats">';1441 html += '<tr><th>Seeders:</th><td>' + (tracker.seederCount > -1 ? tracker.seederCount : na) + '</td></tr>';1442 html += '<tr><th>Leechers:</th><td>' + (tracker.leecherCount > -1 ? tracker.leecherCount : na) + '</td></tr>';1443 html += '<tr><th>Downloads:</th><td>' + (tracker.downloadCount > -1 ? tracker.downloadCount : na)+ '</td></tr>';1444 html += '</table></li>';1432 html.push( '<li class="inspector_tracker_entry ', parity, '"><div class="tracker_host" title="', tracker.announce, '">', 1433 tracker.host, '</div>', 1434 '<div class="tracker_activity">', 1435 '<div>', lastAnnounceStatusHash['label'], ': ', lastAnnounceStatusHash['value'], '</div>', 1436 '<div>', announceState, '</div>', 1437 '<div>', lastScrapeStatusHash['label'], ': ', lastScrapeStatusHash['value'], '</div>', 1438 '</div><table class="tracker_stats">', 1439 '<tr><th>Seeders:</th><td>', (tracker.seederCount > -1 ? tracker.seederCount : na), '</td></tr>', 1440 '<tr><th>Leechers:</th><td>', (tracker.leecherCount > -1 ? tracker.leecherCount : na), '</td></tr>', 1441 '<tr><th>Downloads:</th><td>', (tracker.downloadCount > -1 ? tracker.downloadCount : na), '</td></tr>', 1442 '</table></li>' ); 1445 1443 } 1446 html += '</ul>';1444 html.push( '</ul>' ); 1447 1445 } 1448 html += '</div>';1446 html.push( '</div>' ); 1449 1447 } 1450 1448 } 1451 setInnerHTML(this._inspector_trackers_list, html );1449 setInnerHTML(this._inspector_trackers_list, html.join('')); 1452 1450 }, 1453 1451 1454 1452 lastAnnounceStatus: function(tracker){ 1455 1453 var lastAnnounceLabel = 'Last Announce'; 1456 var lastAnnounce = 'N/A';1454 var lastAnnounce = [ 'N/A' ]; 1457 1455 if (tracker.hasAnnounced) { 1458 1456 var lastAnnounceTime = Transmission.fmt.timestamp(tracker.lastAnnounceTime); 1459 1457 if (tracker.lastAnnounceSucceeded) { 1460 lastAnnounce = lastAnnounceTime; 1461 lastAnnounce += ' (got ' + tracker.lastAnnouncePeerCount + ' peer'; 1462 if (tracker.lastAnnouncePeerCount != 1){ lastAnnounce += 's'; } 1463 lastAnnounce += ')'; 1458 lastAnnounce = [ lastAnnounceTime, ' (got ', Transmission.fmt.plural(tracker.lastAnnouncePeerCount, 'peer'), ')' ]; 1464 1459 } else { 1465 1460 lastAnnounceLabel = 'Announce error'; 1466 lastAnnounce = (tracker.lastAnnounceResult ? tracker.lastAnnounceResult + ' - ' : '') + lastAnnounceTime;1461 lastAnnounce = [ (tracker.lastAnnounceResult ? (tracker.lastAnnounceResult + ' - ') : ''), lastAnnounceTime ]; 1467 1462 } 1468 1463 } 1469 return { 'label':lastAnnounceLabel, 'value':lastAnnounce};1464 return { 'label':lastAnnounceLabel, 'value':lastAnnounce.join('') }; 1470 1465 }, 1471 1466
Note: See TracChangeset
for help on using the changeset viewer.