|
@@ -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; |