app/helpers/site/image_helper.rb
# Generates a responsive IMG tag with lazyloading from a Media object.
#
# === Parameters
#
# [media] the media item
# [options] a hash of options
Generates a responsive IMG tag with lazyloading from a Media object.
Parameters

[media] the media item
[options] a hash of options
Generates a responsive IMG tag with lazyloading from a Media object . Parameters [ media ] the media item [ options ] a hash of options
def lazyloaded_image_tag( media, options = {} )
    return unless media.is_a?( Media )
    options = {
      default: BASE_DEFAULT,
      dimensions: BASE_DIMENSIONS,
      html: {},
      blur: false
    }.deep_merge( options )
    html_attrs = {
      alt:    media.alt_text,
      class:  ''
    }.merge( options[:html] )
    html_attrs[:class] = "#{html_attrs[:class]} lazyload".strip
    html_attrs[:src] = options[:blur] ? media.base64_preview : 'data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=='
    html_attrs[:'data-srcset'] = options[:dimensions].map{ |size| variation_path( media, size ) + " #{size}w" }.join(',')
    html_attrs[:sizes] = 'auto'
    retval = tag( :img, html_attrs )
    html_attrs[:srcset] = html_attrs[:'data-srcset']
    html_attrs[:class]  = html_attrs[:class].gsub(/lazyload/, 'lazyload-fallback')
    html_attrs[:src]    = variation_path( media, options[:default] )
    html_attrs.delete( :'data-srcset' )
    retval + '<noscript>'.html_safe + tag( :img, html_attrs ) + '</noscript>'.html_safe
  end
def lazyloaded_image_tag ( media , options = { } ) return unless media . is_a? ( Media ) options = { default : BASE_DEFAULT , dimensions : BASE_DIMENSIONS , html : { } , blur : false } . deep_merge ( options ) html_attrs = { alt : media . alt_text , class : '' } . merge ( options [ :html ] ) html_attrs [ :class ] = "#{html_attrs[:class]} lazyload" . strip html_attrs [ :src ] = options [ :blur ] ? media . base64_preview : 'data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==' html_attrs [ :' data-srcset ' ] = options [ :dimensions ] . map { | size | variation_path ( media , size ) + " #{size}w" } . join ( ',' ) html_attrs [ :sizes ] = 'auto' retval = tag ( :img , html_attrs ) html_attrs [ :srcset ] = html_attrs [ :' data-srcset ' ] html_attrs [ :class ] = html_attrs [ :class ] . gsub ( / lazyload / , 'lazyload-fallback' ) html_attrs [ :src ] = variation_path ( media , options [ :default ] ) html_attrs . delete ( :' data-srcset ' ) retval + '<noscript>' . html_safe + tag ( :img , html_attrs ) + '</noscript>' . html_safe end
Generates a responsive IMG tag with lazyloading from a Media object.
Generates a responsive IMG tag with lazyloading from a Media object .
# fail # default some options # default some HTML attrs # Handle some lazyloading # html_attrs[:style] = "width: #{options[:dimensions].max}px" # now some noscript stuff
media
options