PageSourceSearch

https://www.imprentanacional.go.cr/js_srv/thirdparty/imagenzoom/cloud-zoom.1.0.2.js

js imprentanacional.go.cr collected 2026-10-02 03:12:01 UTC 16,513 bytes, 412 lines download raw bytes

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