Authored by xuqi

common server & passport status

@@ -5,11 +5,97 @@ @@ -5,11 +5,97 @@
5 */ 5 */
6 var $ = require('yoho.zepto'); 6 var $ = require('yoho.zepto');
7 7
8 -var $footer = $('#yoho-footer'); 8 +function cookie(name) {
  9 + var cookies = document.cookie,
  10 + cookieVal,
  11 + offset;
9 12
10 -//页面通用底部位置及status设置  
11 -if ($('body').height() < $(window).height()) {  
12 - $footer.addClass('bottom'); 13 + if (document.cookie && document.cookie !== '') {
  14 + offset = cookies.indexOf(name + '=');
  15 + if (offset > -1) {
  16 + offset += name.length + 1;
  17 +
  18 + cookieVal = decodeURIComponent($.trim(cookies.substring(offset, cookies.indexOf(';', offset))));
  19 + }
  20 + }
  21 +
  22 + return cookieVal;
  23 +}
  24 +
  25 +function getUser() {
  26 + var c = cookie('_UID'),
  27 + user;
  28 +
  29 + if (typeof c === 'undefined') {
  30 + return 0;
  31 + }
  32 +
  33 + user = c.split('::');
  34 +
  35 + if (typeof user === 'undefined' || user.length < 4) {
  36 + return 0;
  37 + }
  38 +
  39 + return user;
  40 +}
  41 +
  42 +function getUid() {
  43 + var user = getUser();
  44 +
  45 + if (user === 0) {
  46 + return 0;
  47 + }
  48 +
  49 + return user[1];
  50 +}
  51 +
  52 +function getShoppingKey() {
  53 + var c = cookie('_g');
  54 +
  55 + if (typeof c === 'undefined') {
  56 + return '';
  57 + }
  58 +
  59 + return JSON.parse(c).k;
13 } 60 }
14 61
15 -$footer.removeClass('hide');  
  62 +//页面通用底部位置及status设置
  63 +(function() {
  64 + var $footer = $('#yoho-footer'),
  65 + $op = $footer.children('.op-row');
  66 +
  67 + var user = getUser();
  68 +
  69 + if ($('body').height() < $(window).height()) {
  70 + $footer.addClass('bottom');
  71 + }
  72 +
  73 + if (user === 0) {
  74 +
  75 + //未登录
  76 + $op.prepend(
  77 + '<a href="http://m.yohobuy.com/signin.html">登录</a>' +
  78 + '<span class="sep-line">|</span>' +
  79 + '<a href="http://m.yohobuy.com/reg.html">注册</a>'
  80 + );
  81 + } else {
  82 +
  83 + //已登录
  84 + $op.prepend(
  85 + 'Hi,' +
  86 + '<a class="user-name" href="http://m.yohobuy.com/home?tmp=' + Math.random() + '">' + user[0] + '</a>' +
  87 + '<a href="http://m.yohobuy.com/passport/signout/index?token=' + user[3] + '">退出</a>'
  88 + );
  89 + }
  90 +
  91 + $footer.removeClass('hide');
  92 +}());
  93 +
  94 +//暴露公共接口
  95 +window.cookie = cookie;
  96 +
  97 +window.getUser = getUser;
  98 +
  99 +window.getUid = getUid;
  100 +
  101 +window.getShoppingKey = getShoppingKey;
@@ -10,12 +10,18 @@ @@ -10,12 +10,18 @@
10 10
11 .user-name { 11 .user-name {
12 text-decoration: underline; 12 text-decoration: underline;
  13 + margin-left: .3em;
  14 + margin-right: 1em;
13 } 15 }
14 16
15 .back-to-top { 17 .back-to-top {
16 position: absolute; 18 position: absolute;
17 right: 20px; 19 right: 20px;
18 } 20 }
  21 +
  22 + .sep-line {
  23 + margin: 0 0.3em;
  24 + }
19 } 25 }
20 26
21 .copyright { 27 .copyright {
1 {{#pageFooter}} 1 {{#pageFooter}}
2 <footer id="yoho-footer" class="yoho-footer hide"> 2 <footer id="yoho-footer" class="yoho-footer hide">
3 <p class="op-row"> 3 <p class="op-row">
4 - {{# user}}  
5 - Hi,  
6 - <a class="user-name" href="{{url}}">{{name}}</a>  
7 - <a href="{{signoutUrl}}">退出</a>  
8 - {{^}}  
9 - <a href="{{loginUrl}}">登录</a>  
10 - <span class="sep-line">|</span>  
11 - <a href="{{signupUrl}}">注册</a>  
12 - {{/ user}}  
13 <span class="back-to-top"> 4 <span class="back-to-top">
14 Back to top 5 Back to top
15 <i class="iconfont">&#xe608;</i> 6 <i class="iconfont">&#xe608;</i>