Skip to content
This repository
Browse code

update head img

  • Loading branch information...
commit 0aa0e575082cd6ee301ab7d9c30f8526d68b1c83 1 parent 7e4e900
Thomas Yang authored March 07, 2012
18  ROOT/js/application.js
@@ -141,7 +141,7 @@ function tagsInfoHTML(relativePath) {
141 141
 }
142 142
 
143 143
 function signinHTML(relativePath) {
144  
-    $.get(relativePath + '/me', function (data) {
  144
+    $.get(relativePath + '/me.json', function (data) {
145 145
         if (data['ok']) {
146 146
             var template = '<p class="navbar-text pull-right">Welcome, <a href="{0}/me" class="signin">{1}</a>&nbsp;<a href="{2}/user/logout" class="signin">Logout</a></p>';
147 147
             $("#signin").append($(String.format(template, relativePath, getShowUserName(data['data']), relativePath)));
@@ -159,10 +159,11 @@ function getShowUserName(data) {
159 159
     return showName;
160 160
 }
161 161
 
  162
+var gravatarUrl = "http://gravatar.com/avatar/{0}.png?s=48&d={1}";
162 163
 function getQuestions(relativePath, data) {
163 164
     var questionTemplate = '<tr>\
164 165
         <td class="questioner-img">\
165  
-        <img src="{{ relativePath }}/img/img.jpeg" alt="{{ questioner_name }}">\
  166
+        <img style="width:48px;height:48px;" src="{{ imgUrl }}" alt="{{ questionerName }}">\
166 167
         </td>\
167 168
         <td>\
168 169
         <p>{{ questioner_name }}&nbsp;(Question at&nbsp;{{ time }})</p>\
@@ -172,16 +173,21 @@ function getQuestions(relativePath, data) {
172 173
         </tr>';
173 174
     ich.addTemplate("question", questionTemplate);
174 175
     var questionInfo;
  176
+    var imgUrl;
175 177
     $.each(data, function (index, value) {
176 178
         questionInfo = {
177  
-            questioner_name : getShowUserName(value['user']),
  179
+            questionerName : getShowUserName(value['user']),
178 180
             time: value['createdAt'],
179 181
             id: value['id'],
180 182
             title: value['title'].escapeHTML(),
181  
-            tags: getTagsHTML(relativePath, value['tags']),
182  
-            relativePath: relativePath
  183
+            tags: getTagsHTML(relativePath, value['tags'])
183 184
         };
184  
-
  185
+        // if (value['user']['email']) {
  186
+            imgUrl = String.format(gravatarUrl, value['user']['email'], relativePath + "/img/img.jpeg");
  187
+        // } else {
  188
+            // imgUrl = relativePath + "/img/img.jpeg";
  189
+        // }
  190
+        questionInfo['imgUrl'] = imgUrl;
185 191
         $("#questions").append(ich.question(questionInfo));
186 192
     });
187 193
 }
6  ROOT/js/me.js
... ...
@@ -1,8 +1,7 @@
1 1
 $(function() {
2 2
     var relativePath = '.';
3 3
     loginHTML(relativePath);
4  
-    signinHTML(relativePath);
5  
-    $.get('./me', function (json) {
  4
+    $.get('./me.json', function (json) {
6 5
         if (console && console.log){
7 6
             console.log( 'Sample of data:', $.toJSON(json) );
8 7
         }
@@ -12,8 +11,11 @@ $(function() {
12 11
             $("#provider").val(data['provider']);
13 12
             $("#nickName").val(data['nickName']);
14 13
             $("#email").val(data['email']);
  14
+            var template = '<p class="navbar-text pull-right">Welcome, <a href="{0}/me" class="signin">{1}</a>&nbsp;<a href="{2}/user/logout" class="signin">Logout</a></p>';
  15
+            $("#signin").append($(String.format(template, relativePath, getShowUserName(data), relativePath)));
15 16
         } else {
16 17
             alert('Fail ' + data['msg']);
  18
+            $("#signin").append($('<p class="navbar-text pull-right"><a href="#signin" class="signin">signin</a></p>'));
17 19
         }
18 20
     }, 'json');
19 21
 

0 notes on commit 0aa0e57

Please sign in to comment.
Something went wrong with that request. Please try again.