From 56e9f0927771ab166b9d83e7d985ab1faedcc0d8 Mon Sep 17 00:00:00 2001 From: Paul Adam Davis Date: Wed, 28 Jan 2015 16:30:03 +0000 Subject: [PATCH] Update user image styles Related to #4844 The newly added user image in the content list uses a CSS property to crop `img` tags, but it's not supported in IE or Firefox. This issue corrects that by chancing them to be background images which can be cropped cross-browser. It also adjusts the nav bar user image (previously an `img` tag) which would squash a non-square image. Also removes the border around the settings/users/ user images, to be consistent with the rest of the UI. --- .../assets/sass/components/navigation.scss | 11 +++----- core/client/assets/sass/layouts/content.scss | 10 +++---- core/client/assets/sass/layouts/users.scss | 10 +++---- core/client/assets/sass/modules/mixins.scss | 26 +++++++++++++++++++ core/client/controllers/application.js | 12 +++++++-- core/client/controllers/posts/post.js | 4 +++ core/client/templates/-navbar.hbs | 8 +++--- core/client/templates/posts.hbs | 4 ++- 8 files changed, 56 insertions(+), 29 deletions(-) diff --git a/core/client/assets/sass/components/navigation.scss b/core/client/assets/sass/components/navigation.scss index 0e8948f725..b740b0197f 100644 --- a/core/client/assets/sass/components/navigation.scss +++ b/core/client/assets/sass/components/navigation.scss @@ -125,14 +125,9 @@ // Profile picture .image { - float: left; - margin: 15px 8px 0 0; - - img { - display: block; - width: 30px; - height: 30px; - border-radius: 100%; + @include circular-image(30px) { + float: left; + margin: 15px 14px 0 0; } } diff --git a/core/client/assets/sass/layouts/content.scss b/core/client/assets/sass/layouts/content.scss index be9d4ebabc..59f4815f22 100644 --- a/core/client/assets/sass/layouts/content.scss +++ b/core/client/assets/sass/layouts/content.scss @@ -122,12 +122,10 @@ } .avatar { - width: 18px; - height: 18px; - border-radius: 18px; - margin-right: 14px; - float: left; // Used instead of `display: block;` to remove the stupid space under the image. - object-fit: cover; // Like using 'background-size: cover;', but on an img tag - https://developer.mozilla.org/en-US/docs/Web/CSS/object-fit + @include circular-image(18px) { + float: left; // Used instead of `display: block;` to remove the stupid space under the image. + margin-right: 14px; + } } .status, diff --git a/core/client/assets/sass/layouts/users.scss b/core/client/assets/sass/layouts/users.scss index 075fb0a061..d980b4064e 100644 --- a/core/client/assets/sass/layouts/users.scss +++ b/core/client/assets/sass/layouts/users.scss @@ -97,13 +97,9 @@ a.user-list-item { } .user-list-item-figure { - width: 35px; - height: 35px; - display: block; - border: 1px solid #979797; - border-radius: 100%; - background-size: cover; - background-position: center center; + @include circular-image(35px) { + display: block; + } } .user-list-item-icon, diff --git a/core/client/assets/sass/modules/mixins.scss b/core/client/assets/sass/modules/mixins.scss index 3871bbe91f..428675cf4b 100644 --- a/core/client/assets/sass/modules/mixins.scss +++ b/core/client/assets/sass/modules/mixins.scss @@ -8,6 +8,7 @@ // * tab-focus() // * triangle() // * set-triangle-color() +// * circular-image() // ------------------------------------------------------------ @@ -99,4 +100,29 @@ } @else { @return "transparent"; } +} + + +// +// Reusable styles for creating a circular image which is cropped properly, with the image inside it +// Example: @circular-image(35px); +// -------------------------------------------------- + +@mixin circular-image($widthandheight: 20px) { + @content; + width: $widthandheight; + height: $widthandheight; + border-radius: $widthandheight; + background-size: cover; + background-position: center center; + position: relative; + + img { + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; + opacity: 0; + } } \ No newline at end of file diff --git a/core/client/controllers/application.js b/core/client/controllers/application.js index 951490fd45..ef92105d03 100644 --- a/core/client/controllers/application.js +++ b/core/client/controllers/application.js @@ -7,10 +7,18 @@ var ApplicationController = Ember.Controller.extend({ showGlobalMobileNav: false, showSettingsMenu: false, - userImageAlt: Ember.computed('session.user.name', function () { + userImage: Ember.computed('session.user.image', function () { + return this.get('session.user.image') || this.get('ghostPaths.url').asset('/shared/img/user-image.png'); + }), + + userImageBackground: Ember.computed('userImage', function () { + return 'background-image: url(' + this.get('userImage') + ')'; + }), + + userImageAlt: Ember.computed('session.user.name', function () { var name = this.get('session.user.name'); - return name + '\'s profile picture'; + return (name) ? name + '\'s profile picture' : 'Profile picture'; }), actions: { diff --git a/core/client/controllers/posts/post.js b/core/client/controllers/posts/post.js index adfdb369ee..40f655176c 100644 --- a/core/client/controllers/posts/post.js +++ b/core/client/controllers/posts/post.js @@ -10,6 +10,10 @@ var PostController = Ember.Controller.extend({ return this.get('model.author.image') || this.get('ghostPaths.url').asset('/shared/img/user-image.png'); }), + authorAvatarBackground: Ember.computed('authorAvatar', function () { + return 'background-image: url(' + this.get('authorAvatar') + ')'; + }), + actions: { toggleFeatured: function () { var options = {disableNProgress: true}, diff --git a/core/client/templates/-navbar.hbs b/core/client/templates/-navbar.hbs index 89b04ef9ae..54cdb4a3ec 100644 --- a/core/client/templates/-navbar.hbs +++ b/core/client/templates/-navbar.hbs @@ -31,11 +31,9 @@