Repository navigation
Expand file tree
/
Copy pathwooswipe.js
More file actions
224 lines (209 loc) · 7.67 KB
/
Copy pathwooswipe.js
File metadata and controls
224 lines (209 loc) · 7.67 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
(function(document, window, $) {
"use strict";
(function productThumbnails() {
// see wp_enqueue_script wp_localize_script wooswipe.php
var plugin_path = wooswipe_wp_plugin_path.templateUrl + "/";
var addPintrest = addpin['addpin'];
var firstUrl = $(".single-product-main-image img").attr("src");
var alt = $(".single-product-main-image img").attr("alt");
var link = window.location.href;
// run this on thumbnail click
function pinit(url) {
$(".wooswipe-pinit").attr(
"href",
"https://www.pinterest.com/pin/create/button/?media=" +
url +
"&url=" +
link +
"&description=" +
encodeURI(alt)
);
}
if (addPintrest) {
// set up first pin
$("#wooswipe").prepend(
'<a class="wooswipe-pinit" target="_blank" rel="noreferrer noopener" href="https://www.pinterest.com/pin/create/button/?media=' +
firstUrl +
"&url=" +
link +
"&description=" +
encodeURI(alt) +
'"><img src="' +
plugin_path +
'/pinit/pinterest.svg" alt="Pinterest" /></a>'
);
// popit new window
$(".wooswipe-pinit").click(function(e) {
e.preventDefault();
var popitHref = $(this).attr("href");
window.open(
popitHref,
"popUpWindow",
"height=500,width=500,left=100,top=100,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no,status=yes"
);
return false;
});
// end add pin
}
$(".thumbnail-nav").slick({
variableWidth: false,
dots: false,
focusOnSelect: false,
infinite: false,
slidesToShow: 5,
slidesToScroll: 1,
respondTo: "slider",
responsive: [
{
breakpoint: 680,
settings: {
slidesToShow: 5
}
},
{
breakpoint: 520,
settings: {
slidesToShow: 4
}
},
{
breakpoint: 420,
settings: {
slidesToShow: 3
}
}
]
});
var mainImage = $(".single-product-main-image img");
if (!mainImage.length) {
mainImage = $("#wooswipe > img");
mainImage.wrap('<a class="woocommerce-main-image zoom" href="#"></a>');
$(".woocommerce-main-image").wrap(
'<div class="single-product-main-image"></div>'
);
if (addPintrest) {
pinit(mainImage[0].src);
}
}
$(".thumbnails .thumb").click(function(e) {
e.preventDefault();
var $this = $(this);
var med = $this.attr("data-med");
var srcset = $this.attr("data-med");
var width = $this.attr("data-medw");
var height = $this.attr("data-medh");
var hq = $this.attr("data-hq");
var hqw = $this.attr("data-w");
var hqh = $this.attr("data-h");
var ind = $this.parent().index();
var parHeight = 0;
mainImage
.attr("data-ind", ind)
.attr("src", med)
.attr("srcset", med)
.attr("width", width)
.attr("height", height)
.attr("data-hq", hq)
.attr("data-w", hqw)
.attr("data-h", hqh);
if (addPintrest) {
pinit(med);
}
});
// on variation change set popup index to changed variation
$(document).on("change", ".variations select", function() {
var imgsrc = $("#wooswipe a:not(.wooswipe-pinit)").attr("href");
var srcind = 0;
$(".thumbnails .thumb").each(function() {
if (imgsrc == $(this).attr("data-hq")) {
srcind = $(this)
.parent()
.attr("data-slick-index");
}
});
$("#wooswipe img").attr("data-ind", srcind);
if (addPintrest) {
pinit(mainImage.attr("src"));
}
});
// compatibility for "WooCommerce Variation Swatches and Photo". On swatch change set popup index to changed variation
if ($(".variations .swatch-control").length > 0) {
$(".variations_form").addClass('has-swatches');
$(".variations_form.has-swatches").on('change', function (e) {
var imgsrc = $("#wooswipe a:not(.wooswipe-pinit)").attr("href");
var srcind = 0;
$(".thumbnails .thumb").each(function () {
if (imgsrc == $(this).attr("data-hq")) {
srcind = $(this).parent().attr("data-slick-index");
}
});
$("#wooswipe img").attr("data-ind", srcind);
if (addPintrest) {
pinit(mainImage.attr("src"));
}
});
}
})();
(function photoSwipe() {
var pswpElement = document.querySelectorAll(".pswp")[0];
var items = [];
function openPswp(index) {
var options = {
index: index,
shareEl: false
};
// Initializes and opens PhotoSwipe
var gallery = new PhotoSwipe(
pswpElement,
PhotoSwipeUI_Default,
items,
options
);
gallery.init();
}
// build items array
function pushItem(image) {
var src = image.attributes["data-hq"].value;
var w = image.attributes["data-w"].value;
var h = image.attributes["data-h"].value;
var t = image.attributes["data-title"].value;
var item = {
src: src,
w: w,
h: h,
title: t
};
items.push(item);
}
// Adding items to image for lightbox
if ($(".thumbnails .thumb").length > 0) {
var $thumbs = $(".thumbnails .thumb");
var thumbAlt = $thumbs.find("img").attr("alt");
for (var i = 0; i < $thumbs.length; i++) {
$thumbs.attr("data-title", thumbAlt);
pushItem($thumbs[i]);
}
} else if ($(".single-product-main-image").length > 0) {
var singleImg = $(".single-product-main-image img");
var singleImgAlt = singleImg.attr("alt");
singleImg.attr("data-title", singleImgAlt);
var $this = $(".single-product-main-image img")[0];
pushItem($this);
}
// click event
if ($(".single-product-main-image").length > 0) {
$(".single-product-main-image").click(function(e) {
// Allow user to open image link in new tab or download it
if (e.which == 2 || e.ctrlKey || e.altKey) {
return;
}
var ind = $(this)
.find("img")
.attr("data-ind");
e.preventDefault();
var index = ind ? parseInt(ind) : 0;
openPswp(index);
});
}
})();
})(document, window, jQuery);