Skip to content
This repository has been archived by the owner on Mar 26, 2024. It is now read-only.

Commit

Permalink
Fourth Commit
Browse files Browse the repository at this point in the history
Fixed a bug caused by google not supplying their default avatar which
meant logged in users with the default picture would see no avatar
beside the input box.
  • Loading branch information
pmck91 committed May 3, 2013
1 parent 07ec8da commit 7f288df
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 8 deletions.
44 changes: 39 additions & 5 deletions client/client.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
Meteor.subscribe("user_services");
/***************************
|||| Meteors client code ||||
****************************/

Meteor.startup(function (){
Meteor.subscribe("user_services");
Session.setDefault('service','none');
Session.setDefault('loggedIn','false');
Session.setDefault('possibleGoogleAvatarProblem','true');
Session.setDefault('page','0');
});

var MAX_CHARS = 200;

Expand All @@ -12,7 +22,21 @@ Template.header.greeting = function () {

// code run on loading of #userInput
Template.userInput.rendered = function() {
$('#inputAvatar').css('background-image', 'url(\''+Session.get('avatarURL')+'\')');
Session.set('possibleGoogleAvatarProblem','true');

if(Session.get('service') == 'google') {
$('#inputAvatar').css('background-image', 'url(\'default.png\')');
// found on stack exchange, deals with the fact google returns no image if the user is using the google default
var hiddenImg = new Image();
hiddenImg.onload = function(){
$('#inputAvatar').css('background-image', 'url(\''+Session.get('avatarURL')+'\')');
Session.set('possibleGoogleAvatarProblem', 'false');
};
hiddenImg.src = Session.get('avatarURL');
}else{
$('#inputAvatar').css('background-image', 'url(\''+Session.get('avatarURL')+'\')');
Session.set('possibleGoogleAvatarProblem','false');
}
}

// template events related to #userInput
Expand All @@ -24,6 +48,11 @@ Template.userInput.events({
if(Meteor.userId()){

var $input = $('#inputtext');
var avurl = Session.get('avatarURL');

if(Session.get('possibleGoogleAvatarProblem') == 'true') {
avurl = 'default.png';
}

// prevent the default submission event
event.preventDefault();
Expand All @@ -33,7 +62,7 @@ Template.userInput.events({
body: $input.val(),
created: Date(),
owner: Meteor.userId(),
ownerAvatarUrl: Session.get('avatarURL'),
ownerAvatarUrl: avurl,
score:1,
weightedScore:1
});
Expand Down Expand Up @@ -66,6 +95,8 @@ Template.userInput.events({

// code to be run on dom changes
Deps.autorun(function(){

// if a user is logged in
if(Meteor.userId()){

Session.set('loggedIn','true');
Expand All @@ -76,8 +107,8 @@ Deps.autorun(function(){
avatarUrl = "https://graph.facebook.com/" + Meteor.user().services.facebook.id + "/picture?type=small";
Session.set('service','facebook');
} else if(Meteor.user().services.google) {
avatarUrl = "http://profiles.google.com/s2/photos/profile/" + Meteor.user().services.google.id + "?sz=" + "80";
Session.set('service','google');
avatarUrl = "http://profiles.google.com/s2/photos/profile/" + Meteor.user().services.google.id + "?sz=" + "80";
} else if(Meteor.user().services.twitter){
avatarUrl = "http://api.twitter.com/1/users/profile_image?screen_name=" + Meteor.user().services.twitter.screenName + "&size=bigger";
Session.set('service','twitter');
Expand All @@ -91,5 +122,8 @@ Deps.autorun(function(){
} else {
Session.set('avatarURL', 'none');
Session.set('service','none');
Session.set('loggedIn','false');
}
});
});

// code for checking if the google avatar is valid (google supplys none if the user has the default)
Binary file added public/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions stupid talk.css
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ position: relative;
width: 80px;
height: 80px;
border-radius: 40px;
-webkit-border-radius: 40px;
-webkit-border-radius: 40px ;
-moz-border-radius: 40px;
background-size: 100%;
margin-bottom:25px;
Expand All @@ -141,7 +141,7 @@ position: relative;
}

#remaining {
opacity:0.5;
opacity:0.8;
position:relative;
top: -52px;
left: 580px;
Expand Down
3 changes: 2 additions & 1 deletion stupid talk.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<head>
<title>stupid talk</title>
<link rel="shortcut icon" href="favicon.png" type="image/x-icon">
</head>

<body>
Expand All @@ -26,6 +27,7 @@
{{#if currentUser}}
{{> userInput}}
{{/if}}

<div class="bubbleRight"><p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam vel nunc Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam vel nunc libero, accumsan rutrum arcu. Donec gravida mollis imperdiet</p><div class ="avatarRight"></div></div>
<div><div class ="avatarLeft"><div class="bubbleLeft"><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam vel nunc Lorem ipsum dolor sit amet, k k</p></div></div></div>
</template>
Expand All @@ -34,7 +36,6 @@
<div>
<form id="userinput">
<div id ="inputAvatar">
{{avatar}}
<div class="bubbleLeft">
<input type="text" id="inputtext" maxlength="200" placeholder="So my friend just said something stupid....">
</div>
Expand Down

0 comments on commit 7f288df

Please sign in to comment.