2017-07-24 17:36:52 +00:00
|
|
|
module Banzai
|
|
|
|
module Filter
|
2017-09-12 15:14:54 +00:00
|
|
|
# HTML filter that moves the value of image `src` attributes to `data-src`
|
|
|
|
# so they can be lazy loaded.
|
2017-07-24 17:36:52 +00:00
|
|
|
class ImageLazyLoadFilter < HTML::Pipeline::Filter
|
|
|
|
def call
|
|
|
|
doc.xpath('descendant-or-self::img').each do |img|
|
|
|
|
img['class'] ||= '' << 'lazy'
|
|
|
|
img['data-src'] = img['src']
|
2017-08-15 17:44:37 +00:00
|
|
|
img['src'] = LazyImageTagHelper.placeholder_image
|
2017-07-24 17:36:52 +00:00
|
|
|
end
|
2017-08-15 17:44:37 +00:00
|
|
|
|
2017-07-24 17:36:52 +00:00
|
|
|
doc
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|