From: Brion Vibber Date: Tue, 16 Nov 2010 23:20:37 +0000 (-0800) Subject: Less redrawing of bits in the link thumbnail preview X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=f7fe3fa3868f4e7d84c7d0c8b04ccf6f0727f6bb;p=quix0rs-gnu-social.git Less redrawing of bits in the link thumbnail preview --- diff --git a/plugins/LinkPreview/linkpreview.js b/plugins/LinkPreview/linkpreview.js index 37b0241a5d..5dca3a8071 100644 --- a/plugins/LinkPreview/linkpreview.js +++ b/plugins/LinkPreview/linkpreview.js @@ -133,13 +133,34 @@ */ previewLinks: function(text) { + var old = LinkPreview.links; var links = LinkPreview.findLinks(text); - $('#link-preview').html(''); - for (var i = 0; i < links.length; i++) { - var id = 'link-preview-' + i; - $('#link-preview').append(''); - LinkPreview.prepLinkPreview(id, links[i]); + + // Check for existing common elements... + for (var i = 0; i < old.length && i < links.length; i++) { + if (links[i] != old[i]) { + // Change an existing entry! + var id = 'link-preview-' + i; + $('#' + id).html(''); + LinkPreview.prepLinkPreview(id, links[i]); + } + } + if (links.length > old.length) { + // Adding new entries, whee! + for (var i = old.length; i < links.length; i++) { + var id = 'link-preview-' + i; + $('#link-preview').append(''); + LinkPreview.prepLinkPreview(id, links[i]); + } + } else if (old.length > links.length) { + // Remove preview entries for links that have been removed. + for (var i = links.length; i < old.length; i++) { + var id = 'link-preview-' + i; + $('#' + id).remove(); + } } + + LinkPreview.links = links; } };