diff --git a/app/assets/images/user_default.jpg b/app/assets/images/user_default.jpg deleted file mode 100644 index c67f27f55..000000000 Binary files a/app/assets/images/user_default.jpg and /dev/null differ diff --git a/app/assets/images/user_default_2.jpg b/app/assets/images/user_default_2.jpg deleted file mode 100644 index ed164ab57..000000000 Binary files a/app/assets/images/user_default_2.jpg and /dev/null differ diff --git a/app/assets/images/user_default_big.jpg b/app/assets/images/user_default_big.jpg deleted file mode 100644 index d1c5bcea2..000000000 Binary files a/app/assets/images/user_default_big.jpg and /dev/null differ diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index d6dedd05c..0f9e4b9b0 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -16,11 +16,13 @@ //= require turbolinks //= require ckeditor/init //= require social-share-button +//= require initial //= require app //= require_tree . var initialize_modules = function() { App.Comments.initialize(); + App.Users.initialize(); App.Votes.initialize(); }; diff --git a/app/assets/javascripts/users.js.coffee b/app/assets/javascripts/users.js.coffee new file mode 100644 index 000000000..839b87fce --- /dev/null +++ b/app/assets/javascripts/users.js.coffee @@ -0,0 +1,5 @@ +App.Users = + + initialize: -> + $('.avatar').initial(); + false diff --git a/app/assets/stylesheets/debates.scss b/app/assets/stylesheets/debates.scss index a97764583..3faf62632 100644 --- a/app/assets/stylesheets/debates.scss +++ b/app/assets/stylesheets/debates.scss @@ -524,16 +524,6 @@ } } - .user-photo { - border-radius: 2px; - display: inline-block; - height: 32px; - line-height: $line-height*2; - margin-right: rem-calc(6); - vertical-align: top; - width: 32px; - } - .comment-body { margin-left: $line-height*1.6; @@ -569,4 +559,4 @@ } } } -} \ No newline at end of file +} diff --git a/app/assets/stylesheets/participacion.scss b/app/assets/stylesheets/participacion.scss index 60ffc337d..cbd95ada8 100644 --- a/app/assets/stylesheets/participacion.scss +++ b/app/assets/stylesheets/participacion.scss @@ -522,4 +522,4 @@ form { } } } -} \ No newline at end of file +} diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb new file mode 100644 index 000000000..3fb4c0f67 --- /dev/null +++ b/app/helpers/users_helper.rb @@ -0,0 +1,24 @@ +module UsersHelper + def avatar_image(user, options = {}) + style = options.fetch(:style) { :small } + klass = options.fetch(:class) { '' } + round_corners = options.fetch(:round_corners) { true } + + data_attributes = case style + when :profile + { height: 100, width: 100 } + when :small + { height: 32, width: 32, "font-size" => 20 } + else + {} + end + + if round_corners + radius = (data_attributes[:height].to_i * 0.13).round + data_attributes.merge!(radius: radius) + end + data_attributes.merge!(name: user.name) + + content_tag :img, nil, class: "avatar #{klass}", data: data_attributes + end +end diff --git a/app/views/account/show.html.erb b/app/views/account/show.html.erb index ecfb17209..68274654d 100644 --- a/app/views/account/show.html.erb +++ b/app/views/account/show.html.erb @@ -36,13 +36,15 @@

<%= t("account.show.avatar")%>

- <%= image_tag('user_default_big.jpg', class: "avatar", size: "100x100") %> + <%= avatar_image(@account, style: :profile) %>

<%= t("account.show.notifications")%>

+ <%= f.label :email_on_debate_comment do %> <%= f.check_box :email_on_debate_comment %> <%= t("account.show.email_on_debate_comment_label") %> <% end %> + <%= f.label :email_on_comment_reply do %> <%= f.check_box :email_on_comment_reply %> <%= t("account.show.email_on_comment_reply_label") %> @@ -55,4 +57,4 @@
<% end %> - \ No newline at end of file + diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb index 466752044..468681fec 100644 --- a/app/views/comments/_comment.html.erb +++ b/app/views/comments/_comment.html.erb @@ -1,7 +1,7 @@
- <%= image_tag('user_default_2.jpg', class: 'user-photo left', size: '32x32') %> + <%= avatar_image(comment.user, style: :small, class: 'left') %>
diff --git a/app/views/debates/show.html.erb b/app/views/debates/show.html.erb index 782ecb040..3c2a53674 100644 --- a/app/views/debates/show.html.erb +++ b/app/views/debates/show.html.erb @@ -14,7 +14,7 @@

<%= @debate.title %>

- <%= image_tag('user_default.jpg', class: 'author-photo', size: '32x32') %> + <%= avatar_image(@debate.author, style: :small) %> <%= @debate.author.name %> @@ -62,4 +62,4 @@ <%= render @debate.root_comments.recent %>
- \ No newline at end of file + diff --git a/vendor/assets/javascripts/initial.js b/vendor/assets/javascripts/initial.js new file mode 100644 index 000000000..fde754dea --- /dev/null +++ b/vendor/assets/javascripts/initial.js @@ -0,0 +1,64 @@ +(function ($) { + $.fn.initial = function (options) { + + // Defining Colors + var colors = ["#1abc9c", "#16a085", "#f1c40f", "#f39c12", "#2ecc71", "#27ae60", "#e67e22", "#d35400", "#3498db", "#2980b9", "#e74c3c", "#c0392b", "#9b59b6", "#8e44ad", "#bdc3c7", "#34495e", "#2c3e50", "#95a5a6", "#7f8c8d", "#ec87bf", "#d870ad", "#f69785", "#9ba37e", "#b49255", "#b49255", "#a94136"]; + + return this.each(function () { + + var e = $(this); + var settings = $.extend({ + // Default settings + name: 'Name', + charCount: 1, + textColor: '#ffffff', + height: 100, + width: 100, + fontSize: 60, + fontWeight: 400, + fontFamily: 'HelveticaNeue-Light,Helvetica Neue Light,Helvetica Neue,Helvetica, Arial,Lucida Grande, sans-serif', + radius: 0 + }, options); + + // overriding from data attributes + settings = $.extend(settings, e.data()); + + // making the text object + var c = settings.name.substr(0, settings.charCount).toUpperCase(); + var cobj = $('').attr({ + 'y': '50%', + 'x': '50%', + 'dy' : '0.35em', + 'pointer-events':'auto', + 'fill': settings.textColor, + 'font-family': settings.fontFamily + }).html(c).css({ + 'font-weight': settings.fontWeight, + 'font-size': settings.fontSize+'px', + }); + + var colorIndex = Math.floor((c.charCodeAt(0) - 65) % colors.length); + + var svg = $('').attr({ + 'xmlns': 'http://www.w3.org/2000/svg', + 'pointer-events':'none', + 'width': settings.width, + 'height': settings.height + }).css({ + 'background-color': colors[colorIndex], + 'width': settings.width+'px', + 'height': settings.height+'px', + 'border-radius': settings.radius+'px', + '-moz-border-radius': settings.radius+'px' + }); + + svg.append(cobj); + // svg.append(group); + var svgHtml = window.btoa(unescape(encodeURIComponent($('
').append(svg.clone()).html()))); + + e.attr("src", 'data:image/svg+xml;base64,' + svgHtml); + + }) + }; + +}(jQuery)); \ No newline at end of file