PageSourceSearch

https://www.compeve.com/includes/templates/mozen_temp/jscript/cloud-zoom.1.0.3.js

js compeve.com collected 2026-09-29 21:55:09 UTC 16,329 bytes, 421 lines download raw bytes

vendor: 4,982 bytes, lines 1-152
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 ($) {
11   
12    // Get the path of executing script.
13    var scripts = document.getElementsByTagName("script");
14    var last = scripts[scripts.length-1].src.lastIndexOf('/');
15    var scriptPath = scripts[scripts.length-1].src.slice(0,last);
16        
17    $(document).ready(function () {
18        $('.cloud-zoom, .cloud-zoom-gallery').CloudZoom();
19    });
20
21    function format(str) {
22        for (var i = 1; i < arguments.length; i++) {
23            str = str.replace('%' + (i - 1), arguments[i]);
24        }
25        return str;
26    }
27
28    function CloudZoom(jWin, opts) {
29     
30        var sImg = $('img', jWin);
31        var	img1;
32        var	img2;
33        var zoomDiv = null;
34        var	$mouseTrap = null;
35        var	lens = null;
36        var	$tint = null;
37        var	softFocus = null;
38        var	$ie6Fix = null;
39        var	zoomImage;
40        var controlTimer = 0;      
41        var cw, ch;
42        var destU = 0;
43        var	destV = 0;
44        var currV = 0;
45        var currU = 0;      
46        var filesLoaded = 0;
47        var mx,
48        my; 
49        var ctx = this, zw;
50        // Display an image loading message. This message gets deleted when the images have loaded and the zoom init function is called.
51        // We add a small delay before the message is displayed to avoid the message flicking on then off again virtually immediately if the
52        // images load really fast, e.g. from the cache. 
53        //var	ctx = this;
54        setTimeout(function () {
55            if ($mouseTrap === null) {
56                var w = jWin.width();
57                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)));
58                $('cloud-zoom-loading', jWin.parent()).css('opacity', 0.5)
59            }
60        }, 200);
61
62
63        var ie6FixRemove = function () {
64
65            if ($ie6Fix !== null) {
66                $ie6Fix.remove();
67                $ie6Fix = null;
68            }
69        };
70
71        // Removes cursor, tint layer, blur layer etc.
72        this.removeBits = function () {
73            //$mouseTrap.unbind();
74            if (lens) {
75                lens.remove();
76                lens = null;             
77            }
78            if ($tint) {
79                $tint.remove();
80                $tint = null;
81            }
82            if (softFocus) {
83                softFocus.remove();
84                softFocus = null;
85            }
86            ie6FixRemove();
87
88            $('.cloud-zoom-loading', jWin.parent()).remove();
89        };
90
91
92        this.destroy = function () {
93            jWin.data('zoom', null);
94
95            if ($mouseTrap) {
96                $mouseTrap.unbind();
97                $mouseTrap.remove();
98                $mouseTrap = null;
99            }
100            if (zoomDiv) {
101                zoomDiv.remove();
102                zoomDiv = null;
103            }
104            //ie6FixRemove();
105            this.removeBits();
106        // DON'T FORGET TO REMOVE JQUERY 'DATA' VALUES
107        };
108
109
110        // This is called when the zoom window has faded out so it can be removed.
111        this.fadedOut = function () {
112            
113            if (zoomDiv) {
114                zoomDiv.remove();
115                zoomDiv = null;
116            }
117            this.removeBits();
118        //ie6FixRemove();
119        };
120
121        this.controlLoop = function () {
122            if (lens) {
123                var x = (mx - sImg.offset().left - (cw * 0.5)) >> 0;
124                var y = (my - sImg.offset().top - (ch * 0.5)) >> 0;
125               
126                if (x < 0) {
127                    x = 0;
128                }
129                else if (x > (sImg.outerWidth() - cw)) {
130                    x = (sImg.outerWidth() - cw);
131                }
132                if (y < 0) {
133                    y = 0;
134                }
135                else if (y > (sImg.outerHeight() - ch)) {
136                    y = (sImg.outerHeight() - ch);
137                }
138
139                lens.css({
140                    left: x,
141                    top: y
142                });
143                lens.css('background-position', (-x) + 'px ' + (-y) + 'px');
144
145                destU = (((x) / sImg.outerWidth()) * zoomImage.width) >> 0;
146                destV = (((y) / sImg.outerHeight()) * zoomImage.height) >> 0;
147                currU += (destU - currU) / opts.smoothMove;
148                currV += (destV - currV) / opts.smoothMove;
149
150                zoomDiv.css('background-position', (-(currU >> 0) + 'px ') + (-(currV >> 0) + 'px'));              
151            }
152            controlTimer = setTimeout(function () {
153                ctx.controlLoop();
154            }, 30);
155        };
156
157        this.init2 = function (img, id) {
158
159            filesLoaded++;
160            //console.log(img.src + ' ' + id + ' ' + img.width);	
161            if (id === 1) {
162                zoomImage = img;
163            }
164            //this.images[id] = img;
165            if (filesLoaded === 2) {
166                this.init();
167            }
168        };
169
170        /* Init function start.  */
171        this.init = function () {
172            // Remove loading message (if present);
173            $('.cloud-zoom-loading', jWin.parent()).remove();
174
175
176            /* Add a box (mouseTrap) over the small image to trap mouse events.
177		It has priority over zoom window to avoid issues with inner zoom.
178		We need the dummy background image as IE does not trap mouse events on
179		transparent parts of a div.
180		*/
181            var $m = $("<div class='mousetrap' style='background-image:url(\"" + scriptPath + "/blank.png\")" + "\'></div>");
182            $mouseTrap = jWin.parent().append($m).find(':last');
183            $mouseTrap = $('.mousetrap',jWin.parent());
184            $mouseTrap.css({
185                width:sImg.outerWidth(),
186                height:sImg.outerHeight(),
187                top:0,
188                left:0,
189                position:'absolute',
190                zIndex:9999
191            });
192            //////////////////////////////////////////////////////////////////////			
193            /* Do as little as possible in mousemove event to prevent slowdown. */
194            $mouseTrap.bind('mousemove', this, function (event) {
195                // Just update the mouse position
196                mx = event.pageX;
197                my = event.pageY;
198               
199            });
200            //////////////////////////////////////////////////////////////////////					
201            $mouseTrap.bind('mouseleave', this, function (event) {
202                clearTimeout(controlTimer);
203                //event.data.removeBits();                
204                if(lens) {
205                    lens.fadeOut(299);
206                }
207                if($tint) {
208                    $tint.fadeOut(299);
209                }
210                if(softFocus) {
211                    softFocus.fadeOut(299);
212                }
213                zoomDiv.fadeOut(300, function () {
214                    ctx.fadedOut();
215                });																
216                return false;
217            });
218            //////////////////////////////////////////////////////////////////////			
219            $mouseTrap.bind('mouseenter', this, function (event) {
220                mx = event.pageX;
221                my = event.pageY;
222                zw = event.data;
223                if (zoomDiv) {
224                    zoomDiv.stop(true, false);
225                    zoomDiv.remove();
226                }
227
228                var xPos = opts.adjustX,
229                yPos = opts.adjustY;
230                             
231                var siw = sImg.outerWidth();
232                var sih = sImg.outerHeight();
233
234                var w = opts.zoomWidth;
235                var h = opts.zoomHeight;
236                if (opts.zoomWidth == 'auto') {
237                    w = siw;
238                }
239                if (opts.zoomHeight == 'auto') {
240                    h = sih;
241                }
242                //$('#info').text( xPos + ' ' + yPos + ' ' + siw + ' ' + sih );
243                var appendTo = jWin.parent(); // attach to the wrapper			
244                switch (opts.position) {
245                    case 'top':
246                        yPos -= h; // + opts.adjustY;
247                        break;
248                    case 'right':
249                        xPos += siw; // + opts.adjustX;					
250                        break;
251                    case 'bottom':
252                        yPos += sih; // + opts.adjustY;
253                        break;
254                    case 'left':
255                        xPos -= w; // + opts.adjustX;					
256                        break;
257                    case 'inside':
258                        w = siw;
259                        h = sih;
260                        break;
261                    // All other values, try and find an id in the dom to attach to.
262                    default:
263                        appendTo = $('#' + opts.position);
264                        // If dom element doesn't exit, just use 'right' position as default.
265                        if (!appendTo.length) {
266                            appendTo = jWin;
267                            xPos += siw; //+ opts.adjustX;
268                            yPos += sih; // + opts.adjustY;	
269                        } else {
270                            w = appendTo.innerWidth();
271                            h = appendTo.innerHeight();
272                        }
273                }
274
275                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, yPos, w, h, zoomImage.src)).find(':last');
276                zoomDiv = $('.cloud-zoom-big',appendTo);
277                // Add the title from title tag.
278                if (sImg.attr('title') && opts.showTitle) {
279                    zoomDiv.append(format('<div class="cloud-zoom-title">%0</div>', sImg.attr('title'))); 
280                    $('.cloud-zoom-title', zoomDiv).css('opacity', opts.titleOpacity);
281                }
282
283                // Fix ie6 select elements wrong z-index bug. Placing an iFrame over the select element solves the issue...		
284                if ($.browser.msie && $.browser.version < 7) {
285                    $ie6Fix = $('<iframe frameborder="0" src="#"></iframe>').css({
286                        position: "absolute",
287                        left: xPos,
288                        top: yPos,
289                        zIndex: 99,
290                        width: w,
291                        height: h
292                    }).insertBefore(zoomDiv);
293                }
294
295                zoomDiv.fadeIn(500);
296
297                if (lens) {
298                    lens.remove();
299                    lens = null;
300                } /* Work out size of cursor */
301                cw = (sImg.outerWidth() / zoomImage.width) * zoomDiv.width();
302                ch = (sImg.outerHeight() / zoomImage.height) * zoomDiv.height();
303
304                // Attach mouse, initially invisible to prevent first frame glitch
305                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');
306                lens = $('.cloud-zoom-lens',jWin);
307                $mouseTrap.css('cursor', lens.css('cursor'));
308
309                var noTrans = false;
310
311                // Init tint layer if needed. (Not relevant if using inside mode)			
312                if (opts.tint) {
313                    lens.css('background', 'url("' + sImg.attr('src') + '")');
314                    $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');
315                    $tint = $('.cloud-zoom-tint',jWin);
316                    
317                    $tint.css('opacity', opts.tintOpacity);                    
318                    noTrans = true;
319                    $tint.fadeIn(500);
320
321                }
322                if (opts.softFocus) {
323                    lens.css('background', 'url("' + sImg.attr('src') + '")');
324                    jWin.append(format('<div class="cloud-zoom-soft" style="position:absolute;display:none;top:2px; left:2px; width:%0px; height:%1px;" />', sImg.outerWidth() - 2, sImg.outerHeight() - 2, opts.tint));
325                    softFocus = $('.cloud-zoom-soft',jWin);
326                    softFocus.css('background', 'url("' + sImg.attr('src') + '")');
327                    softFocus.css('opacity', 0.5);
328                    noTrans = true;
329                    softFocus.fadeIn(500);
330                }
331
332                if (!noTrans) {
333                    lens.css('opacity', opts.lensOpacity);										
334                }
335                if ( opts.position !== 'inside' ) {
336                    lens.fadeIn(500);
337                }
338
339                // Start processing. 
340                zw.controlLoop();
341
342                return; // Don't return false here otherwise opera will not detect change of the mouse pointer type.
343            });
344        };
345
346        img1 = new Image();
347        $(img1).load(function () {
348            ctx.init2(this, 0);
349        });
350        img1.src = sImg.attr('src');
351
352        img2 = new Image();
353        $(img2).load(function () {
354            ctx.init2(this, 1);
355        });
356        img2.src = jWin.attr('href');
357    }
358
359    $.fn.CloudZoom = function (options) {
360        // IE6 background image flicker fix
361        try {
362            document.execCommand("BackgroundImageCache", false, true);
363        } catch (e) {}
364        this.each(function () {
365            var	relOpts, opts;
366            // Hmm...eval...slap on wrist.
367            eval('var	a = {' + $(this).attr('rel') + '}');
368            relOpts = a;
369            if ($(this).is('.cloud-zoom')) {
370                $(this).css({
371                    'position': 'relative',
372                    'display': 'block'
373                });
374                $('img', $(this)).css({
375                    'display': 'block'
376                });
377                // Wrap an outer div around the link so we can attach things without them becoming part of the link.
378                // But not if wrap already exists.
379                if ($(this).parent().attr('id') != 'wrap') {
380                    $(this).wrap('<div id="wrap" style="top:0px;z-index:9999;position:relative;"></div>');
381                }
382                opts = $.extend({}, $.fn.CloudZoom.defaults, options);
383                opts = $.extend({}, opts, relOpts);
384                $(this).data('zoom', new CloudZoom($(this), opts));
385
386            } else if ($(this).is('.cloud-zoom-gallery')) {
387                opts = $.extend({}, relOpts, options);
388                $(this).data('relOpts', opts);
389                $(this).bind('click', $(this), function (event) {
390                    var data = event.data.data('relOpts');
391                    // Destroy the previous zoom
392                    $('#' + data.useZoom).data('zoom').destroy();
393                    // Change the biglink to point to the new big image.
394                    $('#' + data.useZoom).attr('href', event.data.attr('href'));
395                    // Change the small image to point to the new small image.
396                    $('#' + data.useZoom + ' img').attr('src', event.data.data('relOpts').smallImage);
397                    // Init a new zoom with the new images.				
398                    $('#' + event.data.data('relOpts').useZoom).CloudZoom();
399                    return false;
400                });
401            }
402        });
403        return this;
404    };
405
406    $.fn.CloudZoom.defaults = {
407        zoomWidth: 'auto',
408        zoomHeight: 'auto',
409        position: 'inside',
410        tint: '#FFFFFF',
411        tintOpacity: 1,
412        lensOpacity: 0.5,
413        softFocus: false,
414        smoothMove: 3,
415        showTitle: false,
416        titleOpacity: 0.5,
417        adjustX: 0,
418        adjustY: 0
419    };
420
421})(jQuery);

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.