PageSourceSearch

https://www.speedyapplianceparts.com/content/magiczoomplus/magiczoomplus.stencil.js

js speedyapplianceparts.com collected 2026-10-09 22:40:02 UTC 15,867 bytes, 350 lines download raw bytes

1function mtLinkFile(url) {
2    var extention = url.replace(/^.+\.([^.]+)$/, '$1'),
3        targetTag = document.getElementsByTagName('head')[0];
4    if (extention == 'js') {
5        var scriptTag = document.createElement('script');
6        scriptTag.type = 'text/javascript';
7        scriptTag.src = url;
8        scriptTag.async = false;
9        if (arguments.length > 1) {
10            scriptTag.onload = arguments[1];
11        }
12        targetTag.appendChild(scriptTag);
13    }
14    if (extention == 'css') {
15        var linkTag = document.createElement('link');
16        linkTag.type = 'text/css';
17        linkTag.href = url;
18        linkTag.rel = 'stylesheet';
19        linkTag.media = 'screen';
20        targetTag.appendChild(linkTag);
21    }
22}
23
24mtLinkFile('/content/magiczoomplus/magiczoomplus.css');
25mtLinkFile('/content/magiczoomplus/magicscroll.css');
26mtLinkFile('/content/magiczoomplus/magiczoomplus.stencil.css');
27
28mtLinkFile('/content/magiczoomplus/magiczoomplus.settings.js');
29mtLinkFile('/content/magiczoomplus/magicscroll.js');
30mtLinkFile('/content/magiczoomplus/magiczoomplus.js');
31
32if (typeof jQuery == 'undefined') {
33    mtLinkFile('https://code.jquery.com/jquery-3.3.1.min.js');
34}
35
36mzpScriptsReady(function() { initMagicZoomPlus(); })
37
38var $mzp_firstImageIsVideo = false;
39
40function mzpScriptsReady(fnc) {
41    if (typeof MagicZoom == 'undefined' || typeof MagicScroll == 'undefined' || typeof mzOptions == 'undefined' || typeof jQuery == 'undefined') {
42        setTimeout(function() {
43            mzpScriptsReady(fnc);
44        }, 250);
45        return;
46    }
47    arguments[0]();
48}
49
50
51function initSirv() {
52    var SirvProductID = jQuery('input[name="product_id"]').val(),
53        SirvProductSKU = BCData.product_attributes.sku;
54    if (SirvID == '') return;
55
56    var spinURL = document.location.protocol.replace('file:', 'http:') + '//' + SirvID + '.sirv.com/' + SirvSpinsPath.replace(/{product\-id}/g, SirvProductID).replace(/{product\-sku}/g, SirvProductSKU);
57
58    jQuery.ajax({
59        url: spinURL,
60        dataType: "jsonp",
61        cache: true,
62        timeout: 8000,
63        error: function(data) {},
64        success: function(data) {
65
66            jQuery('div[data-slide-id="zoom"]').after('<div style="display:none;" data-slide-id="spin"><div class="Sirv" id="sirv-spin" data-src="' + spinURL + '"></div></div>');
67
68            jQuery('.MagicZoomSelectors').addClass('sirv-enabled').show().append('<a data-slide-id="spin" class="SirvIcon mz-thumb" href="#"><img id="SirvIcon" src="' + SirvIconURL + '"/></a>');
69
70            jQuery('.MagicZoomSelectors a[data-zoom-id]').first().addClass('active-magic-selector');
71
72            initMagicZoomPlusSelectors('a[data-slide-id="spin"]') 
73
74            var sirv = document.createElement('script');
75            sirv.type = 'text/javascript';
76            sirv.async = true;
77            sirv.src = document.location.protocol.replace('file:', 'http:') + '//scripts.sirv.com/sirv.js';
78            document.getElementsByTagName('script')[0].parentNode.appendChild(sirv);
79        }
80    });
81}
82
83function initMagicZoomPlusSelectors($s) {
84    jQuery($s).on('click touchend', function(e) {
85        if ( jQuery('div[data-slide-id]:visible iframe').length ==1 ) {
86          jQuery('div[data-slide-id]:visible iframe')[0].src = jQuery('div[data-slide-id]:visible iframe')[0].src;
87        }
88        jQuery('div[data-slide-id]').hide();
89        jQuery('div[data-slide-id="' + jQuery(this).attr('data-slide-id') + '"]').show();
90        jQuery('a.active-magic-selector').removeClass('active-magic-selector');
91        jQuery(this).addClass('active-magic-selector');
92        e.preventDefault();
93    });
94}
95
96function isVideoSelector($s) {
97    var regex_youtube_short = /https?:\/\/youtu\.be\/([^\/]{1,})\/?/gm,
98        regex_youtube_full = /https?:\/\/www\.youtube\.com\/watch\?v=(.{1,})/gm,
99        regex_youtube_embed = /https?:\/\/www\.youtube\.com\/embed\/(.{1,})/gm,
100        regex_vimeo = /https?:\/\/vimeo\.com\/(.{1,})/gm,
101        video_id, video_type;
102    var m = regex_youtube_short.exec($s);
103    if (m) {
104        video_id = m[1];
105        video_type = 'youtube';
106    } else {
107        var m = regex_youtube_full.exec($s);
108        if (m) {
109            video_id = m[1];
110            video_type = 'youtube';
111        } else {
112            var m = regex_youtube_embed.exec($s);
113            if (m) {
114                video_id = m[1];
115                video_type = 'youtube';
116            } else {
117                var m = regex_vimeo.exec($s);
118                if (m) {
119                    video_id = m[1];
120                    video_type = 'vimeo';
121                }
122            }  
123        }
124    }
125    if (video_type=='youtube') {
126        return '<iframe src="https://www.youtube.com/embed/'+video_id+'" frameborder="0" allowfullscreen></iframe>';
127    } else if (video_type=='vimeo') {
128        return '<iframe src="https://player.vimeo.com/video/'+video_id+'" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>';
129    }
130
131    return false;
132}
133
134function initMagicZoomPlus() {
135
136    var themes = {
137        'Light': {
138            'imagesList': '.productView .productView-thumbnails img',
139            'galleryContainer': 'figure.productView-image',
140            'elementsToHide': 'ul.productView-thumbnails, div.productView-thumbnails'
141        },
142        'Light2': {
143            'imagesList': '.productView .productView-thumbnails img',
144            'galleryContainer': 'ul.productView.productView-image',
145            'elementsToHide': 'ul.productView-thumbnails, div.productView-thumbnails'
146        },
147        'Arcade': {
148            'imagesList': '.template-product .product-images img',
149            'galleryContainer': '.template-product .product-images',
150            'elementsToHide': ''
151        },
152        'Clean': {
153            'imagesList': '.product-wrap .product-thumbnails img',
154            'galleryContainer': '.product-wrap .product-main-image',
155            'elementsToHide': '.product-wrap .product-thumbnails'
156        },
157        'Exhibit': {
158            'imagesList': '.main-product-graphic .product-slides-container img',
159            'galleryContainer': '.main-product-graphic .product-slides-container',
160            'elementsToHide': ''
161        },
162        'Cornerstone': {
163            'imagesList': '.productView-img-container img',
164            'galleryContainer': '.productView-img-container',
165            'elementsToHide': 'ul.productView-thumbnails'
166        },
167        'Cornerstone2': {
168            'imagesList': '.productView-images .productView-thumbnails img',
169            'galleryContainer': '.productView-images .productView-image-update',
170            'elementsToHide': '.productView-images .productView-thumbnails'
171        },
172        'PartsWarehouse': {
173            'imagesList': '#product-images-container .main-image-container img',
174            'galleryContainer': '#product-images-container .main-image-container',
175            'elementsToHide': '#product-images-container .slider-nav'
176        },
177        'Covent': {
178            'imagesList': '.productView-images .productView-thumbs img',
179            'galleryContainer': 'figure.productView-image',
180            'elementsToHide': '.productView-thumbs'
181        },
182        'Covent2': {
183            'imagesList': '.productView-images .productView-img-container img',
184            'galleryContainer': 'figure.productView-image',
185            'elementsToHide': '.productView-thumbs'
186        },
187        'Merchant': {
188            'imagesList': 'body.product .product-slides-container img',
189            'galleryContainer': 'body.product .product-images-container',
190            'elementsToHide': 'body.product .product-images-container .product-images-p
190agination'
191        },
192        'Fortune': {
193            'imagesList': 'body.template-product .product-slideshow-wrapper img',
194            'galleryContainer': 'body.template-product .product-slideshow-wrapper',
195            'elementsToHide': 'body.template-product .single-product-thumbnails'
196        },
197        'Supermarket': {
198            'imagesList': '.productView-detailsWrapper .productView-images .productView-imageCarousel-main img',
199            'galleryContainer': '.productView-detailsWrapper .productView-images .productView-imageCarousel-main',
200            'elementsToHide': '.productView-detailsWrapper .productView-images .productView-imageCarousel-nav'
201        },
202        'Supermarket2': {
203            'imagesList': '.productView-images .productView-imageCarousel-main img',
204            'galleryContainer': '.productView-images .productView-imageCarousel-main',
205            'elementsToHide': '.productView-images .productView-imageCarousel-nav'
206        },
207        'Foundry': {
208            'imagesList': '.template-product .product-slideshow .product-slideshow-images img',
209            'galleryContainer': '.template-product .product-slideshow .product-slideshow-images',
210            'elementsToHide': '.template-product .product-slideshow .product-thumbnails, .template-product .product-slideshow .spinner'
211        },
212        'Eloquence': {
213            'imagesList': '.hero-carousel--product img',
214            'galleryContainer': '.hero-carousel--product',
215            'elementsToHide': '.hero-carousel-navContainer'
216        },
217        'Warm': {
218            'imagesList': 'body.product .product-container .product-images .product-thumbnails img',
219            'galleryContainer': 'body.product .product-container .product-images .product-main-image',
220            'elementsToHide': 'body.product .product-container .product-images .product-thumbnails'
221        },
222        'Solera': {
223            'imagesList': '.page-type-product .productView-images .productView-wrap .productView-image img',
224            'galleryContainer': '.page-type-product .productView-images .productView-wrap',
225            'elementsToHide': '.page-type-product .productView-images .productView-thumbnails'
226        },
227        'Warm2': // single image page
228        {
229            'imagesList': 'body.product .product-container .product-images .product-main-image img',
230            'galleryContainer': 'body.product .product-container .product-images .product-main-image',
231            'elementsToHide': 'body.product .product-container .product-images .product-thumbnails'
232        }
233    }
234
235    mzOptions.onUpdate = function() {
236        jQuery('a.active-magic-selector').removeClass('active-magic-selector');
237        jQuery('a.mz-thumb-selected').addClass('active-magic-selector');
238    }
239
240    mzOptions.onZoomReady = function(id) {
241        if (!$mzp_firstImageIsVideo) {
242            jQuery('a.mz-thumb-selected').addClass('active-magic-selector');
243        }
244    }
245
246	var $initScroll = true;
247
248    for (var th in themes) {
249        var theme = themes[th];
250        if (jQuery(theme.imagesList).length && jQuery(theme.galleryContainer).length) {
251
252            var $gallery = jQuery('<div class="MagicZoomGallery ' + th + '"><div class="MagicZoomSelectors"><div data-options="items:4" class="MagicScroll"></div></div></div>');
253
254            var $images = [];
255
256            jQuery(theme.imagesList).each(function(index, el) {
257                var $imageURL = jQuery(this).attr('src');
258
259                if (typeof jQuery(this).attr('data-src') !== typeof undefined && jQuery(this).attr('data-src') !== false) {
260                    $imageURL = jQuery(this).attr('data-src').replace(/(.*)\?.*$/gm, '$1');
261                }
262                if (typeof jQuery(this).attr('data-lazy') !== typeof undefined && jQuery(this).attr('data-lazy') !== false) {
263                    $imageURL = jQuery(this).attr('data-lazy').replace(/(.*)\?.*$/gm, '$1');
264                }
265
266                if (typeof $images[$imageURL] != 'undefined') {
267                    return;
268                }
269
270                $images[$imageURL] = $imageURL;
271
272                $imageURL = $imageURL.replace(/(.*)\?.*?$/gm,'$1').replace(/stencil\/[0-9]{1,}x[0-9]{1,}\/products/gm, 'stencil/original/products').replace(/\?[^\/]*$/gm,'')+'?c=2&imbypass=on&imbypass=on';
273
274                var $alt = jQuery(this).attr('alt'),
275                    $title = jQuery(this).attr('alt');
276                var $videoCode = isVideoSelector($alt);
277
278                if (index == 0) {
279                    $gallery.prepend(
280                        '<div data-slide-id="zoom">' +
281                        '<a title="' + $title + '" class="MagicZoom" data-options="autostart:false;" id="zoom" href="' + $imageURL + '">' +
282                        '<img title="' + $title + '" alt="' + $alt + '" src="' + $imageURL.replace(/\/original\//gm, '/500x659/') + '" xsrcset="' + $imageURL.replace(/\/original\//gm, '/1000x1318/') + ' 2x"/>' +
283                        '</a></div>'
284                    );
285                }
286
287                if ($videoCode) {
288                    $gallery.find('.MagicZoomSelectors .MagicScroll').append('<a data-slide-id="video-' + index + '" href="#"><img src="' + $imageURL.replace(/\/original\//gm, '/75x75/') + '"/></a>');
289                    $gallery.find('div[data-slide-id="zoom"]').after('<div style="display:none" data-slide-id="video-' + index + '">' + $videoCode + '</div>');
290
291                    if (index == 0) {
292                        $mzp_firstImageIsVideo = true;
293                        $gallery.find('div[data-slide-id="zoom"]').hide();
294                        $gallery.find('div[data-slide-id="video-' + index + '"]').show();
295                        $gallery.find('a[data-slide-id="video-' + index + '"]').addClass('active-magic-selector');
296                    }
297
298                } else {
299                    $gallery.find('.MagicZoomSelectors .MagicScroll').append('<a data-slide-id="zoom" title="' + $title + '" data-zoom-id="zoom" href="' + $imageURL + '" data-image="' + $imageURL.replace(/\/original\//gm, '/500x659/') + '" xdata-image-2x="' + $imageURL.replace(/\/original\//gm, '/1000x1318/') + '"><img title="' + $title + '" alt="' + $alt + '" src="' + $imageURL.replace(/\/original\//gm, '/200x60/') + '" srcset="' + $imageURL.replace(/\/original\//gm, '/400x120/') + ' 2x"/></a>');
300                }
301
302            })
303
304            jQuery(theme.galleryContainer).hide().after($gallery);
305
306            if (jQuery('.MagicZoomSelectors a').length == 1) {
307                jQuery('.MagicZoomSelectors').hide();
308            }
309
310            initMagicZoomPlusSelectors('a[data-slide-id]');
311
312            jQuery(theme.elementsToHide).remove();
313            jQuery(document.body).addClass('MZP-' + th);
314
315            jQuery('input[name*="attribute"], select[name*="attribute"]').on('change', function() {
316                var data = { }, $formData = $('form[data-cart-item-add]').serializeArray();
317                for (var i in $formData) {
318                    data[$formData[i].name] = $formData[i].value;
319                }
320                jQuery.ajax({
321                    dataType: "json",
322                    url: '/remote/v1/product-attributes/' + jQuery('input[name="product_id"]').val(),
323                    headers: { 'stencil-config': '{}', 'stencil-options': '{"render_with":"products/bulk-discount-rates"}', "x-xsrf-token": window.BCData && window.BCData.csrf_token ? window.BCData.csrf_token : "" },
324                    data: data,
325                    method: 'post',
326                    success: function(response) {
327                        if (response.data.image != null) {
328                            MagicZoom.update('zoom', response.data.image.data.replace('{:size}', 'original'), response.data.image.data.replace('{:size}', '1000x1318'))
329                        }
330                    }
331                });
332            });
333
334            $mjs(document).jAddEvent('domready', function() {
335                setTimeout(function(){MagicZoom.start();MagicScroll.start();},100);
336            });
337
338            initSirv();
339
340$initScroll = false;
341
342            break;
343        }
344    }
345
346	if ($initScroll) {
347setTimeout(function(){MagicScroll.start();},100);
348	}
349
350}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.