PageSourceSearch

https://cdn.hddfs.com/front/js/KO/cloud-zoom.1.0.2.js?ver=491

js hddfs.com collected 2026-09-28 06:31:13 UTC 14,510 bytes, 379 lines download raw bytes

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