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" >Èäåò çàãðóçêà...</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 destU = (((x) / sImg.outerWidth()) * zoomImage.width) >> 0; 137 destV = (((y) / sImg.outerHeight()) * zoomImage.height) >> 0; 138 139 140 currU += (destU - currU) / opts.smoothMove; 141 currV += (destV - currV) / opts.smoothMove; 142 if ((690 > zoomImage.width) && (500 > zoomImage.height)) { 143 zoomDiv.css('background-position', ('50% 50%')); 144 } else if ((500 > zoomImage.height) && (690 <= zoomImage.width)) { 145 zoomDiv.css('background-position', (-(currU >> 0) + 'px ') + ('50%')); 146 } else if ((690 > zoomImage.width) && (500 <= zoomImage.height)) { 147 zoomDiv.css('background-position', ('50%') + (-(currV >> 0) + 'px')); 148 } else if ((690 <= zoomImage.width) && (500 <= zoomImage.height)) { 149 zoomDiv.css('background-position', (-(currU >> 0) + 'px ') + (-(currV >> 0) + 'px')); 150 } 151 } 152 controlTimer = setTimeout(function () {
vendor: 1,135 bytes, lines 153-182
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 $mouseTrap = jWin.parent().append(format("<div class='mousetrap' style='background-image:url(\"/i/0.gif\");z-index:500;position:absolute;width:"+opts.zoomWidth+"px;height:"+opts.zoomHeight+"px;left:%2px;top:%3px;\'></div>", sImg.outerWidth(), sImg.outerHeight(), 0, 0)).find(':last'); 182
183 ////////////////////////////////////////////////////////////////////// 184 /* Do as little as possible in mousemove event to prevent slowdown. */ 185 $mouseTrap.bind('mousemove', this, function (event) { 186 // Just update the mouse position 187 mx = event.pageX; 188 my = event.pageY; 189 }); 190 ////////////////////////////////////////////////////////////////////// 191 $mouseTrap.bind('mouseleave', this, function (event) { 192 clearTimeout(controlTimer); 193 //event.data.removeBits(); 194 if(lens) { lens.fadeOut(299); } 195 if($tint) { $tint.fadeOut(299); } 196 if(softFocus) { softFocus.fadeOut(299); } 197 zoomDiv.fadeOut(300, function () { 198 ctx.fadedOut(); 199 }); 200 return false; 201 }); 202 ////////////////////////////////////////////////////////////////////// 203 $mouseTrap.bind('mouseenter', this, function (event) { 204 mx = event.pageX; 205 my = event.pageY; 206 zw = event.data; 207 if (zoomDiv) { 208 zoomDiv.stop(true, false); 209 zoomDiv.remove(); 210 } 211 212 var xPos = opts.adjustX, 213 yPos = opts.adjustY; 214 215 var siw = sImg.outerWidth(); 216 var sih = sImg.outerHeight(); 217 218 var w = opts.zoomWidth; 219 var h = opts.zoomHeight; 220 if (opts.zoomWidth == 'auto') { 221 w = siw; 222 } 223 if (opts.zoomHeight == 'auto') { 224 h = sih; 225 } 226 //$('#info').text( xPos + ' ' + yPos + ' ' + siw + ' ' + sih ); 227 var appendTo = jWin.parent(); // attach to the wrapper 228 switch (opts.position) { 229 case 'top': 230 yPos -= h; // + opts.adjustY; 231 break; 232 case 'right': 233 xPos += siw; // + opts.adjustX; 234 break; 235 case 'bottom': 236 yPos += sih; // + opts.adjustY; 237 break; 238 case 'left': 239 xPos -= w; // + opts.adjustX; 240 break; 241 case 'inside': 242 w = siw; 243 h = sih; 244 break; 245 // All other values, try and find an id in the dom to attach to. 246 default: 247 appendTo = $('#' + opts.position); 248 // If dom element doesn't exit, just use 'right' position as default. 249 if (!appendTo.length) { 250 appendTo = jWin; 251 xPos += siw; //+ opts.adjustX; 252 yPos += sih; // + opts.adjustY; 253 } else { 254 w = appendTo.innerWidth(); 255 h = appendTo.innerHeight(); 256 } 257 } 258 259 var newImg = new Image(); 260 newImg.src = zoomImage.src; 261 var height = newImg.height; 262 var width = newImg.width; 263 p = $(newImg).ready(function(){ 264 return {width: newImg.width, height: newImg.height}; 265 }); 266 //alert (p[0]['width']+" "+p[0]['height']); 267 268 if (w > p[0]['width'] || h > p[0]['height']) { 269 zoomDiv = appendTo.append(format('<div id="cloud-zoom-big" class="cloud-zoom-big" style="display:none;position:absolute;left:%0px;top:%1px;width:0px;height:0px;z-index:99;border:0px solid #FFF;" rel="1"></div>', xPos, yPos, w, h)).find(':last'); 270 } else { 271 zoomDiv = appendTo.append(format('<div id="cloud-zoom-big" class="cloud-zoom-big" style="display:none;position:absolute;left:%0px;top:%1px;width:'+opts.zoomWidth+'px;height:'+opts.zoomHeight+'px;background-color: #FFF; background-image:url(\'%4\');background-repeat: no-repeat;z-index:99;"></div>', xPos, yPos, w, h, zoomImage.src)).find(':last'); 272 } 273 274 // Add the title from title tag. 275 if (sImg.attr('title') && opts.showTitle) { 276 zoomDiv.append(format('<div class="cloud-zoom-title">%0</div>', sImg.attr('title'))).find(':last').css('opacity', opts.titleOpacity); 277 } 278 279 280 zoomDiv.fadeIn(500); 281 282 if (lens) { 283 lens.remove(); 284 lens = null; 285 } /* Work out size of cursor */ 286 cw = (sImg.outerWidth() / zoomImage.width) * zoomDiv.width(); 287 ch = (sImg.outerHeight() / zoomImage.height) * zoomDiv.height(); 288 289 // Attach mouse, initially invisible to prevent first frame glitch 290 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'); 291 292 if (w > p[0]['width'] || h > p[0]['height']) $mouseTrap.css('cursor', 'default'); 293 else $mouseTrap.css('cursor', lens.css('cursor')); 294 295 296 var noTrans = false;
297 298 // Init tint layer if needed. (Not relevant if using inside mode) 299 if (opts.tint) { 300 lens.css('background', 'url("' + sImg.attr('src') + '")'); 301 $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'); 302 $tint.css('opacity', opts.tintOpacity); 303 noTrans = true; 304 $tint.fadeIn(500); 305 306 } 307 if (opts.softFocus) { 308 lens.css('background', 'url("' + sImg.attr('src') + '")'); 309 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'); 310 softFocus.css('background', 'url("' + sImg.attr('src') + '")'); 311 softFocus.css('opacity', 0.5); 312 noTrans = true; 313 softFocus.fadeIn(500); 314 } 315 316 if (!noTrans) { 317 lens.css('opacity', opts.lensOpacity); 318 } 319 if ( opts.position !== 'inside' ) { lens.fadeIn(500); } 320 321 // Start processing. 322 zw.controlLoop(); 323 324 return; // Don't return false here otherwise opera will not detect change of the mouse pointer type. 325 }); 326 }; 327 328 img1 = new Image(); 329 $(img1).load(function () { 330 ctx.init2(this, 0); 331 }); 332 img1.src = sImg.attr('src'); 333 334 img2 = new Image(); 335 $(img2).load(function () { 336 ctx.init2(this, 1); 337 }); 338 img2.src = jWin.attr('href'); 339 } 340 341 $.fn.CloudZoom = function (options) { 342 // IE6 background image flicker fix 343 try { 344 document.execCommand("BackgroundImageCache", false, true); 345 } catch (e) {} 346 this.each(function () { 347 var relOpts, opts; 348 // Hmm...eval...slap on wrist. 349 eval('var a = {' + $(this).attr('rel') + '}'); 350 relOpts = a; 351 if ($(this).is('.cloud-zoom')) { 352 $(this).css({ 353 'position': 'relative', 354 'display': 'block' 355 }); 356 $('img', $(this)).css({ 357 'display': 'block' 358 }); 359 // Wrap an outer div around the link so we can attach things without them becoming part of the link. 360 // But not if wrap already exists. 361 if ($(this).parent().attr('id') != 'wrap') { 362 $(this).wrap('<div id="wrap" style="top:0px;z-index:550;position:relative;"></div>'); 363 } 364 opts = $.extend({}, $.fn.CloudZoom.defaults, options); 365 opts = $.extend({}, opts, relOpts); 366 $(this).data('zoom', new CloudZoom($(this), opts)); 367 368 } else if ($(this).is('.cloud-zoom-gallery')) { 369 opts = $.extend({}, relOpts, options); 370 $(this).data('relOpts', opts); 371 $(this).bind('click', $(this), function (event) { 372 var data = event.data.data('relOpts'); 373 // Destroy the previous zoom 374 $('#' + data.useZoom).data('zoom').destroy(); 375 // Change the biglink to point to the new big image. 376 $('#' + data.useZoom).attr('href', event.data.attr('href')); 377 // Change the small image to point to the new small image. 378 $('#' + data.useZoom + ' img').attr('src', event.data.data('relOpts').smallImage); 379 // Init a new zoom with the new images. 380 $('#' + event.data.data('relOpts').useZoom).CloudZoom(); 381 return false; 382 }); 383 } 384 }); 385 return this; 386 }; 387 388 $.fn.CloudZoom.defaults = { 389 zoomWidth: 'auto', 390 zoomHeight: 'auto', 391 position: 'right', 392 tint: false, 393 tintOpacity: 0.5, 394 lensOpacity: 0.5, 395 softFocus: false, 396 smoothMove: 3, 397 showTitle: true, 398 titleOpacity: 0.5, 399 adjustX: 0, 400 adjustY: 0 401 }; 402 403})(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.