gitlab-org--gitlab-foss/app/helpers/lazy_image_tag_helper.rb

26 lines
648 B
Ruby
Raw Normal View History

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] ||= {}
2017-10-05 14:29:45 +00:00
options[:data][:src] = path_to_image(source)
2017-10-04 11:58:32 +00:00
options[:class] ||= ""
options[:class] << " lazy"
source = placeholder_image
end
super(source, options)
end
# Required for Banzai::Filter::ImageLazyLoadFilter
module_function :placeholder_image
end