-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
122 lines (89 loc) · 3.75 KB
/
index.js
File metadata and controls
122 lines (89 loc) · 3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
$(document).ready(function() {
$('.tellMore').on('click', function() {
$(this).siblings('.moreInfo').toggle();
$(this).text(function(i, text){
return text === "Tell me more" ? "See Less" : "Tell me more";
});
});
$('.add').on('click', function() {
var quantityId = $(this).parent('div').attr('id');
var cartId = "cart_"+quantityId;
var cartTotal = $("#cartTotal").data('cartTotal') || 0;
var addCount = $('#cart').find('#'+cartId).find('.quantity').data('addCount') || 0;
var itemPrice = $(this).parent('div').data('price');
if (addCount < 1) {
$(this).siblings('.moreInfo').hide();
$(this).parent().clone().appendTo('#cart').prop({ id: (cartId)});
}
$('#cart').find('#'+cartId).find('.removeFromCart').show();
addCount += 1;
// $(this).siblings('.quantity').data('addCount', addCount);
// $(this).siblings('.quantity').text('Quantity: ' + addCount);
$(this).siblings('.quantity').show();
$('#cart').find('#'+cartId).find('.quantity').data('addCount', addCount);
$('#cart').find('#'+cartId).find('.quantity').text('Quantity: ' + addCount);
cartTotal += itemPrice;
$("#cartTotal").data('cartTotal', cartTotal);
$("#cartTotal").text('$' + cartTotal.toFixed(2));
if (cartTotal > 0) {
$('#cartImage').show();
$('#cartImageText').show();
}
});
$(document).on('click', '.removeFromCart', function() {
var cartTotalEl = $("#cartTotal")
var quantityEl = $(this).siblings('.quantity')
var cartTotal = cartTotalEl.data('cartTotal') || 0;
var addCount = quantityEl.data('addCount') || 0;
var itemPrice = $(this).parent('div').data('price');
addCount -= 1;
cartTotal -= itemPrice;
if (addCount < 1) {
$(this).parent('div').remove();
// $(this).parent().clone().appendTo('#cart').prop({ id: (cartId)});
// $('#cart').find('#'+cartId).find('.removeFromCart').show();
}
quantityEl.data('addCount', addCount);
quantityEl.text('Quantity: ' + addCount);
cartTotalEl.data('cartTotal', cartTotal);
cartTotalEl.text('$' + cartTotal.toFixed(2));
$("#cartTotal").data('cartTotal', cartTotal);
if (cartTotal < 1) {
$('#cartImage').hide();
$('#cartImageText').hide();
}
});
$('#checkout').on('click', function() {
// var confirmPage = document.createElement('div');
// confirmPage.id = 'confirmPage';
var cartTotal = $("#cartTotal").data('cartTotal') || 0;
var confirmYesButton = document.createElement('button');
var confirmNoButton = document.createElement('button');
confirmYesButton.textContent = 'Confirm Purchase';
confirmYesButton.id = 'confirm';
confirmNoButton.textContent = 'Cancel Purchase';
confirmNoButton.id = 'cancel';
document.getElementById('overlay').innerHTML = '<h1 id="c" style="margin-top:50px;text-align:center;">Thank you for shopping!, ' +
'your total is: $'+ cartTotal.toFixed(2) + '<br><br>' +
'<img src="http://gifs.gifbin.com/280sw007883.gif" width="500px" />';
$('#overlay').show('slow');
// document.getElementById('overlay').appendChild(confirmPage);
document.getElementById('overlay').appendChild(confirmNoButton);
document.getElementById('overlay').appendChild(confirmYesButton);
});
$(document).on('click', '#cancel', function() {
$('#overlay').hide('slow');
});
//$('product').on('hover', function() {});
$('div.featured').find('.price').append(function() {
var price = $(this).parent().data('price');
price *= 0.9;
$(this).data('price', price);
return '<div class="new-price">New Price: $'+ price.toFixed(2) + '</div>';
});
function toggleRotate() {
$("#left_pin").toggleClass("rotate");
$("#right_pin").toggleClass("neg_rotate");
}
setInterval(toggleRotate, 500);
});