Merge pull request #7834 from SuperTux88/fix-photo-uploader-preview

Fix preview with uploaded photos
This commit is contained in:
Benjamin Neff 2018-07-18 01:56:52 +02:00
commit 7fef695e29
No known key found for this signature in database
GPG key ID: 971464C3F1A90194
4 changed files with 19 additions and 4 deletions

View file

@ -72,11 +72,19 @@ app.views.PublisherUploader = Backbone.View.extend({
);
// replace placeholder
var placeholder = publisher.photozoneEl.find("li.loading#upload-" + id);
var imgElement = document.createElement("img");
imgElement.src = image.thumb_medium.url;
imgElement.classList.add("hidden");
imgElement.dataset.id = photoId;
imgElement.dataset.small = image.thumb_small.url;
imgElement.dataset.scaled = image.scaled_full.url;
placeholder
.prepend(
"<div class=\"x\"></div>" +
"<div class=\"circle\"></div>" +
"<img src=\"" + image.url + "\" data-id=\"" + photoId + "\" alt=\"\" class=\"hidden\" />"
'<div class="x"></div>' +
'<div class="circle"></div>' +
imgElement.outerHTML
).removeClass("loading");
placeholder.find("div.progress").remove();
placeholder.find("img").on("load", function(ev) {

View file

@ -127,7 +127,9 @@ end
When /^I click to delete the first uploaded photo$/ do
page.execute_script("$('#photodropzone .x').css('display', 'block');")
image_count = all(".publisher_photo img").count
find("#photodropzone .x", match: :first).trigger "click"
page.assert_selector(".publisher_photo img", count: image_count - 1)
end
And /^I click on selector "([^"]*)"$/ do |selector|

View file

@ -14,10 +14,13 @@ module PublishingCukeHelpers
def upload_file_with_publisher(path)
page.execute_script(%q{$("input[name='qqfile']").css("opacity", '1');})
image_count = all(".publisher_photo img").count
with_scope("#publisher-textarea-wrapper") do
attach_file("qqfile", Rails.root.join(path).to_s)
# wait for the image to be ready
page.assert_selector(".publisher_photo.loading", count: 0)
page.assert_selector(".publisher_photo img", count: image_count + 1)
page.assert_selector(".publisher_photo img.hidden", count: 0)
end
end

View file

@ -624,7 +624,9 @@ describe("app.views.Publisher", function() {
var img = li.find('img');
expect(li).not.toHaveClass("loading");
expect(img.attr("src")).toBe("/uploads/images/test.jpg");
expect(img.attr("src")).toBe("/uploads/images/thumb_medium_test.jpg");
expect(img.attr("data-small")).toBe("/uploads/images/thumb_small_test.jpg");
expect(img.attr("data-scaled")).toBe("/uploads/images/scaled_full_test.jpg");
expect(img.attr("data-id")).toBe("987");
});