Merge branch 'develop' of http://git.dev.yoho.cn/web/yohobuy into develop
Showing
1 changed file
with
57 additions
and
64 deletions
@@ -6,80 +6,73 @@ | @@ -6,80 +6,73 @@ | ||
6 | 6 | ||
7 | 7 | ||
8 | var $ = require('jquery'), | 8 | var $ = require('jquery'), |
9 | - Hammer = require('yoho.hammer'), | ||
10 | - tip = require('../../plugin/tip'), | ||
11 | - chosePanel = require('../../cart/chose-panel'); | 9 | + tip = require('../../plugin/tip'), |
10 | + chosePanel = require('../../cart/chose-panel'); | ||
12 | 11 | ||
13 | -var likeEle = document.getElementById('likeBtn'), | ||
14 | - likeHammer = likeEle && new Hammer(likeEle); | 12 | +var productId = $('#productId').val(); |
15 | 13 | ||
16 | -var addToCartEle = document.getElementById('addtoCart'), | ||
17 | - addToCartHammer = addToCartEle && new Hammer(addToCartEle), | ||
18 | - productId = $('#productId').val(); | 14 | +$('#likeBtn').on('click', function() { |
15 | + var opt, | ||
16 | + favorite; | ||
19 | 17 | ||
20 | -if (likeHammer) { | ||
21 | - likeHammer.on('tap', function(e) { | ||
22 | - var opt, | ||
23 | - favorite; | 18 | + var $this = $(this); |
24 | 19 | ||
25 | - var $this = $(e.target); | 20 | + if ($this.hasClass('liked')) { |
21 | + opt = 'cancel'; | ||
22 | + favorite = 0; | ||
23 | + } else { | ||
24 | + opt = 'ok'; | ||
25 | + favorite = 1; | ||
26 | + } | ||
26 | 27 | ||
27 | - if ($this.hasClass('liked')) { | ||
28 | - opt = 'cancel'; | ||
29 | - favorite = 0; | ||
30 | - } else { | ||
31 | - opt = 'ok'; | ||
32 | - favorite = 1; | ||
33 | - } | ||
34 | - | ||
35 | - $.ajax({ | ||
36 | - type: 'POST', | ||
37 | - url: '/product/opt/favoriteProduct', | ||
38 | - data: { | ||
39 | - id: productId, | ||
40 | - opt: opt | ||
41 | - }, | ||
42 | - success: function(data) { | ||
43 | - if (data.code === 200) { | ||
44 | - $this.toggleClass('liked'); | 28 | + $.ajax({ |
29 | + type: 'POST', | ||
30 | + url: '/product/opt/favoriteProduct', | ||
31 | + data: { | ||
32 | + id: productId, | ||
33 | + opt: opt | ||
34 | + }, | ||
35 | + success: function(data) { | ||
36 | + if (data.code === 200) { | ||
37 | + $this.toggleClass('liked'); | ||
45 | 38 | ||
46 | - if ('cancel' === opt) { | ||
47 | - tip.show('取消收藏成功'); | ||
48 | - } else if ('ok' === opt) { | ||
49 | - tip.show('收藏成功'); | ||
50 | - } | ||
51 | - } else if (data.code === 400) { | ||
52 | - location.href = data.data;//未登录跳转登录页 | ||
53 | - } else { | ||
54 | - tip.show(data.message); | 39 | + if ('cancel' === opt) { |
40 | + tip.show('取消收藏成功'); | ||
41 | + } else if ('ok' === opt) { | ||
42 | + tip.show('收藏成功'); | ||
55 | } | 43 | } |
56 | - }, | ||
57 | - error: function() { | ||
58 | - tip.show('网络断开连接了~'); | 44 | + } else if (data.code === 400) { |
45 | + location.href = data.data;//未登录跳转登录页 | ||
46 | + } else { | ||
47 | + tip.show(data.message); | ||
59 | } | 48 | } |
60 | - }); | ||
61 | - | ||
62 | - // 统计代码:用于统计用户加入或取消商品收藏的动作 | ||
63 | - if (window._yas) { | ||
64 | - window._yas.sendCustomInfo({ | ||
65 | - pd: productId, | ||
66 | - fa: favorite | ||
67 | - }, true); | 49 | + }, |
50 | + error: function() { | ||
51 | + tip.show('网络断开连接了~'); | ||
68 | } | 52 | } |
69 | }); | 53 | }); |
70 | -} | ||
71 | 54 | ||
72 | -if (addToCartHammer) { | ||
73 | - addToCartHammer.on('tap', function(e) { | ||
74 | - chosePanel.show(); | 55 | + // 统计代码:用于统计用户加入或取消商品收藏的动作 |
56 | + if (window._yas) { | ||
57 | + window._yas.sendCustomInfo({ | ||
58 | + pd: productId, | ||
59 | + fa: favorite | ||
60 | + }, true); | ||
61 | + } | ||
75 | 62 | ||
76 | - //统计代码:用于统计用户加入购物车的动作 | ||
77 | - if (window._yas) { | ||
78 | - window._yas.sendCustomInfo({ | ||
79 | - pd: productId, | ||
80 | - by: 1 | ||
81 | - }, true); | ||
82 | - } | 63 | + return false; |
64 | +}); | ||
83 | 65 | ||
84 | - }); | ||
85 | -} | 66 | +$('#addtoCart').on('click', function() { |
67 | + chosePanel.show(); | ||
68 | + | ||
69 | + //统计代码:用于统计用户加入购物车的动作 | ||
70 | + if (window._yas) { | ||
71 | + window._yas.sendCustomInfo({ | ||
72 | + pd: productId, | ||
73 | + by: 1 | ||
74 | + }, true); | ||
75 | + } | ||
76 | + | ||
77 | + return false; | ||
78 | +}); |
-
Please register or login to post a comment