Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if Gravatar Returns a 404 #40

Open
realph opened this issue Apr 1, 2016 · 2 comments
Open

Check if Gravatar Returns a 404 #40

realph opened this issue Apr 1, 2016 · 2 comments

Comments

@realph
Copy link

realph commented Apr 1, 2016

Is there a way to check if the gravatar exists, and if it doesn't return some other element?

<img ng-if="gravatarExists" gravatar-src-once="user.email">
<div ng-if"!gravatarExists">Some other element</div>

Any help is appreciated. Thanks in advance!

@wallin
Copy link
Owner

wallin commented Apr 2, 2016

Hi, that's I good idea. I looks like it's possible if you set the fallback image to '404', because then you can detect if the image was loaded correctly or not by doing a element.bind('error', -> ...) here:
https://github.com/wallin/angular-gravatar/blob/master/src/angular-gravatar.coffee#L22

However we'd need the variable to be default true, otherwise it won't even try to load the image.
And, I'd need to figure out in which scope to put the variable if you'd want to use it like in your example.

I'll see if I can get something to work, but unfortunately I don't have so much time to look into it atm. Let me know if you have any ideas, and feel free to do a pull request if you come up with something

Thanks!

@jenslind
Copy link

I also need a nice way of hiding/showing different elements if the gravatar returns a 404.

Perhaps we could solve it with something like the following:

<img gravatar-error="controller.gravatarExists = false">
element.bind('error', function () {
  scope.$apply(attrs[gravatar-error])
})

Thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants