Changeset 392
- Timestamp:
- 06/28/08 06:39:33 (2 months ago)
- Files:
-
- branches/rpc/web/javascript/torrent.js (modified) (6 diffs)
- branches/rpc/web/javascript/transmission.js (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/rpc/web/javascript/torrent.js
r389 r392 150 150 * Process a right-click event on this torrent 151 151 */ 152 rightClickTorrent: function(event) { 153 154 var torrent = event.data.element._torrent; 155 156 // Don't stop the event! need it for the right-click menu 157 if (!torrent.isSelected()) { 158 torrent._controller.deselectAll(); 159 torrent.select(); 160 } 152 rightClickTorrent: function(event) 153 { 154 // don't stop the event! need it for the right-click menu 155 156 var t = event.data.element._torrent; 157 if ( !t.isSelected( ) ) 158 t._controller.setSelectedTorrent( t ); 161 159 }, 162 160 … … 164 162 * Process a click event on this torrent 165 163 */ 166 clickTorrent: function(event) { 164 clickTorrent: function( event ) 165 { 167 166 // Prevents click carrying to parent element 168 167 // which deselects all on click … … 179 178 } 180 179 181 var selectionChanged = false;182 183 180 // Shift-Click - Highlight a range between this torrent and the last-clicked torrent 184 181 if (iPhone) { 185 torrent._controller.deselectAll(); 186 torrent.select( ); 187 selectionChanged = true; 182 torrent._controller.setSelectedTorrent( torrent, true ); 188 183 189 184 } else if (event.shiftKey) { 190 torrent._controller.selectRange( torrent, true );185 torrent._controller.selectRange( torrent, true ); 191 186 // Need to deselect any selected text 192 187 window.focus(); … … 194 189 // Apple-Click, not selected 195 190 } else if (!torrent.isSelected() && meta_key) { 196 torrent.select( ); 197 selectionChanged = true; 191 torrent._controller.selectTorrent( torrent, true ); 198 192 199 193 // Regular Click, not selected 200 194 } else if (!torrent.isSelected()) { 201 torrent._controller.deselectAll(); 202 torrent.select( ); 203 selectionChanged = true; 195 torrent._controller.setSelectedTorrent( torrent, true ); 204 196 205 197 // Apple-Click, selected 206 198 } else if (torrent.isSelected() && meta_key) { 207 torrent.deselect( ); 208 selectionChanged = true; 199 torrent._controller.deselectTorrent( torrent, true ); 209 200 210 201 // Regular Click, selected 211 202 } else if (torrent.isSelected()) { 212 torrent._controller.deselectAll(); 213 torrent.select( ); 214 selectionChanged = true; 203 torrent._controller.setSelectedTorrent( torrent, true ); 215 204 } 216 205 217 206 torrent._controller.setLastTorrentClicked(torrent); 218 219 if( selectionChanged )220 torrent._controller.selectionChanged( );221 207 }, 222 208 … … 420 406 421 407 /* 422 * Select this torrent423 */424 select: function( doNotify )425 {426 // skipping height stuff on iPhone lets us omit dimensions.js; needs watching just in case427 if (!iPhone) {428 // Make sure it's visible in the torrent list (i.e. not too far down with the scrollbar all the way up)429 var container = $('#torrent_container'),430 offsetTop = this._element[0].offsetTop;431 scrollTop = container.scrollTop(),432 offsetHeight = this._element.outerHeight(),433 innerHeight = container.innerHeight();434 if (offsetTop < scrollTop) { // torrent is too far up435 container.scrollTop(offsetTop);436 } else if (innerHeight + scrollTop < offsetTop + offsetHeight) { // torrent is too far down437 container.scrollTop(offsetTop + offsetHeight - innerHeight);438 }439 }440 441 $.className.add( this.element()[0], 'selected' );442 443 if( doNotify )444 this._controller.selectionChanged();445 },446 447 /*448 * De-Select this torrent449 */450 deselect: function( doNotify ) {451 $.className.remove( this.element()[0], 'selected' );452 if( doNotify )453 this._controller.selectionChanged();454 },455 456 /*457 408 * Return true if this torrent is selected 458 409 */ 459 410 isSelected: function() { 460 return $.className.has( this.element()[0], 'selected' ); 411 var e = this.element( ); 412 return e && $.className.has( e[0], 'selected' ); 461 413 }, 462 414 … … 576 528 high = mid; 577 529 } 578 if( ( low < torrents.length ) && ( torrents[low].id() == id ) ) 530 if( ( low < torrents.length ) && ( torrents[low].id() == id ) ) { 579 531 return low; 580 else532 } else { 581 533 return -1; // not found 534 } 582 535 } 583 536 branches/rpc/web/javascript/transmission.js
r391 r392 184 184 }, 185 185 186 contextSelectAll: function( ) {187 transmission.selectAll( true);188 }, 189 190 contextDeselectAll: function( ) {191 transmission.deselectAll( true);186 contextSelectAll: function( ) { 187 transmission.selectAll( true ); 188 }, 189 190 contextDeselectAll: function( ) { 191 transmission.deselectAll( true ); 192 192 }, 193 193 … … 250 250 var torrents = [ ]; 251 251 for( var i=0, len=this._rows.length; i<len; ++i ) 252 if( this._rows[i][0].style.display != 'none' ) 253 torrents.push( this._rows[i]._torrent ); 252 if( this._rows[i]._torrent ) 253 if( this._rows[i][0].style.display != 'none' ) 254 torrents.push( this._rows[i]._torrent ); 254 255 return torrents; 255 256 }, … … 257 258 getSelectedTorrents: function() 258 259 { 259 var torrents = [ ]; 260 for( var i=0, len=this._rows.length; i<len; ++i ) 261 if( this._rows[i]._torrent.isSelected( ) ) 262 torrents.push( this._rows[i]._torrent ); 263 return torrents; 260 var v = this.getVisibleTorrents( ); 261 var s = [ ]; 262 for( var i=0, len=v.length; i<len; ++i ) 263 if( v[i].isSelected( ) ) 264 s.push( v[i] ); 265 return s; 264 266 }, 265 267 … … 287 289 }, 288 290 291 scrollToElement: function( e ) 292 { 293 if( iPhone ) 294 return; 295 296 var container = $('#torrent_container'); 297 var scrollTop = container.scrollTop( ); 298 var innerHeight = container.innerHeight( ); 299 300 var offsetTop = e[0].offsetTop; 301 var offsetHeight = e.outerHeight( ); 302 303 if( offsetTop < scrollTop ) 304 container.scrollTop( offsetTop ); 305 else if( innerHeight + scrollTop < offsetTop + offsetHeight ) 306 container.scrollTop( offsetTop + offsetHeight - innerHeight ); 307 }, 308 289 309 /*-------------------------------------------- 290 310 * … … 293 313 *--------------------------------------------*/ 294 314 295 selectRow: function( rowIndex, doUpdate ) 296 { 297 var e = this._rows[rowIndex]; 298 if( !e._torrent.isSelected( ) ) 299 e._torrent.select( doUpdate ); 300 }, 301 302 deselectRow: function( rowIndex, doUpdate ) 303 { 304 var e = this._rows[rowIndex]; 305 if( e._torrent.isSelected( ) ) 306 e._torrent.deselect( doUpdate ); 307 }, 308 309 selectionChanged: function() 310 { 311 this.updateButtonStates(); 312 this.updateInspector(); 315 setSelectedTorrent: function( torrent, doUpdate ) { 316 this.deselectAll( ); 317 this.selectTorrent( torrent, doUpdate ); 318 }, 319 320 selectElement: function( e, doUpdate ) { 321 $.className.add( e[0], 'selected' ); 322 this.scrollToElement( e ); 323 if( doUpdate ) 324 this.selectionChanged( ); 325 $.className.add( e[0], 'selected' ); 326 }, 327 selectRow: function( rowIndex, doUpdate ) { 328 this.selectElement( this._rows[rowIndex], doUpdate ); 329 }, 330 selectTorrent: function( torrent, doUpdate ) { 331 if( torrent._element ) 332 this.selectElement( torrent._element, doUpdate ); 333 }, 334 335 deselectElement: function( e, doUpdate ) { 336 $.className.remove( e[0], 'selected' ); 337 if( doUpdate ) 338 this.selectionChanged( ); 339 }, 340 deselectTorrent: function( torrent, doUpdate ) { 341 if( torrent._element ) 342 this.deselectElement( torrent._element, doUpdate ); 313 343 }, 314 344 … … 316 346 var tr = transmission; 317 347 for( var i=0, len=tr._rows.length; i<len; ++i ) 318 if( tr._rows[i].is(':visible') ) 319 tr.selectRow( i ); 348 tr.selectElement( tr._rows[i] ); 320 349 if( doUpdate ) 321 350 tr.selectionChanged(); 322 351 }, 323 324 352 deselectAll: function( doUpdate ) { 325 353 var tr = transmission; 326 354 for( var i=0, len=tr._rows.length; i<len; ++i ) 327 if( tr._rows[i].is(':visible') ) 328 tr.deselectRow( i ); 355 tr.deselectElement( tr._rows[i] ); 329 356 tr._last_torrent_clicked = null; 330 357 if( doUpdate ) … … 354 381 if( doUpdate ) 355 382 this.selectionChanged( ); 383 }, 384 385 selectionChanged: function() 386 { 387 this.updateButtonStates(); 388 this.updateInspector(); 356 389 }, 357 390 … … 653 686 setSortMethod: function( sort_method ) { 654 687 this.setPref( Prefs._SortMethod, sort_method ); 655 this.re sort( );688 this.refilter( ); 656 689 }, 657 690 658 691 setSortDirection: function( direction ) { 659 692 this.setPref( Prefs._SortDirection, direction ); 660 this.re sort( );693 this.refilter( ); 661 694 }, 662 695 … … 972 1005 var pos = Torrent.indexOf( this._torrents, t.id( ) ); 973 1006 var e = this._torrents[pos].element(); 974 if( e ) e.remove( ); 975 this._torrents.slice( pos, 1 ); 1007 if( e ) { 1008 delete e._torrent; 1009 e.hide( ); 1010 } 1011 this._torrents.splice( pos, 1 ); 976 1012 removedAny = true; 977 1013 } … … 991 1027 992 1028 this.refilter( ); 993 this.resort( );994 this.selectionChanged( );995 1029 }, 996 1030 … … 1140 1174 refilter: function() 1141 1175 { 1142 var torrents = this.getAllTorrents( ); 1143 1144 for( var i=0, len=torrents.length; i<len; ++i ) 1145 { 1146 var torrent = torrents[i]; 1147 var element = torrent.element( ); 1148 if( torrent.test( this[Prefs._FilterMode], 1149 this._current_search ) ) 1150 element[0].style.display = 'block'; 1151 else { 1152 torrent.deselect(); 1153 element[0].style.display = 'none'; 1154 } 1155 } 1156 1176 // decide which torrents to keep showing 1177 var allTorrents = this.getAllTorrents( ); 1178 var keep = [ ]; 1179 for( var i=0, len=allTorrents.length; i<len; ++i ) { 1180 var t = allTorrents[i]; 1181 if( t.test( this[Prefs._FilterMode], this._current_search ) ) 1182 keep.push( t ); 1183 } 1184 1185 // sort the keepers 1186 Torrent.sortTorrents( keep, this[Prefs._SortMethod], 1187 this[Prefs._SortDirection] ); 1188 1189 // make a backup of the selection 1190 var sel = this.getSelectedTorrents( ); 1191 this.deselectAll( ); 1192 1193 // hide the ones we're not keeping 1194 for( var i=keep.length; i<this._rows.length; ++i ) { 1195 var e = this._rows[i]; 1196 delete e._torrent; 1197 e[0].style.display = 'none'; 1198 } 1199 1200 // show the ones we're keeping 1201 sel.sort( Torrent.compareById ); 1202 for( var i=0, len=keep.length; i<len; ++i ) { 1203 var e = this._rows[i]; 1204 e[0].style.display = 'block'; 1205 var t = keep[i]; 1206 t.setElement( e ); 1207 if( Torrent.indexOf( sel, t.id() ) != -1 ) 1208 this.selectElement( e ); 1209 } 1210 1211 // sync gui 1157 1212 this.setTorrentBgColors( ); 1158 1213 this.updateStatusbar( ); 1159 1214 this.selectionChanged( ); 1160 },1161 1162 resort: function()1163 {1164 var torrents = this.getVisibleTorrents( );1165 var sel = this.getSelectedTorrents( );1166 var rows = this.getVisibleRows( );1167 1168 // sort the local array of torrents1169 Torrent.sortTorrents( torrents,1170 this[Prefs._SortMethod],1171 this[Prefs._SortDirection] );1172 1173 // sync the gui1174 for( var i=0, len=torrents.length; i<len; ++i )1175 torrents[i].setElement( rows[i] );1176 1177 // sync the selection class names1178 if( sel.length ) {1179 sel.sort( Torrent.compareById ); // for Torrent.indexOf1180 for( var i=0, len=rows.length; i<len; ++i ) {1181 var t = rows[i]._torrent;1182 if( Torrent.indexOf( sel, t.id() ) != -1 )1183 rows[i]._torrent.select( );1184 else1185 rows[i]._torrent.deselect( );1186 }1187 }1188 1215 }, 1189 1216
