fixed double or many click edit color and size
Showing
2 changed files
with
23 additions
and
10 deletions
@@ -10,6 +10,7 @@ var Stepper = require('./cart/stepper'); | @@ -10,6 +10,7 @@ var Stepper = require('./cart/stepper'); | ||
10 | 10 | ||
11 | $(function() { | 11 | $(function() { |
12 | var $this; | 12 | var $this; |
13 | + var editable = true; | ||
13 | 14 | ||
14 | // 关闭info-bar | 15 | // 关闭info-bar |
15 | $('.info-bar .close').on('click', function() { | 16 | $('.info-bar .close').on('click', function() { |
@@ -60,16 +61,25 @@ $(function() { | @@ -60,16 +61,25 @@ $(function() { | ||
60 | }).delegate('.editable', 'click', function() { | 61 | }).delegate('.editable', 'click', function() { |
61 | $this = $(this); | 62 | $this = $(this); |
62 | 63 | ||
63 | - // 编辑商品颜色和属性 | ||
64 | - Cart.editColorOrSize( | ||
65 | - $this.attr('data-productId'), | ||
66 | - $this.attr('data-productSkn'), | ||
67 | - $this.find('.default-color').text(), | ||
68 | - $this.find('.default-size').text()); | 64 | + if (editable) { |
65 | + editable = false; | ||
69 | 66 | ||
70 | - $('body').on('click', function() { | ||
71 | - $('.edit-color-size').remove(); | ||
72 | - }); | 67 | + // 编辑商品颜色和属性 |
68 | + Cart.editColorOrSize( | ||
69 | + $this.attr('data-productId'), | ||
70 | + $this.attr('data-productSkn'), | ||
71 | + $this.find('.default-color').text(), | ||
72 | + $this.find('.default-size').text(), function() { | ||
73 | + editable = true; | ||
74 | + }); | ||
75 | + | ||
76 | + $('body').off('click').on('click', function() { | ||
77 | + if ($('.edit-color-size').length) { | ||
78 | + $('.edit-color-size').remove(); | ||
79 | + editable = true; | ||
80 | + } | ||
81 | + }); | ||
82 | + } | ||
73 | }).delegate('#checkout_btn', 'click', function(e) { | 83 | }).delegate('#checkout_btn', 'click', function(e) { |
74 | e.preventDefault(); | 84 | e.preventDefault(); |
75 | if ($('.chk-group').length) { | 85 | if ($('.chk-group').length) { |
@@ -263,8 +263,9 @@ var Cart = { | @@ -263,8 +263,9 @@ var Cart = { | ||
263 | * @params { String } skn 商品skn | 263 | * @params { String } skn 商品skn |
264 | * @params { String } defaultColor 商品默认颜色 | 264 | * @params { String } defaultColor 商品默认颜色 |
265 | * @params { String } defaultSize 商品默认尺寸 | 265 | * @params { String } defaultSize 商品默认尺寸 |
266 | + * @params { Function } setEditable 编辑商品回调 | ||
266 | */ | 267 | */ |
267 | - editColorOrSize: function(productId, skn, defaultColor, defaultSize) { | 268 | + editColorOrSize: function(productId, skn, defaultColor, defaultSize, setEditable) { |
268 | var template; | 269 | var template; |
269 | var index = 0; | 270 | var index = 0; |
270 | var colors; | 271 | var colors; |
@@ -359,12 +360,14 @@ var Cart = { | @@ -359,12 +360,14 @@ var Cart = { | ||
359 | success: function(newCartData) { | 360 | success: function(newCartData) { |
360 | editTarget.find('.edit-color-size').remove(); | 361 | editTarget.find('.edit-color-size').remove(); |
361 | Util.refreshCart(newCartData); | 362 | Util.refreshCart(newCartData); |
363 | + setEditable(); | ||
362 | } | 364 | } |
363 | }); | 365 | }); |
364 | return false; | 366 | return false; |
365 | }).delegate('#cancel', 'click', function(e) { | 367 | }).delegate('#cancel', 'click', function(e) { |
366 | e.preventDefault(); | 368 | e.preventDefault(); |
367 | editTarget.find('.edit-color-size').remove(); | 369 | editTarget.find('.edit-color-size').remove(); |
370 | + setEditable(); | ||
368 | return false; | 371 | return false; |
369 | }).delegate('.edit-color-size', 'click', function(e) { | 372 | }).delegate('.edit-color-size', 'click', function(e) { |
370 | e.preventDefault(); | 373 | e.preventDefault(); |
-
Please register or login to post a comment