-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lazy load images using lazyload-rails gem #8043
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,28 @@ | ||
<div class="col-lg-6 note-container-question"> | ||
<div class="note note-pane note-question<% if node.status == 4 %> moderated<% end %>"> | ||
|
||
<div class="header-icon"><i class="fa fa-question-circle"></i> <a href="/q/<%= node.id %>"><i class="fa fa-link"></i></a></div> | ||
|
||
<div style="overflow: hidden;"> | ||
|
||
<%= render partial: 'dashboard/node_moderate', locals: { node: node } %> | ||
|
||
<% if node.main_image %> | ||
<a class="img" href="<%= node.path(:question) %>"><img src="<%= node.main_image.path(:default) %>" style="width:100%;" /></a> | ||
<a class="img" href="<%= node.path(:question) %>"><%= image_tag(node.main_image.path(:default), style:'width:100%;') %></a> | ||
<% elsif node.scraped_image %> | ||
<a class="img" href="<%= node.path %>"><img src="<%= node.scraped_image %>" style="width:100%;" /></a> | ||
<a class="img" href="<%= node.path %>"><%= image_tag(node.scraped_image, style:'width:100%;') %></a> | ||
<% end %> | ||
|
||
<h4><a href="<%= node.path(:question) %>"><%= node.title %></a></h4> | ||
|
||
<p class="meta"><%= translation('dashboard._node_question.question') %> <%= render partial: "dashboard/node_meta", locals: { node: node } %></p> | ||
|
||
</div> | ||
</div> | ||
</div> | ||
|
||
<script> | ||
$(function(){ | ||
$("img").lazyload(); | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
<div class="card"> | ||
<% if node.main_image %> | ||
<a class="card-img-top img" style="overflow: hidden; height:10em;"<% if @widget %>target="_blank"<% end %> href="<%= node.path %>"><img src="<%= node.main_image.path(:default) %>" style="width:100%;"/></a> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So let's revert this entire file, only. That should solve it! |
||
<a class="card-img-top img" style="overflow: hidden; height:10em;"<% if @widget %>target="_blank"<% end %> href="<%= node.path %>"><%= image_tag(node.main_image.path(:default), style:'width:100%;') %></a> | ||
<% elsif node.scraped_image %> | ||
<a class="card-img-top img" style="overflow: hidden; height:10em;" href="<%= node.path %>"><img src="<%= node.scraped_image %>" style="width:100%;" /></a> | ||
<a class="card-img-top img" style="overflow: hidden; height:10em;" href="<%= node.path %>"><%= image_tag(node.scraped_image, style:'width:100%;') %></a> | ||
<% else %> | ||
<a class="imgg" style="height:10em; margin-bottom: 10px;padding: 1rem;"> | ||
<i class="fa fa-picture-o note-not aria-hidden="true" style="color: #ccc; font-size: 6em;"></i> | ||
|
@@ -66,3 +66,9 @@ | |
</div> | ||
</small> | ||
</div> | ||
|
||
<script> | ||
$(function(){ | ||
$("img").lazyload(); | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,10 +5,10 @@ | |
<%= render :partial => "map/leaflet" , locals: { lat: @map_lat, lon: @map_lon, zoom: @map_zoom, blurred: @map_blurred, topmap: true, user: @profile_user } %> | ||
<% elsif !current_user.nil? && current_user.id == @profile_user.id %> | ||
<div id="map_template" style="position: relative; width: 100%; display: inline-block;"> | ||
<img src="https://a.tiles.mapbox.com/v3/jywarren.map-lmrwb2em/0/0/0.png" style="height:300px; width: 100%; margin: 0; position: relative; margin-right: -10px;"> | ||
<img src="https://a.tiles.mapbox.com/v3/jywarren.map-lmrwb2em/0/0/0.png" style="height:300px; width: 100%; margin: 0; position: relative; margin-right: -10px;"> | ||
<button type='button' class='blurred-location-input btn btn-default btn-lg' onclick='addLocation()' style="position: absolute; position: absolute;top: 41% ; left: 15% ;"> <strong> Share your Location </strong> </button> | ||
<p><i><small>Learn about <a href='https://publiclab.org/wiki/location-privacy'>privacy</a> </small></i></p> | ||
</div> | ||
</div> | ||
<% end %> | ||
|
||
<br /> | ||
|
@@ -45,14 +45,14 @@ | |
|
||
<div class="offset-md-1 order-first order-md-last col-md-4 text-center"> | ||
<div class="text-center"> | ||
<%if @content_approved or (!current_user.nil? && current_user.id == @profile_user.id)%> | ||
<img class="d-none d-lg-inline rounded-circle" id="profile-photo" style="width:50%;margin-bottom:10px;" src="<%= @profile_user.profile_image %>" /> | ||
<%if @content_approved or (!current_user.nil? && current_user.id == @profile_user.id)%> | ||
<%= image_tag(@profile_user.profile_image, class:'d-none d-lg-inline rounded-circle', id:'profile-photo', style:"width:50%;margin-bottom:10px;") %> | ||
<%end%> | ||
<h4 class="mt-3"><strong>@<%= @profile_user.name %> <%= @profile_user.new_contributor %></strong></h4> | ||
</div> | ||
<div style="text-align:center;" class="d-lg-none"> | ||
<%if @content_approved or (!current_user.nil? && current_user.id == @profile_user.id)%> | ||
<img class="rounded-circle" id="profile-photo" style="width:50%;margin-bottom:20px;" src="<%= @profile_user.profile_image(:medium) %>" /> | ||
<%if @content_approved or (!current_user.nil? && current_user.id == @profile_user.id)%> | ||
<%= image_tag(@profile_user.profile_image(:medium), class:'rounded-circle', id:'profile-photo', style:"width:50%;margin-bottom:20px;") %> | ||
<%end%> | ||
<h4 class="mt-3"><strong>@<%= @profile_user.name %> <%= @profile_user.new_contributor %></strong></h4> | ||
</div> | ||
|
@@ -66,9 +66,9 @@ | |
<% if @profile_user.status == 0 %> | <i class="fa fa-ban" style="color:#a00;"></i> <%= translation('users.profile.banned') %><% end %> | ||
</small> | ||
</h4> | ||
<%if @content_approved or (!current_user.nil? && current_user.id == @profile_user.id)%> | ||
<%if @content_approved or (!current_user.nil? && current_user.id == @profile_user.id)%> | ||
<p><%= raw auto_link(RDiscount.new(@profile_user.bio || '').to_html, :sanitize => false) %></p> | ||
<%end%> | ||
<%end%> | ||
<div class="mt-3"> | ||
|
||
<a class="btn btn-outline-secondary" id="tags-section">Tags</a> | ||
|
@@ -273,6 +273,9 @@ | |
<script src = "https://cdn.jsdelivr.net/npm/[email protected]/dist/frappe-charts.min.iife.js"></script> | ||
|
||
<script type = "text/javascript"> | ||
$(function(){ | ||
$("img").lazyload(); | ||
}); | ||
//Upon clicking copy button, copyToken function is activated. | ||
$('#copy-btn').on('click', copyToken); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Lazyload::Rails.configure do |config| | ||
# By default, a 1x1 grey gif is used as placeholder ("data:image/gif;base64,..."). | ||
# This can be easily customized: | ||
# config.placeholder = "/public/img/grey.gif" | ||
|
||
# image_tag can return lazyload-friendly images by default, | ||
# no need to pass the { lazy: true } option | ||
config.lazy_by_default = true | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @Tlazypanda - this seems to have disrupted the loading of some images which are "blob" type - see for example the admittedly odd ones in this view:
https://publiclab.org/embed/grid/grid:infragram-upload
See how these actually use a dataurl as the image? I know its weird but I see the
image_tag
method is replacing the filename withblob
- can we include a workaround, perhaps, if the image path is a data url?This is a pretty weird workflow... i feel like maybe I'm missing something!
Also, I'm trying to fix the somewhat related assets on that template (for use in embedded content), here:
36c54a2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @jywarren I was thinking of writing a conditional rendering for this but am having some difficulty in defining the condition I was thinking of something like:-
<% elsif current_user.photo.url.start_with?("data:image") %>
but doesn't seem to work... My understanding of the models may not be at point here can you help me out 😅There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, hmm. Are we mixing up blobs with data_urls? This is a bit mysterious! Uh, is it possible that the lazy load gem is converting a data-url into a blob?
AH! I remember, i wrote some really obscure code here. Let's see...
OMG YES -- #6931 and #6930 -- deep mysterious code! But yes, it has the data-uri-to-blob method there. That should help us!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we consider just turning off lazy loading for this one instance in order to recover the functionality? @TildaDares @Manasa2850 @17sushmita are any of you interested in this particular bug? Thank you all!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was looking into this and was playing around with some modifications on the unstable but I'm not sure how to reproduce this on my local. Would love to get any help regarding this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately I'm not sure how to reproduce... I'm not sure how the blob images are saved! Can we dig into the raw html shown on unstable to try to learn more?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My best guess here is that we should just turn off lazy loading for this one type of image.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK this file is for the old dashboard! So ignore this particular file, we'll revert the one specifically for the new card-style display of nodes, below, i'll leave a comment.