Authored by xuqi

common server & passport status

... ... @@ -5,11 +5,97 @@
*/
var $ = require('yoho.zepto');
var $footer = $('#yoho-footer');
function cookie(name) {
var cookies = document.cookie,
cookieVal,
offset;
//页面通用底部位置及status设置
if ($('body').height() < $(window).height()) {
$footer.addClass('bottom');
if (document.cookie && document.cookie !== '') {
offset = cookies.indexOf(name + '=');
if (offset > -1) {
offset += name.length + 1;
cookieVal = decodeURIComponent($.trim(cookies.substring(offset, cookies.indexOf(';', offset))));
}
}
return cookieVal;
}
function getUser() {
var c = cookie('_UID'),
user;
if (typeof c === 'undefined') {
return 0;
}
user = c.split('::');
if (typeof user === 'undefined' || user.length < 4) {
return 0;
}
return user;
}
function getUid() {
var user = getUser();
if (user === 0) {
return 0;
}
return user[1];
}
function getShoppingKey() {
var c = cookie('_g');
if (typeof c === 'undefined') {
return '';
}
return JSON.parse(c).k;
}
$footer.removeClass('hide');
\ No newline at end of file
//页面通用底部位置及status设置
(function() {
var $footer = $('#yoho-footer'),
$op = $footer.children('.op-row');
var user = getUser();
if ($('body').height() < $(window).height()) {
$footer.addClass('bottom');
}
if (user === 0) {
//未登录
$op.prepend(
'<a href="http://m.yohobuy.com/signin.html">登录</a>' +
'<span class="sep-line">|</span>' +
'<a href="http://m.yohobuy.com/reg.html">注册</a>'
);
} else {
//已登录
$op.prepend(
'Hi,' +
'<a class="user-name" href="http://m.yohobuy.com/home?tmp=' + Math.random() + '">' + user[0] + '</a>' +
'<a href="http://m.yohobuy.com/passport/signout/index?token=' + user[3] + '">退出</a>'
);
}
$footer.removeClass('hide');
}());
//暴露公共接口
window.cookie = cookie;
window.getUser = getUser;
window.getUid = getUid;
window.getShoppingKey = getShoppingKey;
\ No newline at end of file
... ...
... ... @@ -10,12 +10,18 @@
.user-name {
text-decoration: underline;
margin-left: .3em;
margin-right: 1em;
}
.back-to-top {
position: absolute;
right: 20px;
}
.sep-line {
margin: 0 0.3em;
}
}
.copyright {
... ...
{{#pageFooter}}
<footer id="yoho-footer" class="yoho-footer hide">
<p class="op-row">
{{# user}}
Hi,
<a class="user-name" href="{{url}}">{{name}}</a>
<a href="{{signoutUrl}}">退出</a>
{{^}}
<a href="{{loginUrl}}">登录</a>
<span class="sep-line">|</span>
<a href="{{signupUrl}}">注册</a>
{{/ user}}
<span class="back-to-top">
Back to top
<i class="iconfont">&#xe608;</i>
... ...