From 05bd3caaf9f46afedbc34e43414ba3c3ace252d0 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sun, 24 May 2009 01:29:03 +0000 Subject: [PATCH] (trunk web) #2052: when adding new torrents to the list (such as on startup), batch together all the additions to prevent unnecessary dom reflows --- web/javascript/torrent.js | 8 ++++---- web/javascript/transmission.js | 13 +++++-------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/web/javascript/torrent.js b/web/javascript/torrent.js index 93f2edd05..46e766306 100644 --- a/web/javascript/torrent.js +++ b/web/javascript/torrent.js @@ -6,8 +6,8 @@ * Class Torrent */ -function Torrent(controller,data) { - this.initialize(controller,data); +function Torrent(domParent,controller,data) { + this.initialize(domParent,controller,data); } // Constants @@ -23,7 +23,7 @@ Torrent.prototype = /* * Constructor */ - initialize: function(controller, data) { + initialize: function(domParent,controller, data) { this._id = data.id; this._is_private = data.isPrivate; this._hashString = data.hashString; @@ -102,7 +102,7 @@ Torrent.prototype = this._element.css('margin-top', '7px'); // insert the element - this._controller._torrent_list.appendChild( top_e ); + domParent.appendChild(top_e); this.initializeTorrentFilesInspectorGroup(); diff --git a/web/javascript/transmission.js b/web/javascript/transmission.js index 22a8dc1cb..9e47f3f47 100644 --- a/web/javascript/transmission.js +++ b/web/javascript/transmission.js @@ -1154,14 +1154,11 @@ Transmission.prototype = }, addTorrents: function( new_torrents ){ - var tr = this; - - $.each( new_torrents, function(){ - var torrent = this; - tr._torrents.push( new Torrent( tr, torrent ) ); - }); - - this.refilter(); + var fragment = document.createDocumentFragment( ); + for( var i=0, row; row=new_torrents[i]; ++i ) + this._torrents.push( new Torrent( fragment, this, row ) ); + this._torrent_list.appendChild( fragment ); + this.refilter( ); }, deleteTorrents: function(torrent_ids){