Showing
6 changed files
with
134 additions
and
88 deletions
@@ -12,6 +12,7 @@ | @@ -12,6 +12,7 @@ | ||
12 | {{{body}}} | 12 | {{{body}}} |
13 | </div> | 13 | </div> |
14 | <div id="login-tip" class="login-tip">未登录</div> | 14 | <div id="login-tip" class="login-tip">未登录</div> |
15 | + <input id="is-login" type="hidden" value="{{isLogin}}"> | ||
15 | </body> | 16 | </body> |
16 | {{> footer}} | 17 | {{> footer}} |
17 | </html> | 18 | </html> |
@@ -19,6 +19,8 @@ exports.init = function() { | @@ -19,6 +19,8 @@ exports.init = function() { | ||
19 | var $intro = $('#intro'), | 19 | var $intro = $('#intro'), |
20 | winH = $(window).height(), | 20 | winH = $(window).height(), |
21 | tpl; | 21 | tpl; |
22 | + var isLogin = $('#is-login').val(); | ||
23 | + isLogin = isLogin ? isLogin : 'N'; | ||
22 | //登录提示变量 | 24 | //登录提示变量 |
23 | var $loginTip = $('#login-tip'), | 25 | var $loginTip = $('#login-tip'), |
24 | winW, | 26 | winW, |
@@ -71,29 +73,38 @@ exports.init = function() { | @@ -71,29 +73,38 @@ exports.init = function() { | ||
71 | 73 | ||
72 | //绑定商品信息的收藏和取消收藏事件(相关推荐和搭配模块) | 74 | //绑定商品信息的收藏和取消收藏事件(相关推荐和搭配模块) |
73 | $('.new-arrival-content').delegate('.good-islike', 'touchstart', function(e) { | 75 | $('.new-arrival-content').delegate('.good-islike', 'touchstart', function(e) { |
74 | - var $cur = $(e.currentTarget), | ||
75 | - $good = $cur.closest('.good-info'), | 76 | + var $cur, |
77 | + $good, | ||
78 | + id; | ||
79 | + if (isLogin === 'N') { | ||
80 | + $cur = $(e.currentTarget); | ||
81 | + $good = $cur.closest('.good-info'); | ||
76 | id = $good.data('id'); | 82 | id = $good.data('id'); |
77 | - | ||
78 | - $.ajax({ | ||
79 | - type: 'GET', | ||
80 | - url: '/favorite/product', | ||
81 | - data: { | ||
82 | - st: 0, | ||
83 | - product_skn: id | ||
84 | - } | ||
85 | - }).then(function(data) { | ||
86 | - if (data.code === 200) { | ||
87 | - $cur.toggleClass('good-like'); | ||
88 | - } else if (data.code === 400) { | ||
89 | - //提示登录信息 | ||
90 | - $('#login-tip').fadeIn(500, function() { | ||
91 | - setTimeout(function() { | ||
92 | - $('#login-tip').fadeOut(500); | ||
93 | - }, 1000); | ||
94 | - }); | ||
95 | - } | ||
96 | - }); | 83 | + |
84 | + $.ajax({ | ||
85 | + type: 'GET', | ||
86 | + url: '/favorite/product', | ||
87 | + data: { | ||
88 | + st: 0, | ||
89 | + product_skn: id | ||
90 | + } | ||
91 | + }).then(function(data) { | ||
92 | + if (data.code === 200) { | ||
93 | + $cur.toggleClass('good-like'); | ||
94 | + } else if (data.code === 400) { | ||
95 | + //提示登录信息 | ||
96 | + $('#login-tip').fadeIn(500, function() { | ||
97 | + setTimeout(function() { | ||
98 | + $('#login-tip').fadeOut(500); | ||
99 | + }, 1000); | ||
100 | + }); | ||
101 | + } | ||
102 | + }); | ||
103 | + } | ||
104 | + }).delegate('.good-islike', 'click', function(e) { | ||
105 | + if (isLogin === 'N') { | ||
106 | + e.preventDefault(); | ||
107 | + } | ||
97 | }); | 108 | }); |
98 | 109 | ||
99 | //文章点赞 | 110 | //文章点赞 |
@@ -129,27 +140,37 @@ exports.init = function() { | @@ -129,27 +140,37 @@ exports.init = function() { | ||
129 | }); | 140 | }); |
130 | }); | 141 | }); |
131 | 142 | ||
132 | - $('#brand-like').bind('touchstart', function() { | ||
133 | - var $cur = $(this), | 143 | + $('#brand-like').bind('touchstart', function(e) { |
144 | + var $cur, | ||
145 | + id; | ||
146 | + if (isLogin === 'N') { | ||
147 | + $cur = $(this); | ||
134 | id = $(this).closest('.brand-info').data('id'); | 148 | id = $(this).closest('.brand-info').data('id'); |
135 | - | ||
136 | - $.ajax({ | ||
137 | - type: 'GET', | ||
138 | - url: '/favorite/brand', | ||
139 | - data: { | ||
140 | - brand_id: id | ||
141 | - } | ||
142 | - }).then(function(data) { | ||
143 | - if (data.code === 200) { | ||
144 | - $cur.toggleClass('like'); | ||
145 | - } else if (data.code === 400) { | ||
146 | - $('#login-tip').fadeIn(500, function() { | ||
147 | - setTimeout(function() { | ||
148 | - $('#login-tip').fadeOut(500); | ||
149 | - }, 1000); | ||
150 | - }); | ||
151 | - } | ||
152 | - }); | 149 | + |
150 | + // | ||
151 | + $.ajax({ | ||
152 | + type: 'GET', | ||
153 | + url: '/favorite/brand', | ||
154 | + data: { | ||
155 | + brand_id: id | ||
156 | + } | ||
157 | + }).then(function(data) { | ||
158 | + if (data.code === 200) { | ||
159 | + $cur.toggleClass('like'); | ||
160 | + } else if (data.code === 400) { | ||
161 | + $('#login-tip').fadeIn(500, function() { | ||
162 | + setTimeout(function() { | ||
163 | + $('#login-tip').fadeOut(500); | ||
164 | + }, 1000); | ||
165 | + }); | ||
166 | + } | ||
167 | + }); | ||
168 | + } | ||
169 | + }).bind('click', function(e) { | ||
170 | + if (isLogin === 'N') { | ||
171 | + //阻止链接跳转 | ||
172 | + e.preventDefault(); | ||
173 | + } | ||
153 | }); | 174 | }); |
154 | }); | 175 | }); |
155 | }; | 176 | }; |
@@ -21,6 +21,9 @@ exports.init = function() { | @@ -21,6 +21,9 @@ exports.init = function() { | ||
21 | tipH, | 21 | tipH, |
22 | tipW; | 22 | tipW; |
23 | 23 | ||
24 | + var isLogin = $('#is-login').val(); | ||
25 | + isLogin = isLogin ? isLogin : 'N'; | ||
26 | + | ||
24 | //头部作者信息样式计算(在描述信息过长时换行显示, 去除intro的padding-top) | 27 | //头部作者信息样式计算(在描述信息过长时换行显示, 去除intro的padding-top) |
25 | var $linkC = $('#link-container'), | 28 | var $linkC = $('#link-container'), |
26 | $avatar = $linkC.find('.avatar'), | 29 | $avatar = $linkC.find('.avatar'), |
@@ -56,29 +59,38 @@ exports.init = function() { | @@ -56,29 +59,38 @@ exports.init = function() { | ||
56 | 59 | ||
57 | //绑定商品信息的收藏和取消收藏事件(相关推荐和搭配模块) | 60 | //绑定商品信息的收藏和取消收藏事件(相关推荐和搭配模块) |
58 | $('.good-list, .prod-list').delegate('.good-islike', 'touchstart', function(e) { | 61 | $('.good-list, .prod-list').delegate('.good-islike', 'touchstart', function(e) { |
59 | - var $cur = $(e.currentTarget), | ||
60 | - $good = $cur.closest('.good-info'), | 62 | + var $cur, |
63 | + $good, | ||
64 | + id; | ||
65 | + if (isLogin === 'N') { | ||
66 | + $cur = $(e.currentTarget); | ||
67 | + $good = $cur.closest('.good-info'); | ||
61 | id = $good.data('id'); | 68 | id = $good.data('id'); |
62 | - | ||
63 | - $.ajax({ | ||
64 | - type: 'GET', | ||
65 | - url: '/favorite/product', | ||
66 | - data: { | ||
67 | - st: 1, | ||
68 | - product_skn: id | ||
69 | - } | ||
70 | - }).then(function(data) { | ||
71 | - if (data.code === 200) { | ||
72 | - $cur.toggleClass('good-like'); | ||
73 | - } else if (data.code === 400) { | ||
74 | - //提示登录信息 | ||
75 | - $('#login-tip').fadeIn(500, function() { | ||
76 | - setTimeout(function() { | ||
77 | - $('#login-tip').fadeOut(500); | ||
78 | - }, 1000); | ||
79 | - }); | ||
80 | - } | ||
81 | - }); | 69 | + |
70 | + $.ajax({ | ||
71 | + type: 'GET', | ||
72 | + url: '/favorite/product', | ||
73 | + data: { | ||
74 | + st: 1, | ||
75 | + product_skn: id | ||
76 | + } | ||
77 | + }).then(function(data) { | ||
78 | + if (data.code === 200) { | ||
79 | + $cur.toggleClass('good-like'); | ||
80 | + } else if (data.code === 400) { | ||
81 | + //提示登录信息 | ||
82 | + $('#login-tip').fadeIn(500, function() { | ||
83 | + setTimeout(function() { | ||
84 | + $('#login-tip').fadeOut(500); | ||
85 | + }, 1000); | ||
86 | + }); | ||
87 | + } | ||
88 | + }); | ||
89 | + } | ||
90 | + }).delegate('.good-islike', 'click', function(e) { | ||
91 | + if (isLogin === 'N') { | ||
92 | + e.preventDefault(); | ||
93 | + } | ||
82 | }); | 94 | }); |
83 | }); | 95 | }); |
84 | }; | 96 | }; |
@@ -24,7 +24,10 @@ exports.init = function() { | @@ -24,7 +24,10 @@ exports.init = function() { | ||
24 | $svc = $goodList.filter('.sales-volume-container'), | 24 | $svc = $goodList.filter('.sales-volume-container'), |
25 | $pc = $goodList.filter('.price-container'), | 25 | $pc = $goodList.filter('.price-container'), |
26 | tpl; //商品信息模板 | 26 | tpl; //商品信息模板 |
27 | - | 27 | + |
28 | + var isLogin = $('#is-login').val(); | ||
29 | + isLogin = isLogin ? isLogin : 'N'; | ||
30 | + | ||
28 | //筛选相关变量 | 31 | //筛选相关变量 |
29 | var curFilter = { | 32 | var curFilter = { |
30 | brand: '', | 33 | brand: '', |
@@ -400,28 +403,37 @@ exports.init = function() { | @@ -400,28 +403,37 @@ exports.init = function() { | ||
400 | 403 | ||
401 | //Like | 404 | //Like |
402 | $('#goods-content').delegate('.good-islike', 'touchstart', function(e) { | 405 | $('#goods-content').delegate('.good-islike', 'touchstart', function(e) { |
403 | - var $cur = $(e.currentTarget), | ||
404 | - $good = $cur.closest('.good-info'), | 406 | + var $cur, |
407 | + $good, | ||
408 | + id; | ||
409 | + if (isLogin === 'N') { | ||
410 | + $cur = $(e.currentTarget); | ||
411 | + $good = $cur.closest('.good-info'); | ||
405 | id = $good.data('id'); | 412 | id = $good.data('id'); |
406 | - | ||
407 | - $.ajax({ | ||
408 | - type: 'GET', | ||
409 | - url: '/favorite/product', | ||
410 | - data: { | ||
411 | - product_skn: id | ||
412 | - } | ||
413 | - }).then(function(data) { | ||
414 | - if (data.code === 200) { | ||
415 | - $cur.toggleClass('good-like'); | ||
416 | - } else if (data.code === 400) { | ||
417 | - //提示登录信息 | ||
418 | - $('#login-tip').fadeIn(500, function() { | ||
419 | - setTimeout(function() { | ||
420 | - $('#login-tip').fadeOut(500); | ||
421 | - }, 1000); | ||
422 | - }); | ||
423 | - } | ||
424 | - }); | 413 | + |
414 | + $.ajax({ | ||
415 | + type: 'GET', | ||
416 | + url: '/favorite/product', | ||
417 | + data: { | ||
418 | + product_skn: id | ||
419 | + } | ||
420 | + }).then(function(data) { | ||
421 | + if (data.code === 200) { | ||
422 | + $cur.toggleClass('good-like'); | ||
423 | + } else if (data.code === 400) { | ||
424 | + //提示登录信息 | ||
425 | + $('#login-tip').fadeIn(500, function() { | ||
426 | + setTimeout(function() { | ||
427 | + $('#login-tip').fadeOut(500); | ||
428 | + }, 1000); | ||
429 | + }); | ||
430 | + } | ||
431 | + }); | ||
432 | + } | ||
433 | + }).delegate('.good-islike', 'click', function(e) { | ||
434 | + if (isLogin === 'N') { | ||
435 | + e.preventDefault(); | ||
436 | + } | ||
425 | }); | 437 | }); |
426 | }); | 438 | }); |
427 | }; | 439 | }; |
@@ -6,7 +6,7 @@ | @@ -6,7 +6,7 @@ | ||
6 | <div class="header-content"> | 6 | <div class="header-content"> |
7 | <p class="name-islike-container"> | 7 | <p class="name-islike-container"> |
8 | <span class="name">{{name}}</span> | 8 | <span class="name">{{name}}</span> |
9 | - <a id="brand-like" class="brand-islike iconfont {{# isLike}}like{{/ isLike}}" href="javascript:void(0)"> | 9 | + <a id="brand-like" class="brand-islike iconfont {{# isLike}}like{{/ isLike}}" href="{{likeUrl}}"> |
10 |  | 10 |  |
11 | </a> | 11 | </a> |
12 | </p> | 12 | </p> |
1 | <div class="good-info" data-id="{{id}}"> | 1 | <div class="good-info" data-id="{{id}}"> |
2 | <div class="good-detail-img"> | 2 | <div class="good-detail-img"> |
3 | - <a class="good-islike {{# isLike}}good-like{{/ isLike}} iconfont" href="javascript:;"></a> | 3 | + <a class="good-islike {{# isLike}}good-like{{/ isLike}} iconfont" href="{{likeUrl}}"></a> |
4 | <a class="good-thumb" href="{{url}}"> | 4 | <a class="good-thumb" href="{{url}}"> |
5 | <img class="lazy" data-original="{{thumb}}"> | 5 | <img class="lazy" data-original="{{thumb}}"> |
6 | </a> | 6 | </a> |
-
Please register or login to post a comment