move image preview setup to ~setPostImagePreview()~ in twister_formatpost.js and fix it slightly

This commit is contained in:
Simon Grim 2015-08-10 03:02:15 +05:00
parent 3f20e20945
commit ea144e63f9
2 changed files with 18 additions and 14 deletions

View File

@ -486,22 +486,10 @@ function postExpandFunction(e, postLi) {
var originalLi = $('<li/>', {class: 'module post original'}).appendTo(itemOl)
.append(originalPost);
setPostImagePreview(postExpandedContent, originalPost.find('a[rel="nofollow"]'));
postExpandedContent.slideDown('fast');
if ($.Options.displayPreview.val === 'enable') {
var previewContainer = postExpandedContent.find('.preview-container')[0];
/* was the preview added before... */
if ($(previewContainer).children().length === 0) {
var link = originalPost.find('a[rel="nofollow"]');
/*is there any link in the post?*/
for (var i = 0; i < link.length; i++) {
if (/^[^?]+\.(?:jpe?g|gif|png)$/i.test(link[i].href)) {
var url = proxyURL(link[i].href);
$(previewContainer).append($('<img src="' + url + '" class="image-preview" />'));
}
}
}
}
// insert 'reply_to' before
requestRepliedBefore(originalLi);
// insert replies to this post after

View File

@ -695,3 +695,19 @@ function reverseHtmlEntities(str) {
.replace(/&apos;/g, "'")
.replace(/&amp;/g, '&');
}
function setPostImagePreview(elem, links) {
if ($.Options.displayPreview.val === 'enable') {
var previewContainer = elem.find('.preview-container');
// was the preview added before...
if (!previewContainer.children().length) {
// is there any links to images in the post?
for (var i = 0; i < links.length; i++) {
if (/^[^?]+\.(?:jpe?g|gif|png)$/i.test(links[i].href)) {
var url = proxyURL(links[i].href);
previewContainer.append($('<img src="' + url + '" class="image-preview" />'));
}
}
}
}
}