Coder Social home page Coder Social logo

avatar's Introduction

logo

Consolidated Avatar Template Package for Meteor

ANNOUNCEMENT

This package has been forked from @bengott's original Avatar package since it is longer maintained. It's been added to the utilities collection so that it can henceforth be maintained by other community members.

BREAKING CHANGES

As of version 0.9.0 the React support that was added to version 0.8.0 has been removed. The latest updates to Meteor and the React package have made the build unstable, and despite my best efforts I haven't been able to create a single solution that works with both apps that use and don't use React. Days have been lost trying to solve the issues, and this has stopped me from publishing other updates. This situation will be revisited at a later stage, or else a separate React fork may be considered. In the meantime you'll need to use the Blaze template within your React code.

In version 0.7.14 and earlier the Avatar options were overridden by assigning them directly to Avatar.options. You should no longer do this. Instead, you must call Avatar.setOptions() and pass the options that you wish to override.

The template parameters were overhauled in version 0.5.0. The Avatar.options object changed quite a bit in version 0.6.0 too. And make sure you note the defaultType/fallbackType changes in version 0.7.0. Basically, things are still in a state of flux (pre-1.0.0), so check for breaking changes and read the rest of the README carefully when you update the package.

Installation

In your Meteor project directory, run:

$ meteor add utilities:avatar

Of course, you also need to add the accounts- packages for the services you're using (e.g. accounts-twitter) and accounts-ui or something similar in order to add login functionality to your app.

Usage

In an HTML file:

{{> avatar (user=<user> || userId=<userId>)
           (size="large" || "small" || "extra-small" || <user-defined size>)
           (shape="rounded" || "circle")
           (class="some custom classes")
           (initials="<initials>") (bgColor="<color>") (txtColor="<color>") }}

That may look like a lot of options, but they are all optional. Most of the time, your HTML will look more like this:

{{> avatar user=this shape="circle"}}

Optional template parameters:

  • user or userId: Either a user object or userId string, default avatar if omitted
  • size: Size of the avatar, by default either "large" (80px), "small" (30px), or "extra-small" (20px), although these may be overridden and new ones defined. If no size is provided 50px is used.
  • shape: Used for CSS border-radius property, either "rounded" or "circle", square if omitted
  • class: Any custom CSS classes you'd like to define on the avatar container. The string is passed straight through to the class attribute on the div container element.
  • initials: Specify the initials to show for the initials avatar. The package automatically tries to determine the user's initials from profile data, but if defined, this param will override that.
  • bgColor and txtColor: Override the default colors for the initials avatar (color name or hex value string).

Publishing & Subscribing

This package will help you display an avatar based on the data available in the user object, but it won't actually make that data available for you. In other words, you still need to publish the relevant user profile fields, and subscribe to that publication yourself somewhere in your app's codebase.

Generated CSS

The CSS required by this package is generated based on the options that you configure (see below) and then pushed into the head of your HTML at the point that the application is served to the client. This approach gives us great flexibility and allows us to provide features that would not otherwise be possible (such as custom avatar sizes).

However, since the CSS isn't generated when you build the project, you won't have any styling for Cordova apps (until they talk to the server). In this case you'll need to provide your own CSS for the avatars.

If you don't wish the CSS to be pushed to the client at all then you may set generateCSS to false in the global options.

Global Configuration Options

The package exports a global Avatar object which has a property named options (also an object). The default options provided can be overridden by calling Avatar.setOptions() and passing in the options that you wish to override.

Note that Avatar.setOptions() must be called in both server and client code.

  • fallbackType: Determines the type of fallback to use when no image can be found via linked services (Gravatar included):
    • "default image" (the default option, which will show either the image specified by defaultImageUrl, the package's default image, or a Gravatar default image). OR
    • "initials" (show the user's initials)
  • defaultImageUrl: This will replace the included package default image URL ("packages/utilities_avatar/default.png"). It can be a relative path (e.g. "images/defaultAvatar.png").
  • gravatarDefault: Gravatar default option to use (overrides defaultImageUrl option and included package default image URL). Options are available here.
  • emailHashProperty: This property on the user object will be used for retrieving gravatars (useful when user emails are not published).
  • customImageProperty: If you're storing images URLs in a property on the user object, you can specify it here. You can set it to a function that returns the image URL (this is the user object).
  • cssClassPrefix: This property is used to prefix the CSS classes of the DOM elements generated by this package.
  • imageSizes: This property defines the avatar sizes that are available to your project
  • backgroundColor: The background color for initials avatars (color name or hex value string or a function). The default is gray ("#AAA"). Assign your own background color scheme by passing a function that take only one argument, the user instance and return a CSS compatible color code e.g. "#123abc".
  • textColor: The text color for initials avatars (color name or hex value string or a function). The default is white ("#FFF"). Assign your own text color scheme by passing a function that take only one argument, the user instance and return a CSS compatible color code e.g. "#123abc".
  • generateCSS: When true the CSS required to style the Avatars based on the above settings is generated and pushed to the client when the application is loaded.

Example usage:

  • To show initials when no avatar image can be found via linked services:
Avatar.setOptions({
  fallbackType: "initials"
});
  • To show the included package default image, you don't need to specify any options because this is the default functionality. However, you could specify it explicitly like so:
Avatar.setOptions({
  fallbackType: "default image"
});
  • To show a custom default image:
Avatar.setOptions({
  defaultImageUrl: "img/default-avatar.png" OR "http://example.com/default-avatar.png"
});

Note that Gravatar's default option requires a publicly accessible URL, so it won't work when your app is running on localhost and you're using either the included package default image or a custom defaultImageUrl that is a relative path. It will work fine once deployed though.

  • To show a custom image property defined on the user object
Avatar.setOptions({
  customImageProperty: "imageURL"
});

where the value of imageURL on the user object may either be a string, or a function that returns the image URL. You may also pass a function directly:

Avatar.setOptions({
  customImageProperty: function() {
    var user = this;
    // calculate the image URL here
    return user.profileImageUrl;
  }
});
  • To show one of Gravatar's default options (e.g. "identicon"):
Avatar.setOptions({
  gravatarDefault: "identicon"
});

Note that gravatarDefault overrides defaultImageUrl and the included package default image.

  • Set a value to the cssClassPrefix to avoid conflicts in CSS class names. Setting the property value like this:
Avatar.setOptions({
  cssClassPrefix: 'foo'
});

Will assign CSS class names prefixed by 'foo', like below:

<div class="foo foo-small foo-circle">
    <img class="foo-image" src="path_to_your_avatar" alt="avatar" onerror="this.style.display='none';" width="30" height="30">
    <span class="foo-initials">A</span>
</div>

If a cssClassPrefix is not set, then the default prefix 'avatar' is used for CSS class names in the rendered the HTML:

<div class="avatar avatar-small avatar-circle">
    <img class="avatar-image" src="path_to_your_avatar" alt="avatar" onerror="this.style.display='none';" width="30" height="30">
    <span class="avatar-initials">A</span>
</div>
  • If your app does not publish the user.emails object/property but publishes an email hash property instead, you can specify it like this (the Gravatar package generates a hash internally when you give it an email too; this just allows you to decouple those two steps so as not to make all your users' emails public):
Avatar.setOptions({
  emailHashProperty: "email_hash"
});

Note that you can use Avatar.hash("[email protected]"); to generate a Gravatar email hash.

  • You may override the default avatar sizes, or create new ones, by overriding the imageSizes option:
Avatar.setOptions({
  imageSizes: {
    'large': 80,
    'mySize': 40
  }  
});
  • To use a custom coloring scheme for the initials, first write a function that implements your coloring scheme, then assign that to the backgroundColor option:
var customColorScheme = function (user) {
  if (user.profile.name === "Red")
    return "#ff0000";
  else if (user.profile.name === "Green")
    return "#00ff00";
  else
    return "#aaaaaa";
};

Avatar.setOptions({
  backgroundColor: customColorScheme,
});

How the package chooses an avatar

Given a user object or userId string, Avatar will retrieve the user's image with the following priority:

  1. The user object's custom image URL (stored in the property defined by Avatar.options.customImageProperty)
  2. Twitter
  3. Facebook
  4. Google
  5. GitHub
  6. Instagram
  7. Linkedin
  8. Gravatar, which will try to return an avatar matching the user's email address/hash. If it can't find one, then: - If Avatar.options.fallbackType is "initials", Gravatar returns a 404 (Not Found) response. - Else,
    • If Avatar.options.gravatarDefault is valid, Gravatar will return a default image (e.g. an identicon).
    • If Avatar.options.gravatarDefault is invalid or undefined, Gravatar will return either the image referenced by Avatar.options.defaultImageUrl or the included default image.
  9. If no image can be retrieved, the user's initials will be shown.

Required Fields/Properties on the User Object

Since fields in user.services contain security info, it's often wise to restrict access to those in publications, e.g.:

UsersCollection.find({ /* query */ }, {
  fields: {
    //...
    "services.facebook.id" : true
    //...
  }
});

Fields used to get avatar image (one per service):

"services.twitter.profile_image_url_https"
"services.facebook.id"
"services.google.picture"
"services.github.username"
"services.instagram.profile_picture"
"services.linkedin.pictureUrl"

Fields used to form initials (if needed):

 "profile.firstName"
 "profile.lastName"
 "profile.familyName"
 "profile.secondName"
 "profile.name"

Linked Services/Accounts: By default, the Meteor accounts system creates a separate user account for each service you login with. In order to merge those accounts together, you'd need to use a package like accounts-meld or link-accounts.

Credits

avatar's People

Contributors

aaronjudd avatar bengott avatar cwohlman avatar edsadr avatar em0ney avatar erasaur avatar glennrs avatar gwendall avatar jorisbontje avatar kikobeats avatar kosich avatar moooji avatar mquandalle avatar panayi avatar raiyankamal avatar rodrigok avatar sachag avatar saimeunt avatar silkroadnomad avatar timothyarmes avatar trusktr avatar yoh avatar zimme avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

avatar's Issues

Setting generateCSS to false has no effect

The option generateCSS has no effect because, on initial load, Avatar.setOptions({}); is called, and default value of generateCSS is true. And the injection has already taken place, before anyone could set generateCSS to false. What to do?

Export Gravatar or write proxy method (for Gravatar.hash()) to use emailHashProperty

Hi !

I would to use emailHashProperty to be able to show avatars without publish users emails.
I try to set a profile.emailHash property on user when it is saved but I can't access to Gravatar to use Gravatar.hash() method.
Is there way to do this with this package (through this package) or must I add jparker:gravatar on my project to use Gravatar.hash() ?

Is it intelligent to export Gravatar object or add a proxy method on Avatar to use Gravatar.hash() ?

Request for Plugins and Customization Options

There exists a distinct lack of support for arbitrary services, Enterprise Github avatars in particular. Can we create some sort of plug-in system to expand this package's usability?

Decoupling from rendering libs

This is more a suggestion than an issue. That would be a good idea to have:

  • a package containing the data logic / exposing the Avatar JS object only (that we could also publish to NPM)
  • other packages containing the templates / components based on that logic.

This way that would be easy to use it with either Blaze or React. Have you considered that ?

CSS injected even if generateCSS == false

Hi there,

i'm running

Avatar.setOptions({
    cssClassPrefix: "tt-avatar",
    generateCSS: false,
})

both on client and server but CSS is injected, and without the prefix. What's going on?

version 0.9.2
meteor 1.2.1

Avatar image not showing in basic example

Was just trying out the package, and wasnt able to get a default avatar image to load. I downloaded and saved the default.png avatar image to my projects /public directory. In my html, I had the following:

<div class="col-md-12">
    {{> avatar size="large" shape="circle"}}
</div>

then in my main js file:

Avatar.setOptions({
  defaultImageUrl: "default.png"
});

Yet this is how it appears: http://prntscr.com/br0o6u

How to use random bgColor for each user intials ?

var customColorScheme = function (user) {
  if (user.profile.name === "Red")
    return "#ff0000";
   else if (user.profile.name === "Green")
     return "#00ff00";
   else
     return "#aaaaaa";
 };

   Avatar.setOptions({
   backgroundColor: customColorScheme,
  });

The above is not helping to set the random colors as mentioned in doc,
what it does is it simply adds

 backgroundColor:customColorScheme = function(user){if (user.profile.name === "Red")return"#ff0000";else if (user.profile.name === "Green")return "#00ff00";else return "#aaaaaa"; };" 

as string to the CSS Attribute.

Am I doing this wrong ?? Please help!!

I also tried randomColor js No results..

     var customColorScheme = function () {
       return randomColor();
     };

   Avatar.setOptions({
   backgroundColor: customColorScheme,
  });

Failed to load resource

Getting failed to load resource: bad request for packages/avatar/default.png
I can see default.png in packages/utilities_avatar/default.png and there is no packages/avatar

Custom avatar with dynamic CSS

Is it possible to customize avatar (color border) depending on an option set in user profile?
I'm using Telescope.
https://github.com/fricolab/slowfashionnext-events

I read:

// Default background color when displaying the initials.
// Can also be set to a function to map an user object to a background color.
backgroundColor: "#aaa",

but no idea how to build that function. I have a custom field pointing to a color in user object already.
I know it is not an issue but any help will be welcome!!
Thanks

Should check if url is a function

When using customImageProperty the passed property may actually be a function. For example:

Avatar.setOptions
  customImageProperty: 'pictureUrl'

# Using https://github.com/dburles/meteor-collection-helpers
Meteor.users.helpers
  pictureUrl: ->
    pictureId = @profile?.picture
    if pictureId and (picture = Files.findOne(pictureId))
      picture.url()

This currently fails with: Exception in template helper: TypeError: url.trim is not a function.

Instead

imageUrl: function () {
should be something like:

  imageUrl: function () {
    var user = this.user ? this.user : Meteor.users.findOne(this.userId);
    var url = Avatar.getUrl(user);
    // Check whether url is a function
    if (typeof url === 'function') {
      url = url();
    }
    // Also check that url is a string so that trim() is defined
    if (url && typeof url === 'string' && url.trim() !== '' && Template.instance().firstNode) {
      var img = Template.instance().find('img');
      if (img.src !== url.trim()) {
        img.style.removeProperty('display');
      }
    }
    return url;
  }

Thoughts?

Question: does React support add any overhead to apps?

I'm not very familiar with React so sorry if this is a dumb question, but does adding React support to this package implies additional files will be loaded on the client?

If so, maybe the dependency on react-meteor-data should be made weak as well?

Fail to build [react]

Hi there.

When I run meteor I get this error:

W20150723-16:40:06.549(2)? (STDERR)
W20150723-16:40:06.551(2)? (STDERR) /Users/maz-dev/.meteor/packages/meteor-tool/.1.1.3.e9jr4p++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:245
W20150723-16:40:06.551(2)? (STDERR)                         throw(ex);
W20150723-16:40:06.551(2)? (STDERR)                               ^
W20150723-16:40:06.551(2)? (STDERR) ReferenceError: ReactMeteorData is not defined
W20150723-16:40:06.551(2)? (STDERR)     at packages/utilities:avatar/react/avatar.jsx:10:16
W20150723-16:40:06.551(2)? (STDERR)     at packages/utilities:avatar/react/avatar.jsx:81:7
W20150723-16:40:06.551(2)? (STDERR)     at /Users/maz-dev/code/dev/js/ramble/.meteor/local/build/programs/server/packages/utilities_avatar.js:512:3
W20150723-16:40:06.552(2)? (STDERR)     at /Users/maz-dev/code/dev/js/ramble/.meteor/local/build/programs/server/boot.js:222:10
W20150723-16:40:06.552(2)? (STDERR)     at Array.forEach (native)
W20150723-16:40:06.552(2)? (STDERR)     at Function._.each._.forEach (/Users/maz-dev/.meteor/packages/meteor-tool/.1.1.3.e9jr4p++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/underscore/underscore.js:79:11)
W20150723-16:40:06.552(2)? (STDERR)     at /Users/maz-dev/code/dev/js/ramble/.meteor/local/build/programs/server/boot.js:117:5

The react package is indeed included.

Any idea on what might be the issue?

Thanks.

Please update your instructions to clarify the need for properly publishing/subscribing to profile picture data

This package did not work properly for me until I added the folllowing. It was not clear to me from the instructions that there was a need to do this. Before adding this, I was stuck with just displaying user initials, and was not aware the issue was tied to publish/subscribe.

Client-side:

Meteor.subscribe('userData');

Server-side (in my case, for login via Facebook/Google):

Meteor.publish("userData", function () {
  if (this.userId) {
    return Meteor.users.find( {_id: this.userId},
      {fields: 
        {
          "services.google.picture": true,
          "services.google.name": true,
          "services.facebook.id": true,
          "services.facebook.name": true
        }
      });
  } else {
    this.ready();
  }
});

Please consider updating the instructions to clarify the need for proper publish/subscribe. (Or perhaps simply have the package itself add these publish/subscribe code snippets?)

react component errs out

Trying to use this with react, and the following component within a loop of users to show the avatar:

<Avatar userId={this.props.member._id} shape="circle" />

However, I'm receiving the following error:

debug.js:41 Exception from Tracker recompute function:
debug.js:41 TypeError: type.toUpperCase is not a function
at autoGenerateWrapperClass (react-runtime-dev.js?8fefd85d334323f8baa58410bac59b2a7f426ea7:9787)
at Object.getComponentClassForElement (react-runtime-dev.js?8fefd85d334323f8baa58410bac59b2a7f426ea7:13823)
at validatePropTypes (react-runtime-dev.js?8fefd85d334323f8baa58410bac59b2a7f426ea7:10727)
at Object.require.react/lib/ReactElementValidator.ReactElementValidator.createElement (react-runtime-dev.js?8fefd85d334323f8baa58410bac59b2a7f426ea7:10774)
at React.createClass.render (GroupMember.jsx:22)
at require.react/lib/ReactCompositeComponent.ReactCompositeComponentMixin._renderValidatedComponentWithoutOwnerOrContext (react-runtime-dev.js?8fefd85d334323f8baa58410bac59b2a7f426ea7:7479)
at require.react/lib/ReactCompositeComponent.ReactCompositeComponentMixin._renderValidatedComponent (react-runtime-dev.js?8fefd85d334323f8baa58410bac59b2a7f426ea7:7506)
at require.react/lib/ReactPerf.ReactPerf.measure.wrapper [as _renderValidatedComponent] (react-runtime-dev.js?8fefd85d334323f8baa58410bac59b2a7f426ea7:14055)
at require.react/lib/ReactCompositeComponent.ReactCompositeComponentMixin.mountComponent (react-runtime-dev.js?8fefd85d334323f8baa58410bac59b2a7f426ea7:6927)
at require.react/lib/ReactPerf.ReactPerf.measure.wrapper [as mountComponent] (react-runtime-dev.js?8fefd85d334323f8baa58410bac59b2a7f426ea7:14055)

Use in server side

I would like to use {{> avatar }} while rendering templates in the server side. I am using meteor-handlebars-server.

When I try to render myTemplate.handlebars with avatar partial, I get:

Error: The partial avatar could not be found

I tried to make myTemplate.js in the server directory like this:

Handlebars.templates.myTemplate({}, {
  avatar: Handlebars.templates.avatar
});

But it didn't do anything. Any suggestions?

Please update instructions to clarify the need for adding a data context

Currently, in your instructions, you write:

Most of the time, your HTML will look more like this:

{{> avatar user=this shape="circle"}}

I would recommend that you update your instructions to clarify that this will not work without the proper data context, such as the following:

  {{#with currentUser}}
    {{> avatar user=this shape="circle"}}
  {{/with}}

No CSS with Meteor 1.3 (beta 8)

Tried this package with the latest beta of Meteor 1.3, everything is working but it looks like the CSS is not loaded. Downgrading to Meteor 1.2.1 resolved the issue.

Any plans to support the next version of Meteor ?

License file

Any chance you can add a license file please?

Thanks,
Ben

Colourful background when initials are shown

Proposal for enhancement
A project I'm working on requires colourful backgrounds when user's initials are shown in place of avatar images. Much like the Gmail app. Do others find this feature useful? If yes, I'll send a pull request to merge this functionality.

Suggestion : optional CSS

the initial css is great for prototyping etc, but in a production app, I really rather this didn't stick its default styles in the header, would be great to be able to pass an option to turn it off.

serving the meteor app over SSL

When serving the meteor app over SSL (https:), all content that requests resources (i.e.images) over plain HTTP (http:) is considered BAD. A solution is to NOT specify the protocol. So instead of

<img src="http://i0.wp.com/pilot.get12.com/packages/avatar/default.png">

you could write it as

<img src="//i0.wp.com/pilot.get12.com/packages/avatar/default.png">

The browser will then use the protocol that was used to serve the initial HTML page. It would work in both cases (plain & SSL) without any BAD warnings, and warning signs in the lock of the addressbar (Chrome).

Could you do that? That would be grand!

screen shot 2015-07-28 at 23 33 29

custom default image not working on live server

Hey There

we've loaded our app on a digital ocean box and it seems like the URL for default image is being escaped?

my options look like :

Avatar.setOptions({
  fallbackType: 'default image',
  defaultImageUrl: "img/avatar-default.png",
  customImageProperty: 'profile.avatarUrl',
});

If I navigate to the url the image is loaded, but inspecting the source I get the following :

https://secure.gravatar.com/avatar/527aaddfcf91ca986f16b23dd4b2c80d?default=http%3A%2F%2Flocalhost%3A3000%2Fimg%2Favatar-default.png&size=200

any ideas?

getInitials not internationally friendly?

I'd expect SashaG would know this but getInitials in export.js seems like if nothing else it should at least have docs that say if you use this function your Japanese and Chinese users are going to have initials that make absolutely no sense to them.

My point being devs should probably be discouraged or at least warned? Or maybe that function should just be removed? Just a thought.

Update to meteor 1.2

I'm getting the following message / error when trying to update to meteor 1.2

While selecting package versions:
error: Potentially incompatible change required to top-level dependency: utilities:avatar 0.9.0, was 0.9.2.
Constraints on package "utilities:avatar":

Rendering on the server side

Originally posted by @sungwoncho:


I would like to use {{> avatar }} while rendering templates in the server side. I am using meteor-handlebars-server.

When I try to render myTemplate.handlebars with avatar partial, I get:

Error: The partial avatar could not be found

I tried to make myTemplate.js in the server directory like this:

Handlebars.templates.myTemplate({}, {
  avatar: Handlebars.templates.avatar
});

But it didn't do anything. Any suggestions?

Ghostery blocks avatar

Ghostery is blocking Gravatar, and as a result the avatar package can't detect that no image is coming back and shows users that have Ghostery installed a broken image.

Avatar image as link

It would be really nice to have an avatar image as link. For example, in application I'm working on, we need to be able to click on user avatar in order to go to his profile page. Is it currently possible?

'Size' kind of sucks

(size="large" || "small" || "extra-small") is sorta crappy. I wonder if there's a good reason for not just using pixel values (or at least overrides for them). Any insight?

Offline support

Hi,
is there any possibility to have an offline support for the avatar?
Obviously, the app cannot access the url for the profile picture when not online. Did someone try to download the avatar to the database or something like that? Is it possible to cache avatar pictures from an external url?
Thanks for your help.

Can't publish new version

I'm trying to publish a new version for Meteor 1.2 compatibility, but I get the following error:

Sachas-MacBook-Pro:meteor-avatar sacha$ meteor publish
=> Errors while initializing project:

While building package utilities:avatar:
packages/check/match.js:299:1: Match error: Unknown key in field react (compiling react/avatar.jsx)
at packages/check/match.js:299:1
at Function._.each._.forEach (packages/underscore/underscore.js:113:1)
at checkSubtree (packages/check/match.js:290:1)
at check (packages/check/match.js:32:1)
at Object.getDefaultOptions (packages/babel-compiler/babel.js:8:1)
at handler (packages/transpileJSX/jsx-plugin.js:4:1)

Facebook image not showing

Hello:

I'm using the accounts-facebook`` package for login and am successfully pulling back the Facebook services data, includinguser.services.facebook.idand storing it in the user document. However when I call{{> avatar user=this shape="circle"}}``` in my template I just get an empty gray circle with no errors. Any ideas what the issue might be?

Suggestion to update your Guide

Nice package! Thanks!!!

One good tip to add in your Documentation is to have the following Data context when the Avatar does not show.


  <p>{{> avatar user=this shape="circle"}}</p>

{{/with}}```

CSS not injected into head

For some reason the generated css is not injected into the head. I copied it manually into a css file so it works for now, but anyway, any ideas what could cause this?

put avatar in the same line

I have a array of user ID and want to set a line of avatar base on this array. So I use

        {{#each userIDs}}
            <span>{{> avatar userId=this size="small"}}</span>
        {{/each}}

But the avatars stack vertically. Can someone help me ?
Thank you

Android / Cordova - avatar not displayed

Any issue with this on Cordova Apps?

I have it working nicely on web, but on cordova I only see a white flash of my circular avatar and then it is hidden - no errors. Anyone else having this issue?

Just return URL

It would be nice to have a simple option that can just return the image URL, this way you can use it in an img tag

Ability to work with GridFS stored images

I'm using GridFS for images storage and storing it in different sizes as described here: Meteor-CollectionFS#image-manipulation.
Currently there is no way to tell avatar which size of GridFS image to serve so it always serves the smallest size by default. I had to use this hack in order for the script to work:

Template.profile.helpers({
  userImage: function(){
    return Images.findOne({source_id: this._id}); // Where Images is an FS.Collection instance
  },
});

and then in Blaze:

{{#if userImage}}
  <div class="avatar avatar-thumbnail avatar-circle">
    <img class="avatar-image" src="{{userImage.url store='thumbnail'}}" alt="avatar">
  </div>
{{else}}
  {{> avatar user=this size="medium" shape="circle" }}
{{/if}}

Can you please add the feature for specifying GridFS image size?
Here's more insight into how it works: Meteor-CollectionFS#display-an-uploaded-image
Thanks in advance.

Hiding 404s?

Since the package handles fallbacks when a user's gravatar is not found, should we consider preventing the 404 error from appearing in the console? Assuming there's a way to do it, of course…

Avatar template helper error

Hi...
I changed bengott:avatar to meteor-utilities:avatar, updated to 0.9.1, Meteor to 1.2.0.1 and now I have this errors in console:
Exception in template helper: TypeError: Cannot read property 'small' of undefined
at sizeClass (http://localhost:3000/packages/utilities_avatar.js?12c7b208abebf60f6408542b905c45bc26de8c48:237:35)
at Object.Template.avatar.helpers.size (http://localhost:3000/packages/utilities_avatar.js?12c7b208abebf60f6408542b905c45bc26de8c48:89:12)
at bindDataContext (http://localhost:3000/packages/blaze.js?695c7798b7f4eebed3f8ce0cbb17c21748ff8ba8:2994:16)
at Blaze._wrapCatchingExceptions (http://localhost:3000/packages/blaze.js?695c7798b7f4eebed3f8ce0cbb17c21748ff8ba8:1658:16)
at http://localhost:3000/packages/blaze.js?695c7798b7f4eebed3f8ce0cbb17c21748ff8ba8:3046:66
at Function.Template._withTemplateInstanceFunc (http://localhost:3000/packages/blaze.js?695c7798b7f4eebed3f8ce0cbb17c21748ff8ba8:3679:12)
at wrapHelper (http://localhost:3000/packages/blaze.js?695c7798b7f4eebed3f8ce0cbb17c21748ff8ba8:3045:27)
at Spacebars.call (http://localhost:3000/packages/spacebars.js?3eafdd2d5d5d8f08431aa842df4b5e8142600b17:175:18)
at Spacebars.mustacheImpl (http://localhost:3000/packages/spacebars.js?3eafdd2d5d5d8f08431aa842df4b5e8142600b17:112:25)
at Object.Spacebars.mustache (http://localhost:3000/packages/spacebars.js?3eafdd2d5d5d8f08431aa842df4b5e8142600b17:116:39)

My jade snippet:
+avatar(user=currentUser shape='rounded' size='small')

The avatar is displayed, but big, not small...

If without size='small', when error almost the same
Exception in template helper: TypeError: Cannot read property 'undefined' of undefined

What I have to do?? Or what I am doing wrong?

React component throws TypeError: type.toUpperCase is not a function

Thx for providing a React component, much appreciated! I get an error, though

Test = React.createClass({
  render(){
    return (
      <div>
        <Avatar userId={this.props.userId} />
      </div>
    )
  }
})

this.props.userId works fine, and here's the error

TypeError: type.toUpperCase is not a function
    at autoGenerateWrapperClass (react-0.13.3.js:9729)
    at Object.getComponentClassForElement (react-0.13.3.js:13744)
    at validatePropTypes (react-0.13.3.js:10972)
    at Object.ReactElementValidator.createElement (react-0.13.3.js:11019)
    at React.createClass.render (StandardAvatar.jsx:6)
    at ReactCompositeComponentMixin._renderValidatedComponentWithoutOwnerOrContext (react-0.13.3.js:7445)
    at ReactCompositeComponentMixin._renderValidatedComponent (react-0.13.3.js:7472)
    at ReactPerf.measure.wrapper (react-0.13.3.js:13970)
    at ReactCompositeComponentMixin.mountComponent (react-0.13.3.js:6893)
    at ReactPerf.measure.wrapper [as mountComponent] (react-0.13.3.js:13970)

Googling a little this basically means something is returning null, not sure what it is though

avatar size issues

I have Avatar options like this:

Avatar.options = {
  customImageProperty: "imageURL",
  fallbackType: "default image",
  emailHashProperty: "emailHash",
  defaultImageUrl: "/images/avatar.png",
  gravatarDefault: "mm",
};

and use avatar like this:

{{> avatar user=currentUser size="large"}}

The size attribute does not recognize the "large" value and set to the default 50x50 px

then I set the options

Avatar.options = {
  customImageProperty: "imageURL",
  imageSizes: {
    'large': 80,
    'small': 30,
    'extra-small': 20,
    'mySize': 400
  },
  fallbackType: "default image",
  emailHashProperty: "emailHash",
  defaultImageUrl: "/images/avatar.png",
  gravatarDefault: "mm",
};

and the size attribute recognize the "large" value but it set the large avatar to 200x200px
It also recognize the small and extra-small with 30 and 20. But when I use my custom size like

small:40

it doesn't work, still 30px
And it does not recognize my custom size "mySize" also when I use it.
I don't know what happen ? Please help me here.
Thank you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.