diff options
author | Tim Zallmann <tzallmann@gitlab.com> | 2017-07-24 17:36:52 +0000 |
---|---|---|
committer | Jacob Schatz <jschatz@gitlab.com> | 2017-07-24 17:36:52 +0000 |
commit | 52b8a0db689c2df968776a1f369ea6a6db245d39 (patch) | |
tree | 4955f45d5d19c1d32aee8bc496041acdd74763cb /app/helpers/lazy_image_tag_helper.rb | |
parent | 3a26bce80eb739ca3f552dfe71e39b9a177eb36e (diff) | |
download | gitlab-ce-52b8a0db689c2df968776a1f369ea6a6db245d39.tar.gz |
Resolve "Lazy load images on the Frontend"
Diffstat (limited to 'app/helpers/lazy_image_tag_helper.rb')
-rw-r--r-- | app/helpers/lazy_image_tag_helper.rb | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/app/helpers/lazy_image_tag_helper.rb b/app/helpers/lazy_image_tag_helper.rb new file mode 100644 index 00000000000..2c5619ac41b --- /dev/null +++ b/app/helpers/lazy_image_tag_helper.rb @@ -0,0 +1,24 @@ +module LazyImageTagHelper + def placeholder_image + "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" + end + + # Override the default ActionView `image_tag` helper to support lazy-loading + def image_tag(source, options = {}) + options = options.symbolize_keys + + unless options.delete(:lazy) == false + options[:data] ||= {} + options[:data][:src] = path_to_image(source) + options[:class] ||= "" + options[:class] << " lazy" + + source = placeholder_image + end + + super(source, options) + end + + # Required for Banzai::Filter::ImageLazyLoadFilter + module_function :placeholder_image +end |