fgcslider.js
13.4 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
function preSlider(a) {
productBoxWidth = 220, productBoxHeight = 140;
var b = jQuery(".fgc-slider");
if (totalProduct = b.find(".slide-frame").length, b.find(".slide-frame").addClass("add_to_cart_button").addClass("ajax_add_to_cart"), $isMobile || $isDesktop ? numProduct = 4 : (numProduct = 3, jQuery(".outbox-slider").css("width", "auto")), totalProduct = b.find(".slide-frame").length, a) {
var c = jQuery("ul.products");
if (totalProduct = c.find("li").length, $isMobile)
for (j = totalProduct + 1; j > 0; j--) moveToSlider(j);
else
for (j = 1; j < totalProduct + 1; j++) moveToSlider(j);
jQuery(".slide-frame").addClass("ajax_add_to_cart")
}
for (i = 1; i < numProduct + 1; i++);
b.find(".popular").parent().addClass("popular-product"), b.find(".slide-frame").each(function() {
jQuery(this).hasClass("popular-product") && jQuery(this).find("h3").before('<span class="popular">MOST POPULAR</span>')
})
}
function moveSlider(a, b, c, d, e) {
var f = jQuery(".fgc-slider");
if (!$isMobile) {
if ("-10px" === f.css("left") && "pre" === a) return;
if ("-2230px" === f.css("left") && "next" === a) return
}
}
function moveNext(a, b, c, d) {
moveSlider("next", a, b, c, d)
}
function movePre(a, b, c, d) {
moveSlider("pre", a, b, c, d)
}
function moveToSlider(a) {
if (jQuery(".products").length > 0) {
var b = jQuery(".fgc-slider .fgc_slider_products"),
c = jQuery("ul.products");
thisLi = c.find("li:nth-child(" + a + ")"), toMove = thisLi.find("a .price").parent(), toMove.addClass("slide-frame"), priceHtml = toMove.find(".amount").text().replace(".00", "").replace(".99", "<small>.99</small>"), toMove.find(".short-description").after('<input type="hidden" value="' + toMove.find(".amount").text().replace("jQuery", "") + '" class="price-value" />'), toMove.find(".price").html(priceHtml), thisLi.hasClass("pa_popular") && toMove.find("h3").before('<span class="popular"></span>'), toMove.attr("href", String(thisLi.find(".add_to_cart_button").attr("href"))), toMove.attr("data-product_id", String(thisLi.find(".add_to_cart_button").attr("data-product_id"))), b.append(toMove)
}
}
function setWidthSlider(a, b, c) {
var d = jQuery(".fgc-slider");
if (totalSlide = d.find(".slide-frame").length, sizeSlider = 0, $isMobile)
for (d.find(".slide-frame").each(function() {
sizeSlider += jQuery(this).outerHeight() + 20
}), d.css("height", sizeSlider + "px"), thisTop = 0, i = 1; i < a + 1; i++) thisTop += d.find(".slide-frame:nth-child(" + i + ")").outerHeight() + 20;
else d.find(".slide-frame").each(function() {
sizeSlider += jQuery(this).outerWidth() + 20
}), d.css("width", sizeSlider + "px"), fgcBoxSlider = (d.find(".slide-frame:first-child").outerWidth() + 20) * a, leftBoxSlider = (jQuery(".outbox-slider").width() - fgcBoxSlider) / 2, jQuery(".fgc-box-slider").css("width", fgcBoxSlider + "px"), thisLeft = (d.find(".slide-frame:first-child").outerWidth() + 20) * a
}
function setAuto(a, b, c) {
return setInterval(function() {
moveNext(a, b, c)
}, 5e3)
}
function getTotalFrameAndPositionFrames() {
return totalFrame = 0, leftFrameArray = [], $isMobile ? (leftFirstFrame = -20, jQuery(".outbox-slider[slider='1'] .slide-frame").each(function() {
leftFrameArray.push(leftFirstFrame + "px"), leftFirstFrame -= jQuery(this).outerHeight(), leftFirstFrame -= 20, totalFrame++
})) : (leftFirstFrame = -10, jQuery(".outbox-slider[slider='1'] .slide-frame").each(function() {
leftFrameArray.push(leftFirstFrame + "px"), leftFirstFrame -= jQuery(this).outerWidth(), leftFirstFrame -= 20, totalFrame++
})), {
totalFrame: totalFrame,
leftFrameArray: leftFrameArray
}
}
function clickNextButton(a, b, c, d) {
jQuery(".next-button").hasClass("disabled") || (jQuery(".next-button").addClass("disabled"), $isMobile ? (indexFrame = a.indexOf(c.css("top")), nextIndex = indexFrame, 0 !== indexFrame && (indexFrame < numProduct ? nextIndex = 0 : nextIndex = indexFrame - numProduct), jQuery(".fgc-slider").animate({
top: a[nextIndex]
}, d, function() {
jQuery(".next-button").removeClass("disabled")
})) : (indexFrame = a.indexOf(c.css("left")), nextIndex = indexFrame, b - indexFrame < 2 * numProduct ? nextIndex = b - numProduct : nextIndex = indexFrame + numProduct, nextIndex = indexFrame, b - indexFrame < 2 * numProduct ? nextIndex = b - numProduct : nextIndex = indexFrame + numProduct, jQuery(".fgc-slider").animate({
left: a[nextIndex]
}, d, function() {
jQuery(".next-button").removeClass("disabled")
})))
}
function clickPreButton(a, b, c, d) {
jQuery(".pre-button").hasClass("disabled") || (jQuery(".pre-button").addClass("disabled"), $isMobile ? (indexFrame = a.indexOf(c.css("top")), nextIndex = indexFrame, b - indexFrame < 2 * numProduct ? nextIndex = b - numProduct : nextIndex = indexFrame + numProduct, jQuery(".fgc-slider").animate({
top: a[nextIndex]
}, d, function() {
jQuery(".pre-button").removeClass("disabled")
})) : (indexFrame = a.indexOf(c.css("left")), nextIndex = indexFrame, 0 !== indexFrame && (indexFrame < numProduct ? nextIndex = 0 : nextIndex = indexFrame - numProduct), jQuery(".fgc-slider").animate({
left: a[nextIndex]
}, d, function() {
jQuery(".pre-button").removeClass("disabled")
})))
}
function singleProductAddToCart(a) {
jQuery.ajax({
type: "POST",
dataType: "html",
url: a,
success: function(a) {
jQuery("#show_login").length > 0 ? (jQuery.cookie("initiateCheckout", "step1", {
expires: 10,
path: "/"
}), window.location = "/login-page") : window.location = "/checkout", disableBlurPage()
}
})
}
function subscriptionProductAddToCart(a, b) {
jQuery.ajax({
type: "POST",
url: a + "&ajax_add_cart=yes",
contentType: "application/json; charset=utf-8",
data: {
"add-to-cart": b
},
success: function(a) {
var a = JSON.parse(a);
"yes" == a.error ? window.location = window.location.href : (jQuery("#show_login").length > 0 ? (jQuery.cookie("step_2", 1, {
expires: 10,
path: "/"
}), jQuery.cookie("initiateCheckout", "step1", {
expires: 10,
path: "/"
}), window.location = "/login-page") : window.location = "/checkout", disableBlurPage())
}
})
}
function enableBlurPage() {
jQuery(".blur-main").fadeIn(), jQuery(".outbox-slider > .ajax-loader.small").removeClass("hide")
}
function disableBlurPage() {
jQuery(".blur-main").fadeOut()
}
jQuery(document).ready(function(a) {
if (screenWidth = a(window).width(), $isMobile = !1, $isDesktop = !0, screenWidth < 746 && ($isMobile = !0), screenWidth < 1024 && ($isDesktop = !1), $isSingleProduct = !1, a("body").hasClass("single-purchase") ? $isSingleProduct = !0 : (a(".fgc_slider_products").prependTo(".fgc-slider"), $isMobile ? a(".fgc_slider_products.desktop").remove() : a(".fgc_slider_products.mobile").remove()), a("body").hasClass("category_page")) {
$isMobile && a(".img-below-slider").closest("p").insertBefore(a(".outbox-slider")), mainPadding = a(".col-full").css("padding"), a(".shop-step-1 ").css("padding", mainPadding), a(".img-below-slider").closest("p").css("padding", mainPadding).css("padding-bottom", "0").css("margin-bottom", "0"), $isDesktop || a(".outbox-slider").css("margin", mainPadding), a(".single_variation_wrap").hide(), preSlider($isSingleProduct);
var b = a(".fgc-slider");
$totalFrameAndPositionFrames = getTotalFrameAndPositionFrames(), totalFrame = $totalFrameAndPositionFrames.totalFrame, leftFrameArray = $totalFrameAndPositionFrames.leftFrameArray, time = 1e3, $isMobile && a(".pre-button").length > 0 && ($isMobile && a(".fgc-slider").css("top", leftFrameArray[totalFrame - 4]), time = 1e3), a(".next-button").click(function() {
clickNextButton(leftFrameArray, totalFrame, b, time)
}), a(".pre-button").click(function() {
clickPreButton(leftFrameArray, totalFrame, b, time)
}), a(".single_add_to_cart_button").addClass("add_to_cart_button").addClass("ajax_add_to_cart").addClass("product-type-variable"), a(".outbox-slider").append('<div class="blur-main"></div>').append('<i class="ajax-loader small animate-spin hide"></i>'), a(".outbox-slider > .ajax-loader.small").css("position", "absolute").css("top", "50%").css("left", "50%").css("z-index", "9"), a(".blur-main").css("width", "100%").css("height", "100%").css("position", "absolute").css("top", "0").css("left", "0").css("background", "#fff").css("opacity", "0.6").css("z-index", "9").css("display", "none"), $isSingleProduct ? $isMobile ? a(".slide-frame").on("tap", function(b) {
b.preventDefault(), enableBlurPage(), $href = a(this).attr("href"), singleProductAddToCart($href)
}) : a(".slide-frame").click(function(b) {
b.preventDefault(), enableBlurPage(), $href = a(this).attr("href"), singleProductAddToCart($href)
}) : $isMobile ? a(".ajax_add_to_cart_variation").on("tap", function(b) {
b.preventDefault(), enableBlurPage(), $addToCartVal = a(this).find('input[name="add-to-cart"]').val(), $href = a(this).attr("href"), subscriptionProductAddToCart($href, $addToCartVal)
}) : a(".ajax_add_to_cart_variation").click(function(b) {
b.preventDefault(), enableBlurPage(), $addToCartVal = a(this).find('input[name="add-to-cart"]').val(), $href = a(this).attr("href"), subscriptionProductAddToCart($href, $addToCartVal)
}), a(".nav-text-pre").click(function(b) {
a(".pre-button").click()
}), a(".nav-text-next").click(function(b) {
a(".next-button").click()
})
}
// jQuery(".pre-button").hasClass("disabled") || (jQuery(".pre-button").addClass("disabled"), $isMobile ? (indexFrame = a.indexOf(c.css("top")), nextIndex = indexFrame, b - indexFrame < 2 * numProduct ? nextIndex = b - numProduct : nextIndex = indexFrame + numProduct, jQuery(".fgc-slider").animate({
// top: a[nextIndex]
// }, d, function() {
// jQuery(".pre-button").removeClass("disabled")
// })) : (indexFrame = a.indexOf(c.css("left")), nextIndex = indexFrame, 0 !== indexFrame && (indexFrame < numProduct ? nextIndex = 0 : nextIndex = indexFrame - numProduct), jQuery(".fgc-slider").animate({
// left: a[nextIndex]
// }, d, function() {
// jQuery(".pre-button").removeClass("disabled")
// })))
$totalFrameAndPositionFrames = getTotalFrameAndPositionFrames();
totalFrame = $totalFrameAndPositionFrames.totalFrame;
leftFrameArray = $totalFrameAndPositionFrames.leftFrameArray;
if(a("#need_move").length > 0){need_move = a("#need_move").val()}else{ need_move = 1}
if($isMobile){
if(totalFrame>3){
nextIndex = totalFrame - need_move - 4;
jQuery(".fgc-slider").animate({
top: leftFrameArray[nextIndex]
});
}
}
else{
if(totalFrame>3){
nextIndex = need_move ;
jQuery(".fgc-slider").animate({
left: leftFrameArray[nextIndex]
});
}
}
// if(a("#need_move").length > 0){need_move = a("#need_move").val()}else{ need_move = 2}
// totalSlide = a(".slide-frame").length;
// if(need_move>totalSlide - 4){
// need_move = totalSlide - 3;
// }
// if($isMobile ){
// move_height = 0 - (a(".slide-frame").outerHeight() + 20) * need_move - 10;
// a(".fgc-slider").animate({
// top: move_height
// }, 0, function() {});
// }
// else{
//
// if( need_move > 1){
// move_width = 0 - (a(".slide-frame").outerWidth() + 20) * (need_move - 1) - 10;
// a(".fgc-slider").animate({
// left: move_width
// }, 0, function() {}) ;
// }
// else if(need_move = 0){
// move_width = (a(".slide-frame").outerWidth() + 20) * (need_move - 1) - 10;
// a(".fgc-slider").animate({
// left: move_width
// }, 0, function() {}) ;
// }
// }
// !$isMobile && need_move !== 1 ? (need_move > 13 && (need_move = 13), move_width = 0 - (a(".slide-frame").outerWidth() + 20) * (need_move - 1) - 10, a(".fgc-slider").animate({
// left: move_width
// }, 0, function() {})) : need_move > 13 ? (move_height = -10, a(".fgc-slider").animate({
// top: move_height
// }, 0, function() {})) : need_move !== 1 && (need_move = 13 - need_move, move_height = 0 - (a(".slide-frame").outerHeight() + 20) * need_move - 10, 10 === need_move && (move_height -= 10), a(".fgc-slider").animate({
// top: move_height
// }, 0, function() {}))
// a("body").hasClass("subscription_category_page") && a("#make_change_subscription").length > 0 && a("#need_move").length > 0 && (need_move = a("#need_move").val(), !$isMobile && need_move > 1 ? (need_move > 13 && (need_move = 13), move_width = 0 - (a(".slide-frame").outerWidth() + 20) * (need_move - 2) - 10, a(".fgc-slider").animate({
// left: move_width
// }, 0, function() {})) : need_move > 13 ? (move_height = -10, a(".fgc-slider").animate({
// top: move_height
// }, 0, function() {})) : need_move > 1 && (need_move = 13 - need_move, move_height = 0 - (a(".slide-frame").outerHeight() + 20) * need_move - 10, 10 === need_move && (move_height -= 10), a(".fgc-slider").animate({
// top: move_height
// }, 0, function() {})))
});