diff options
author | kushalpandya <kushal@gitlab.com> | 2017-09-22 18:52:50 +0300 |
---|---|---|
committer | kushalpandya <kushal@gitlab.com> | 2017-09-25 09:19:20 +0300 |
commit | abb9981d2053ef6808ef877c0066fd53b766f06c (patch) | |
tree | 45fa81eb5b8b98f963871164e58f9b74e54e43bd /app | |
parent | 31d43e34589aaf77512203a8f9278476e3d46436 (diff) |
Add `data-src` when image is to be lazy loaded, use `tag` helper instead of `image_tag` helper
Diffstat (limited to 'app')
-rw-r--r-- | app/helpers/avatars_helper.rb | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/app/helpers/avatars_helper.rb b/app/helpers/avatars_helper.rb index a4c226a6aad..be11d453898 100644 --- a/app/helpers/avatars_helper.rb +++ b/app/helpers/avatars_helper.rb @@ -13,22 +13,29 @@ module AvatarsHelper user_name = options[:user].try(:name) || options[:user_name] avatar_url = options[:url] || avatar_icon(options[:user] || options[:user_email], avatar_size) has_tooltip = options[:has_tooltip].nil? ? true : options[:has_tooltip] - data_attributes = {} + data_attributes = options[:data] || {} css_class = %W[avatar s#{avatar_size}].push(*options[:css_class]) if has_tooltip css_class.push('has-tooltip') - data_attributes = { container: 'body' } + data_attributes[:container] = 'body' end - image_tag( - avatar_url, + if options[:lazy] + css_class << 'lazy' + data_attributes[:src] = avatar_url + avatar_url = LazyImageTagHelper.placeholder_image + end + + image_options = { + alt: "#{user_name}'s avatar", + src: avatar_url, + data: data_attributes, class: css_class, - alt: "#{user_name}'s avatar", - title: user_name, - data: data_attributes, - lazy: true - ) + title: user_name + } + + tag(:img, image_options) end def user_avatar(options = {}) |