diff options
author | Brion Vibber <brion@pobox.com> | 2010-11-16 15:20:37 -0800 |
---|---|---|
committer | Brion Vibber <brion@pobox.com> | 2010-11-16 15:20:37 -0800 |
commit | f7fe3fa3868f4e7d84c7d0c8b04ccf6f0727f6bb (patch) | |
tree | 750a25c62d257ca2a030f07e53e0fbcbdaa248e5 | |
parent | acdb9ac1e5b63f24262449356f526ff8168db8d3 (diff) |
Less redrawing of bits in the link thumbnail preview
-rw-r--r-- | plugins/LinkPreview/linkpreview.js | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/plugins/LinkPreview/linkpreview.js b/plugins/LinkPreview/linkpreview.js index 37b0241a5..5dca3a807 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('<span id="' + id + '"></span>'); - 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('<span id="' + id + '"></span>'); + 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; } }; |