Changeset 8522
- Timestamp:
- May 25, 2009, 1:18:51 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/web/javascript/torrent.js
r8521 r8522 232 232 // 'Apple' button emulation on PC : 233 233 // Need settable meta-key and ctrl-key variables for mac emulation 234 var meta_key = event.metaKey 235 var ctrl_key = event.ctrlKey 234 var meta_key = event.metaKey; 235 var ctrl_key = event.ctrlKey; 236 236 if (event.ctrlKey && navigator.appVersion.toLowerCase().indexOf("mac") == -1) { 237 237 meta_key = true; … … 334 334 335 335 refreshHTML: function() { 336 var c; 337 var e; 336 338 var progress_details; 337 339 var peer_details; … … 346 348 // Fix for situation 347 349 // when a verifying/downloading torrent gets state seeding 348 if( this._state == Torrent._StatusSeeding )350 if( this._state === Torrent._StatusSeeding ) 349 351 notDone = false ; 350 352 … … 364 366 // Create the 'progress details' label 365 367 // Eg: '101 MB of 631 MB (16.02%) - 2 hr remaining' 366 progress_details = Math.formatBytes( this._sizeWhenDone - this._leftUntilDone ) 367 + ' of ' 368 + Math.formatBytes( this._sizeWhenDone ) 369 + ' (' 370 + this.getPercentDoneStr() 371 + '%)' 372 + eta; 368 c = Math.formatBytes( this._sizeWhenDone - this._leftUntilDone ); 369 c += ' of '; 370 c += Math.formatBytes( this._sizeWhenDone ); 371 c += ' ('; 372 c += this.getPercentDoneStr(); 373 c += '%)'; 374 c += eta; 375 progress_details = c; 373 376 374 377 // Figure out the percent completed … … 376 379 377 380 // Update the 'in progress' bar 378 var class_name = this.isActive() ? 'in_progress' : 'incomplete_stopped';379 var e = root._progress_complete_container;380 var str = 'torrent_progress_bar ' + class_name;381 if(css_completed_width == 0) { str+= ' empty'; }382 e.className = str;381 e = root._progress_complete_container; 382 c = 'torrent_progress_bar'; 383 c += this.isActive() ? ' in_progress' : ' incomplete_stopped'; 384 if(css_completed_width === 0) { c += ' empty'; } 385 e.className = c; 383 386 e.style.width = css_completed_width + '%'; 384 387 385 388 // Update the 'incomplete' bar 386 389 e = root._progress_incomplete_container; 387 if( e.className.indexOf( 'incomplete' ) == -1 )390 if( e.className.indexOf( 'incomplete' ) === -1 ) 388 391 e.className = 'torrent_progress_bar in_progress'; 389 392 e.style.width = (MaxBarWidth - css_completed_width) + '%'; … … 393 396 // Eg: 'Downloading from 36 of 40 peers - DL: 60.2 KB/s UL: 4.3 KB/s' 394 397 if( !this.isDownloading( ) ) 395 peer_details= this.stateStr( );398 c = this.stateStr( ); 396 399 else { 397 peer_details = 'Downloading from '398 + this.peersSendingToUs()399 + ' of '400 + this._peers_connected401 + ' peers - DL: '402 + Math.formatBytes(this._download_speed)403 + '/s UL: '404 + Math.formatBytes(this._upload_speed)405 +'/s';400 c = 'Downloading from '; 401 c += this.peersSendingToUs(); 402 c += ' of '; 403 c += this._peers_connected; 404 c += ' peers - DL: '; 405 c += Math.formatBytes(this._download_speed); 406 c += '/s UL: '; 407 c += Math.formatBytes(this._upload_speed); 408 c += '/s'; 406 409 } 410 peer_details = c; 407 411 408 412 } … … 410 414 { 411 415 // Update the 'in progress' bar 412 var class_name = (this.isActive()) ? 'complete' : 'complete_stopped'; 413 var e = root._progress_complete_container; 414 e.className = 'torrent_progress_bar ' + class_name; 416 e = root._progress_complete_container; 417 c = 'torrent_progress_bar'; 418 c += (this.isActive()) ? ' complete' : ' complete_stopped'; 419 e.className = c; 415 420 416 421 // Create the 'progress details' label 417 422 // Eg: '698.05 MB, uploaded 8.59 GB (Ratio: 12.3)' 418 progress_details = Math.formatBytes( this._size ) 419 + ', uploaded ' 420 + Math.formatBytes( this._upload_total ) 421 + ' (Ratio ' 422 + Math.ratio( this._upload_total, this._download_total ) 423 + ')'; 423 c = Math.formatBytes( this._size ); 424 c += ', uploaded '; 425 c += Math.formatBytes( this._upload_total ); 426 c += ' (Ratio '; 427 c += Math.ratio( this._upload_total, this._download_total ); 428 c += ')'; 429 progress_details = c; 424 430 425 431 // Hide the 'incomplete' bar … … 432 438 // Eg: 'Seeding to 13 of 22 peers - UL: 36.2 KB/s' 433 439 if( !this.isSeeding( ) ) 434 peer_details = this.stateStr( ); 435 else 436 peer_details = 'Seeding to ' 437 + this.peersGettingFromUs() 438 + ' of ' 439 + this._peers_connected 440 + ' peers - UL: ' 441 + Math.formatBytes(this._upload_speed) 442 + '/s'; 440 c = this.stateStr( ); 441 else { 442 c = 'Seeding to '; 443 c += this.peersGettingFromUs(); 444 c += ' of '; 445 c += this._peers_connected; 446 c += ' peers - UL: '; 447 c += Math.formatBytes(this._upload_speed); 448 c += '/s'; 449 } 450 peer_details = c; 443 451 } 444 452 … … 448 456 // Update the peer details and pause/resume button 449 457 e = root._pause_resume_button_image; 450 if ( this.state() == Torrent._StatusPaused ) {458 if ( this.state() === Torrent._StatusPaused ) { 451 459 e.alt = 'Resume'; 452 460 e.className = "torrent_resume"; … … 457 465 458 466 if( this._error_message && 459 this._error_message != '' &&460 this._error_message != 'other' ) {467 this._error_message !== '' && 468 this._error_message !== 'other' ) { 461 469 peer_details = this._error_message; 462 470 } … … 475 483 ensureFileListExists: function() { 476 484 if( this._file_view.length == 0 ) { 485 var v, e; 477 486 for( var i=0; i<this._file_model.length; ++i ) { 478 v ar v= new TorrentFile( this._file_model[i] );487 v = new TorrentFile( this._file_model[i] ); 479 488 this._file_view[i] = v; 480 vare = v.domElement( );489 e = v.domElement( ); 481 490 e.className = (i % 2 ? 'even' : 'odd') + ' inspector_torrent_file_list_entry'; 482 491 this._fileList.appendChild( e ); … … 523 532 return pass; 524 533 525 var pos = this._name_lc.indexOf( search.toLowerCase() ); 526 pass = pos != -1; 527 return pass; 534 return this._name_lc.indexOf( search.toLowerCase() ) !== -1; 528 535 } 529 536 }; … … 566 573 var b_ratio = Math.ratio( b._upload_total, b._download_total ); 567 574 return a_ratio - b_ratio; 568 } 575 }; 569 576 570 577 /** … … 603 610 } 604 611 605 if( sortDirection == Prefs._SortDescending )612 if( sortDirection === Prefs._SortDescending ) 606 613 torrents.reverse( ); 607 614 … … 650 657 TorrentFile.prototype = { 651 658 initialize: function(file_data) { 652 //console.log( 'new TorrentFile ' + file_data.name );653 659 this._dirty = true; 654 660 this._torrent = file_data.torrent; 655 661 this._index = file_data.index; 656 var pos = file_data.name.indexOf('/'); 657 if (pos >= 0) 658 this.name = file_data.name.substring(pos + 1); 659 else 660 this.name = file_data.name; 662 var name = file_data.name.substring (file_data.name.lastIndexOf('/')+1); 661 663 this.readAttributes(file_data); 662 664 … … 674 676 var file_div = document.createElement('div'); 675 677 file_div.className = "inspector_torrent_file_list_entry_name"; 676 file_div.innerHTML = this.name.replace(/([\/_\.])/g, "$1​");678 file_div.innerHTML = name.replace(/([\/_\.])/g, "$1​"); 677 679 678 680 var prog_div = document.createElement('div'); … … 696 698 this.refreshHTML(); 697 699 }, 700 701 isDone: function () { 702 return this._done >= this._size; 703 }, 704 705 isEditable: function () { 706 return (this._torrent._file_model.length>1) && !this.isDone(); 707 }, 698 708 699 709 readAttributes: function(file_data) { 700 if( file_data.index != undefined && file_data.index != this._index ) {710 if( file_data.index !== undefined && file_data.index !== this._index ) { 701 711 this._index = file_data.index; 702 712 this._dirty = true; 703 713 } 704 if( file_data.bytesCompleted != undefined && file_data.bytesCompleted != this._done ) {714 if( file_data.bytesCompleted !== undefined && file_data.bytesCompleted !== this._done ) { 705 715 this._done = file_data.bytesCompleted; 706 716 this._dirty = true; 707 717 } 708 if( file_data.length != undefined && file_data.length != this._size ) {718 if( file_data.length !== undefined && file_data.length !== this._size ) { 709 719 this._size = file_data.length; 710 720 this._dirty = true; 711 721 } 712 if( file_data.priority != undefined && file_data.priority != this._prio ) {722 if( file_data.priority !== undefined && file_data.priority !== this._prio ) { 713 723 this._prio = file_data.priority; 714 724 this._dirty = true; 715 725 } 716 if( file_data.wanted != undefined && file_data.wanted != this._wanted ) {726 if( file_data.wanted !== undefined && file_data.wanted !== this._wanted ) { 717 727 this._wanted = file_data.wanted; 718 728 this._dirty = true; … … 728 738 }, 729 739 730 setPriority: function(priority) { 731 if(this.element().hasClass('complete') || this._torrent._file_model.length == 1) 732 return; 733 var priority_level = { high: 1, normal: 0, low: -1 }[priority]; 734 if (this._prio == priority_level) { return; } 735 this._prio = priority_level; 736 this._torrent._controller.changeFileCommand("priority-" + priority, this._torrent, this); 737 this._dirty = true; 740 setPriority: function(prio) { 741 if (this.isEditable()) { 742 var cmd; 743 switch( prio ) { 744 case 1: cmd = 'priority-high'; break; 745 case -1: cmd = 'priority-low'; break; 746 default: cmd = 'priority-normal'; break; 747 } 748 this._prio = prio; 749 this._dirty = true; 750 this._torrent._controller.changeFileCommand( cmd, this._torrent, this ); 751 } 738 752 }, 739 753 … … 747 761 748 762 toggleWanted: function() { 749 if(this.element().hasClass('complete') || this._torrent._file_model.length == 1) 750 return; 751 this.setWanted(!this._wanted); 763 if (this.isEditable()) 764 this.setWanted( !this._wanted ); 752 765 }, 753 766 … … 762 775 763 776 refreshProgressHTML: function() { 764 progress_details = Math.formatBytes(this._done) + ' of ' + 765 Math.formatBytes(this._size) + ' (' + 766 Math.ratio(100 * this._done, this._size) + '%)'; 767 setInnerHTML(this._progress[0], progress_details); 777 var c = Math.formatBytes(this._done); 778 c += ' of '; 779 c += Math.formatBytes(this._size); 780 c += ' ('; 781 c += Math.ratio(100 * this._done, this._size); 782 c += '%)'; 783 setInnerHTML(this._progress[0], c); 768 784 }, 769 785 770 786 refreshWantedHTML: function() { 771 var e = this. element()[0];787 var e = this.domElement(); 772 788 var c = e.classNameConst; 773 if(!this._wanted) c += ' skip';774 if(this. _done>=this._size) c += ' complete';789 if(!this._wanted) { c += ' skip'; } 790 if(this.isDone()) { c += ' complete'; } 775 791 e.className = c; 776 792 }, … … 794 810 var x = event.pageX; 795 811 var target = this; 796 while (target != null) {812 while (target !== null) { 797 813 x = x - target.offsetLeft; 798 814 target = target.offsetParent; 799 815 } 800 var file = event.data.file; 801 if (x < 12) { file.setPriority('low'); } 802 else if (x < 23) { file.setPriority('normal'); } 803 else { file.setPriority('high'); } 816 var prio; 817 if( x < 12 ) prio = -1; 818 else if( x < 23 ) prio = 0; 819 else prio = 1; 820 file.setPriority( prio ); 804 821 } 805 822 };
Note: See TracChangeset
for help on using the changeset viewer.