PageSourceSearch

https://waryearsremembered.co.uk/templates/waryears1/CloudZoom.js?version=1.0.311

js waryearsremembered.co.uk collected 2026-10-02 18:37:33 UTC 15,628 bytes, 372 lines download raw bytes

vendor: 4,204 bytes, lines 1-122
1//////////////////////////////////////////////////////////////////////////////////
2// Cloud Zoom V1.0.3
3// Rev 201209181857
4// (c) 2010-2012 by R Cecco. <http://www.professorcloud.com>
5// MIT License
6//
7// Please retain this copyright header in all versions of the software
8//
9//////////////////////////////////////////////////////////////////////////////////
10(function (jQuery, $) {
11    'use strict';
12    var scripts = document.getElementsByTagName("script"),
13        index = scripts[scripts.length - 1].src.lastIndexOf('/'),
14        lastScriptPath = scripts[scripts.length - 1].src.slice(0, index);
15
16    $(document).ready(function () {
17        $('.cloud-zoom, .cloud-zoom-gallery').CloudZoom();
18    });
19
20    function format(str) {
21        for (var i = 1; i < arguments.length; i++) {
22            str = str.replace('%' + (i - 1), arguments[i]);
23        }
24        return str;
25    }
26
27    function CloudZoom(jWin, opts) {
28        var sImg = $('img', jWin);
29        var img1;
30        var img2;
31        var zoomDiv = null;
32        var $mouseTrap = null;
33        var lens = null;
34        var $tint = null;
35        var softFocus = null;
36        var $ie6Fix = null;
37        var zoomImage;
38        var controlTimer = 0;
39        var cw, ch;
40        var destU = 0;
41        var destV = 0;
42        var currV = 0;
43        var currU = 0;
44        var filesLoaded = 0;
45        var mx, my;
46        var ctx = this,
47            zw;
48        setTimeout(function () {
49            if ($mouseTrap === null) {
50                var w = jWin.width();
51                jWin.parent().append(format('<div style="width:%0px;position:absolute;top:75%;left:%1px;text-align:center" class="cloud-zoom-loading" >Loading...</div>', w / 3, (w / 2) - (w / 6)));
52                $('cloud-zoom-loading', jWin.parent()).css('opacity', 0.5);
53            }
54        }, 200);
55        var ie6FixRemove = function () {
56            if ($ie6Fix !== null) {
57                $ie6Fix.remove();
58                $ie6Fix = null;
59            }
60        };
61        this.removeBits = function () {
62            if (lens) {
63                lens.remove();
64                lens = null;
65            }
66            if ($tint) {
67                $tint.remove();
68                $tint = null;
69            }
70            if (softFocus) {
71                softFocus.remove();
72                softFocus = null;
73            }
74            ie6FixRemove();
75            $('.cloud-zoom-loading', jWin.parent()).remove();
76        };
77        this.destroy = function () {
78            jWin.data('zoom', null);
79            if ($mouseTrap) {
80                $mouseTrap.unbind();
81                $mouseTrap.remove();
82                $mouseTrap = null;
83            }
84            if (zoomDiv) {
85                zoomDiv.remove();
86                zoomDiv = null;
87            }
88            this.removeBits();
89        };
90        this.fadedOut = function () {
91            if (zoomDiv) {
92                zoomDiv.remove();
93                zoomDiv = null;
94            }
95            this.removeBits();
96        };
97        this.controlLoop = function () {
98            if (lens) {
99                var x = (mx - sImg.offset().left - (cw * 0.5)) >> 0;
100                var y = (my - sImg.offset().top - (ch * 0.5)) >> 0;
101                if (x < 0) {
102                    x = 0;
103                } else if (x > (sImg.outerWidth() - cw)) {
104                    x = (sImg.outerWidth() - cw);
105                }
106                if (y < 0) {
107                    y = 0;
108                } else if (y > (sImg.outerHeight() - ch)) {
109                    y = (sImg.outerHeight() - ch);
110                }
111                lens.css({
112                    left: x,
113                    top: y
114                });
115                lens.css('background-position', (-x) + 'px ' + (-y) + 'px');
116                destU = (((x) / sImg.outerWidth()) * zoomImage.width) >> 0;
117                destV = (((y) / sImg.outerHeight()) * zoomImage.height) >> 0;
118                currU += (destU - currU) / opts.smoothMove;
119                currV += (destV - currV) / opts.smoothMove;
120                zoomDiv.css('background-position', (-(currU >> 0) + 'px ') + (-(currV >> 0) + 'px'));
121            }
122            controlTimer = setTimeout(function () {
123                ctx.controlLoop();
124            }, 30);
125        };
126        this.init2 = function (img, id) {
127            filesLoaded++;
128            if (id === 1) {
129                zoomImage = img;
130            }
131            if (filesLoaded === 2) {
132                this.init();
133            }
134        };
135        this.init = function () {
136            $('.cloud-zoom-loading', jWin.parent()).remove();
137            var $m = $("<div class='mousetrap' style='background-image:url(\"" + lastScriptPath + "/blank.png\")" + "\'></div>");
138            $mouseTrap = jWin.parent().append($m).find(':last');
139            $mouseTrap = $('.mousetrap', jWin.parent());
140            $mouseTrap.css({
141                width: sImg.outerWidth(),
142                height: sImg.outerHeight(),
143                top: 0,
144                left: 0,
145                position: 'absolute',
146                zIndex: 9999
147            });
148            $mouseTrap.bind('mousemove', this, function (event) {
149                mx = event.pageX;
150                my = event.pageY;
151            });
152            $mouseTrap.bind('mouseleave', this, function () {
153                cw = (sImg.outerWidth() / zoomImage.width) * opts.zoomWidth;
154                ch = (sImg.outerHeight() / zoomImage.height) * opts.zoomHeight;
155                if ((parseFloat($('body').css('width').replace('px', '')) < 980) ||
156                    (cw === sImg.outerWidth() && ch === sImg.outerWidth()))  return;
157                clearTimeout(controlTimer);
158                if (lens) {
159                    lens.fadeOut(299);
160                }
161                if ($tint) {
162                    $tint.fadeOut(299);
163                }
164                if (softFocus) {
165                    softFocus.fadeOut(299);
166                }
167                zoomDiv.fadeOut(300, function () {
168                    ctx.fadedOut();
169                });
170                return false;
171            });
172            $mouseTrap.bind('mouseenter', this, function (event) {
173                mx = event.pageX;
174                my = event.pageY;
175                zw = event.data;
176                if (zoomDiv) {
177                    zoomDiv.stop(true, false);
178                    zoomDiv.remove();
179                }
180                var xPos = opts.adjustX,
181                    yPos = opts.adjustY;
182                var siw = sImg.outerWidth();
183                var sih = sImg.outerHeight();
184                var w = opts.zoomWidth;
185                var h = opts.zoomHeight;
186                if (opts.zoomWidth === 'auto') {
187                    w = siw;
188                }
189                if (opts.zoomHeight === 'auto') {
190                    h = sih;
191                }
192                var appendTo = jWin.parent();
193                switch (opts.position) {
194                    case 'top':
195                        yPos -= h;
196                        break;
197                    case 'right':
198                        xPos += siw;
199                        break;
200                    case 'bottom':
201                        yPos += sih;
202                        break;
203                    case 'left':
204                        xPos -= w;
205                        break;
206                    case 'inside':
207                        w = siw;
208                        h = sih;
209                        break;
210                    default:
211                        appendTo = $('#' + opts.position);
212                        if (!appendTo.length) {
213                            appendTo = jWin;
214                            xPos += siw;
215                            yPos += sih;
216                        } else {
217                            w = appendTo.innerWidth();
218                            h = appendTo.innerHeight();
219                        }
220                }
221                zoomDiv = appendTo.append(format('<div id="cloud-zoom-big" class="cloud-zoom-big" style="display:none;position:absolute;left:%0px;top:%1px;width:%2px;height:%3px;background-image:url(\'%4\');z-index:99;"></div>', xPos+4, yPos-4, w, h, zoomImage.src)).find(':last');
222                zoomDiv = $('.cloud-zoom-big', appendTo);
223                cw = zoomImage.width > sImg.outerWidth() ?
224                    sImg.outerWidth() / zoomImage.width * zoomDiv.width() :
225                    sImg.outerWidth();
226                ch = zoomImage.height > sImg.outerHeight() ?
227                    sImg.outerHeight() / zoomImage.height * zoomDiv.height() :
228                    sImg.outerHeight();
229                if ((parseFloat($('body').css('width').replace('px', '')) < 980) ||
230                    (cw === sImg.outerWidth() && ch === sImg.outerHeight()))  return;
231
232                if (sImg.attr('title') && opts.showTitle) {
233                    zoomDiv.append(format('<div class="cloud-zoom-title">%0</div>', sImg.attr('title')));
234                    $('.cloud-zoom-title', zoomDiv).css('opacity', opts.titleOpacity);
235                }
236                if ($.browser && $.browser.msie && $.browser.version < 7) {
237                    $ie6Fix = $('<iframe frameborder="0" src="#"></iframe>').css({
238                        position: "absolute",
239                        left: xPos,
240                        top: yPos,
241                        zIndex: 99,
242                        width: w,
243                        height: h
244                    }).insertBefore(zoomDiv);
245                }
246                zoomDiv.fadeIn(500);
247                // fix zoom-big position
248                var bodyWidth = $('body').width();
249                var zOffset = zoomDiv.offset();
250                var sImgOffset = sImg.offset();
251                if (zOffset && zOffset.left) {
252                    var leftSpace = sImgOffset.left,
253                        rightSpace = bodyWidth - zOffset.left;
254
255                    if (rightSpace < leftSpace) {
256                        var zLeft = zoomDiv.css('left');
257                        zoomDiv.css({'left': 'auto', 'right': zLeft});
258                    } else if (zOffset.left < 0) {
259                        zoomDiv.css({'right': 'auto', 'left': zoomDiv.outerWidth()});
260                    }
261                }
262                if (lens) {
263                    lens.remove();
264                    lens = null;
265                }
266                lens = jWin.append(format("<div class = 'cloud-zoom-lens' style='display:none;z-index:98;position:absolute;width:%0px;height:%1px;'></div>", cw, ch)).find(':last');
267                lens = $('.cloud-zoom-lens', jWin);
268                $mouseTrap.css('cursor', lens.css('cursor'));
269                var noTrans = false;
270                if (opts.tint) {
271                    //lens.css('background', 'url("' + sImg.attr('src') + '")'); не показываем фон для линзы из-за проблем при ресайзу
272                    //lens.css('background-size', sImg.outerWidth() + 'px auto');
273                    $tint = jWin.append(format('<div class="cloud-zoom-tint" style="display:none;position:absolute; left:0px; top:0px; width:%0px; height:%1px; background-color:%2;" />', sImg.outerWidth(), sImg.outerHeight(), opts.tint)).find(':last');
274                    $tint = $('.cloud-zoom-tint', jWin);
275                    $tint.css('opacity', opts.tintOpacity);
276                    noTrans = true;
277                    $tint.fadeIn(500);
278                }
279                if (opts.softFocus) {
280                    //lens.css('background', 'url("' + sImg.attr('src') + '")'); не показываем фон для линзы из-за проблем при ресайзу
281                    //lens.css('background-size', sImg.outerWidth() + 'px auto');
282                    jWin.append(format('<div class="cloud-zoom-soft" style="position:absolute;display:none;top:0px; left:0px; width:%0px; height:%1px;" />', sImg.outerWidth() - 2, sImg.outerHeight() - 2, opts.tint));
283                    softFocus = $('.cloud-zoom-soft', jWin);
284                    softFocus.css('background', 'url("' + sImg.attr('src') + '")');
285                    softFocus.css('background-size', '100% 100%');
286                    //softFocus.css('opacity', 0.5);
287                    noTrans = true;
288                    softFocus.fadeIn(500);
289                }
290                if (!noTrans) {
291                    lens.css('opacity', opts.lensOpacity);
292                }
293                if (opts.position !== 'inside') {
294                    lens.fadeIn(500);
295                }
296                zw.controlLoop();
297                return;
298            });
299        };
300        img1 = new Image();
301        $(img1).load(function () {
302            ctx.init2(this, 0);
303        });
304        img1.src = sImg.attr('src');
305        img2 = new Image();
306        $(img2).load(function () {
307            ctx.init2(this, 1);
308        });
309        img2.src = jWin.attr('href');
310    }
311    $.fn.CloudZoom = function (options) {
312        try {
313            document.execCommand("BackgroundImageCache", false, true);
314        } catch (e) {}
315        this.each(function () {
316            var relOpts, opts;
317            if ($(this).find('img').length > 0 && $(this).attr('href') !== '#'){
318                var relArray = $(this).attr('rel').replace(/\'/g, '"').split(',');
319                jQuery.unique(relArray);
320                relArray = $.map(relArray, function(value) {
321                    var i = value.indexOf(':'),
322                        parts = [value.slice(0, i), value.slice(i+1)];
323                    return '"' + $.trim(parts[0]) + '":' + $.trim(parts[1]);
324                });
325                relOpts = $.parseJSON('{' + relArray.join(',') + '}');
326                if ($(this).is('.cloud-zoom')) {
327                    $(this).css({
328                        'position': 'relative',
329                        'display': 'block'
330                    });
331                    $('img', $(this)).css({
332                        'display': 'block'
333                    });
334                    if ($(this).parent().attr('id') !== 'wrap') {
335                        $(this).wrap('<div id="wrap" style="top:0px;position:relative;"></div>');
336                    }
337                    opts = $.extend({}, $.fn.CloudZoom.defaults, options);
338                    opts = $.extend({}, opts, relOpts);
339                    $(this).data('zoom', new CloudZoom($(this), opts));
340                } else if ($(this).is('.cloud-zoom-gallery')) {
341                    opts = $.extend({}, relOpts, options);
342                    $(this).data('relOpts', opts);
343                    $(this).bind('click', $(this), function (event) {
344                        var data = event.data.data('relOpts');
345                        $('#' + data.useZoom).data('zoom').destroy();
346                        $('#' + data.useZoom).attr('href', event.data.attr('href'));
347                        $('#' + data.useZoom + ' img')
348                            .attr('src', event.data.data('relOpts').smallImage)
349                            .removeAttr('srcset');
350                        $('#' + event.data.data('relOpts').useZoom).CloudZoom();
351                        return false;
352                    });
353                }
354            }
355        });
356        return this;
357    };
358    $.fn.CloudZoom.defaults = {
359        zoomWidth: "auto",
360        zoomHeight: "auto",
361        position: "right",
362        tint: "#aa00aa",
363        tintOpacity: "0.5",
364        lensOpacity: "0.5",
365        softFocus: false,
366        smoothMove: 3,
367        showTitle: true,
368        titleOpacity: "0.5",
369        adjustX: "0px",
370        adjustY: "0px"
371    };
372}) (window._$, window._$);

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.