1 2// Multi-Zoom Script (c)2012 John Davenport Scheuer 3// as first seen in http://www.dynamicdrive.com/forums/ 4// username: jscheuer1 - This Notice Must Remain for Legal Use 5// requires: a modified version of Dynamic Drive's Featured Image Zoomer (w/ adjustable power) (included) 6 7/*Featured Image Zoomer (May 8th, 2010) 8* This notice must stay intact for usage 9* Author: Dynamic Drive at http://www.dynamicdrive.com/ 10* Visit http://www.dynamicdrive.com/ for full source code 11*/ 12 13// Feb 21st, 2011: Script updated to v1.5, which now includes new feature by jscheuer1 (http://www.dynamicdrive.com/forums/member.php?u=2033) to show optional "magnifying lens" while over thumbnail image. 14// March 1st, 2011: Script updated to v1.51. Minor improvements to inner workings of script. 15// July 9th, 12': Script updated to v1.5.1, which fixes mouse wheel issue with script when used with a more recent version of jQuery. 16// Nov 5th, 2012: Unofficial update to v1.5.1m for integration with multi-zoom (adds multiple images to be zoomed via thumbnail activated image swapping) 17// Nov 28th, 2012: Version 2.1 w/Multi Zoom, updates - new features and bug fixes 18 19var featuredimagezoomer = { // the two options for Featured Image Zoomer: 20 loadinggif: '../../images/spinner20.gif', // full path or URL to "loading" gif 21 magnifycursor: 'crosshair' // value for CSS's 'cursor' property when over the zoomable image 22}; 23 24 //////////////// No Need To Edit Beyond Here //////////////// 25 26 27 28(function($){ 29 30 $('head').append('<style type="text/css">.featuredimagezoomerhidden {visibility: hidden!important;}</style>'); 31 32 $.fn.multizoomhide = function(){ 33 return $('<style type="text/css">' + this.selector + ' {visibility: hidden;}<\/style>').appendTo('head'); 34 }; 35 36 $.fn.addmultizoom = function(options){ 37 38 var indoptions = {largeimage: options.largeimage}, $imgObj = $(options.imgObj + ':not(".thumbs")'), 39 $descArea = $(options.descArea), first = true, splitre = /, ?/; 40 41 options = $.extend({ 42 speed: 'slow', 43 initzoomablefade: true, 44 zoomablefade: true 45 }, options); 46 47 function loadfunction(){ 48 var lnk = this, styleobj1 = {}, styleobj2 = {}, $nim, lnkd, lnkt, lnko, w, h; 49 if((lnkd = lnk.getAttribute('data-dims'))){ 50 lnkd = lnkd.split(splitre); 51 w = lnkd[0]; h = lnkd[1]; 52 } 53 $(new Image()).error(function(){ 54 if(lnk.tagName && !options.notmulti){ 55 //alert("Error: I couldn't find the image:\n\n" + lnk.href + ((lnkt = lnk.getAttribute('data-title'))? '\n\n"' + lnkt + '"' : '')); 56 if((lnko = $imgObj.data('last-trigger'))){ 57 first = true; 58 $(lnko).trigger('click'); 59 } 60 } 61 }).load(function(){ 62 var opacity = $imgObj.css('opacity'), combinedoptions = {}, $parent; 63 if(isNaN(opacity)){opacity = 1;} 64 if(options.notmulti || !indoptions.largeimage){ 65 w = options.width || $imgObj.width(); h = options.height || $imgObj.height(); 66 } 67 $imgObj.attr('src', this.src).css({width: w || options.width || this.width, height: (h = +(h || options.height || this.height))}); 68 if($imgObj.data('added')) {$imgObj.data('added').remove()}; 69 $imgObj.data('last-trigger', lnk); 70 if(options.imagevertcenter){styleobj1 = {top: ($imgObj.parent().innerHeight() - h) / 2};} 71 $imgObj.css(styleobj1).addimagezoom($.extend(combinedoptions, options, indoptions)) 72 .data('added', $('.magnifyarea:last' + (combinedoptions.cursorshade? ', .cursorshade:last' : '') + ', .zoomstatus:last, .zoomtracker:last')); 73 if(options.magvertcenter){ 74 $('.magnifyarea:last').css({marginTop: (h - $('.magnifyarea:last').height()) / 2}); 75 } 76 if(options.descpos){ 77 $parent = $imgObj.parent(); 78 styleobj2 = { left: $parent.offset().left + ($parent.outerWidth() - $parent.width()) / 2, top: h + $imgObj.offset().top }; 79 80 81 82 } 83 if(options.notmulti){ 84 $descArea.css(styleobj2); 85 } else { 86 $descArea.css(styleobj2).empty().append(lnk.getAttribute('data-title') || ''); 87 } 88 if(+opacity < 1){$imgObj.add($descArea).animate({opacity: 1}, options.speed);} 89 }).attr('src', $imgObj.data('src')); 90 } 91 92 this.click(function(e){
93 e.preventDefault(); 94 var src = $imgObj.attr('src'), ms, zr, cs, opacityObj = {opacity: 0}; 95 if(!first && (src === this.href || src === this.getAttribute('href'))){return;} 96 if(first && !options.initzoomablefade || !options.zoomablefade){opacityObj = {};} 97 first = false; 98 indoptions.largeimage = this.getAttribute('data-large') || options.largeimage || ''; 99 if(indoptions.largeimage === 'none'){indoptions.largeimage = '';} 100 if((ms = this.getAttribute('data-magsize')) || options.magnifiersize){ 101 indoptions.magnifiersize = (ms? ms.split(splitre) : '') || options.magnifiersize; 102 } else {delete indoptions.magnifiersize;} 103 indoptions.zoomrange = ((zr = this.getAttribute('data-zoomrange'))? (zr = zr.split(splitre)) : '') || options.zoomrange || ''; 104 if(zr){zr[0] = +zr[0]; zr[1] = +zr[1];} 105 indoptions.cursorshade = ((cs = this.getAttribute('data-lens'))? cs : '') || options.cursorshade || ''; 106 if(cs){indoptions.cursorshade = eval(cs);} 107 $imgObj.data('added') && 108 $imgObj.stop(true, true).data('added').not('.zoomtracker').remove().end() 109 .css({background: 'url(' + featuredimagezoomer.loadinggif + ') center no-repeat'}); 110 $imgObj.css($.extend({visibility: 'visible'}, ($imgObj.data('added')? options.zoomablefade? {opacity: 0.25} : opacityObj : opacityObj))).data('src', this.href); 111 $descArea.css($.extend({visibility: 'visible'}, opacityObj)); 112 loadfunction.call(this); 113 }).eq(0).trigger('click'); 114 115 return this; 116 }; 117 118 // Featured Image Zoomer main code: 119 120 $.extend(featuredimagezoomer, { 121 122 dsetting: { //default settings 123 magnifierpos: 'right', 124 magnifiersize:[200, 200], 125 cursorshadecolor: '#fff', 126 cursorshadeopacity: 0.3, 127 cursorshadeborder: '1px solid black', 128 cursorshade: false, 129 leftoffset: 15, //offsets here are used (added to) the width of the magnifyarea when 130 rightoffset: 10 //calculating space requirements and to position it visa vis any drop shadow 131 }, 132 133 isie: (function(){/*@cc_on @*//*@if(@_jscript_version >= 5)return true;@end @*/return false;})(), //is this IE? 134 135 showimage: function($tracker, $mag, showstatus){ 136 var specs=$tracker.data('specs'), d=specs.magpos, fiz=this; 137 var coords=$tracker.data('specs').coords //get coords of tracker (from upper corner of document) 138 specs.windimensions={w:$(window).width(), h:$(window).height()}; //remember window dimensions 139 var magcoords={} //object to store coords magnifier DIV should move to 140 magcoords.left = coords.left + (d === 'left'? -specs.magsize.w - specs.lo : $tracker.width() + specs.ro); 141 //switch sides for magnifiers that don't have enough room to display on the right if there's room on the left: 142 if(d!=='left' && magcoords.left + specs.magsize.w + specs.lo >= specs.windimensions.w && coords.left - specs.magsize.w >= specs.lo){ 143 magcoords.left = coords.left - specs.magsize.w - specs.lo; 144 } else if(d==='left' && magcoords.left < specs.ro) { //if there's no room on the left, move to the right 145 magcoords.left = coords.left + $tracker.width() + specs.ro; 146 } 147 $mag.css({left: magcoords.left, top:coords.top}).show(); //position magnifier DIV on page 148 specs.$statusdiv.html(ZoomTrans_1 + ': ' + specs.curpower + '<div style="font-size:80%">'+ZoomTrans_2+'</div>'); 149 if (showstatus) //show status DIV? (only when a range of zoom is defined) 150 fiz.showstatusdiv(specs, 400, 2000); 151 }, 152 153 hideimage: function($tracker, $mag, showstatus){ 154 var specs=$tracker.data('specs'); 155 $mag.hide(); 156 if (showstatus) 157 this.hidestatusdiv(specs); 158 }, 159 160 showstatusdiv: function(specs, fadedur, showdur){ 161 clearTimeout(specs.statustimer) 162 specs.$statusdiv.css({visibility: 'visible'}).fadeIn(fadedur) //show status div 163 specs.statustimer=setTimeout(function(){featuredimagezoomer.hidestatusdiv(specs)}, showdur) //hide status div after delay 164 }, 165 166 hidestatusdiv: function(specs){ 167 specs.$statusdiv.stop(true, true).hide() 168 }, 169 170 getboundary: function(b, val, specs){ //function to set x and y boundaries magnified image can move to (moved outside moveimage for efficiency) 171 if (b=="left"){ 172 var rb=-specs.imagesize.w*specs.curpower+specs.magsize.w 173 return (val>0)? 0 : (val<rb)? rb : val 174 } 175 else{ 176 var tb=-specs.imagesize.h*specs.curpower+specs.magsize.h 177 return (val>0)? 0 : (val<tb)? tb : val 178 } 179 }, 180
181 moveimage: function($tracker, $maginner, $cursorshade, e){ 182 var specs=$tracker.data('specs'), csw = Math.round(specs.magsize.w/specs.curpower), csh = Math.round(specs.magsize.h/specs.curpower), 183 csb = specs.csborder, fiz = this, imgcoords=specs.coords, pagex=(e.pageX || specs.lastpagex), pagey=(e.pageY || specs.lastpagey), 184 x=pagex-imgcoords.left, y=pagey-imgcoords.top; 185 $cursorshade.css({ // keep shaded area sized and positioned proportionately to area being magnified 186 visibility: '', 187 width: csw, 188 height: csh, 189 top: Math.min(specs.imagesize.h-csh-csb, Math.max(0, y-(csb+csh)/2)) + imgcoords.top, 190 left: Math.min(specs.imagesize.w-csw-csb, Math.max(0, x-(csb+csw)/2)) + imgcoords.left 191 }); 192 var newx=-x*specs.curpower+specs.magsize.w/2 //calculate x coord to move enlarged image 193 var newy=-y*specs.curpower+specs.magsize.h/2 194 $maginner.css({left:fiz.getboundary('left', newx, specs), top:fiz.getboundary('top', newy, specs)}) 195 specs.$statusdiv.css({left:pagex-10, top:pagey+20}) 196 specs.lastpagex=pagex //cache last pagex value (either e.pageX or lastpagex), as FF1.5 returns undefined for e.pageX for "DOMMouseScroll" event 197 specs.lastpagey=pagey 198 }, 199 200 magnifyimage: function($tracker, e, zoomrange){ 201 if (!e.detail && !e.wheelDelta){e = e.originalEvent;} 202 var delta=e.detail? e.detail*(-120) : e.wheelDelta //delta returns +120 when wheel is scrolled up, -120 when scrolled down 203 var zoomdir=(delta<=-120)? "out" : "in" 204 var specs=$tracker.data('specs') 205 var magnifier=specs.magnifier, od=specs.imagesize, power=specs.curpower 206 var newpower=(zoomdir=="in")? Math.min(power+1, zoomrange[1]) : Math.max(power-1, zoomrange[0]) //get new power 207 var nd=[od.w*newpower, od.h*newpower] //calculate dimensions of new enlarged image within magnifier 208 magnifier.$image.css({width:nd[0], height:nd[1]}) 209 specs.curpower=newpower //set current power to new power after magnification 210 specs.$statusdiv.html(ZoomTrans_1 + ': '+specs.curpower) 211 this.showstatusdiv(specs, 0, 500) 212 $tracker.trigger('mousemove') 213 }, 214 215 highestzindex: function($img){ 216 var z = 0, $els = $img.parents().add($img), elz; 217 $els.each(function(){ 218 elz = $(this).css('zIndex'); 219 elz = isNaN(elz)? 0 : +elz; 220 z = Math.max(z, elz); 221 }); 222 return z; 223 }, 224 225 init: function($img, options){ 226 var setting=$.extend({}, this.dsetting, options), w = $img.width(), h = $img.height(), o = $img.offset(), 227 fiz = this, $tracker, $cursorshade, $statusdiv, $magnifier, lastpage = {pageX: 0, pageY: 0}, 228 basezindex = setting.zIndex || this.highestzindex($img); 229 if(h === 0 || w === 0){ 230 $(new Image()).load(function(){ 231 featuredimagezoomer.init($img, options); 232 }).attr('src', $img.attr('src')); 233 return; 234 } 235 $img.css({visibility: 'visible'}); 236 setting.largeimage = setting.largeimage || $img.get(0).src; 237 $magnifier=$('<div class="magnifyarea" style="position:absolute;z-index:'+basezindex+';width:'+setting.magnifiersize[0]+'px;height:'+setting.magnifiersize[1]+'px;left:-10000px;top:-10000px;visibility:hidden;overflow:hidden;border:1px solid black;" />') 238 .append('<div style="position:relative;left:0;top:0;z-index:'+basezindex+';" />') 239 .appendTo(document.body) //create magnifier container 240 //following lines - create featured image zoomer divs, and absolutely positioned them for placement over the thumbnail and each other: 241 if(setting.cursorshade){ 242 $cursorshade = $('<div class="cursorshade" style="visibility:hidden;position:absolute;left:0;top:0;z-index:'+basezindex+';" />') 243 .css({border: setting.cursorshadeborder, opacity: setting.cursorshadeopacity, backgroundColor: setting.cursorshadecolor}) 244 .appendTo(document.body); 245 } else { 246 $cursorshade = $('<div />'); //dummy shade div to satisfy $tracker.data('specs') 247 } 248 $statusdiv = $('<div class="zoomstatus preloadevt" style="position:absolute;visibility:hidden;left:0;top:0;z-index:'+basezindex+';" />') 249 .html('<img src="'+this.loadinggif+'" />') 250 .appendTo(document.body); //create DIV to show "loading" gif/ "Current Zoom" info
251 $tracker = $('<div class="zoomtracker" style="cursor:progress;position:absolute;z-index:'+basezindex+';left:'+o.left+'px;top:'+o.top+'px;height:'+h+'px;width:'+w+'px;" />') 252 .css({backgroundImage: (this.isie? 'url(/images/transparent.gif)' : 'none')}) 253 .appendTo(document.body); 254 $(window).bind('load resize', function(){ //in case resizing the window repostions the image or description 255 var o = $img.offset(), $parent; 256 $tracker.css({left: o.left, top: o.top}); 257 if(options.descpos && options.descArea){ 258 $parent = $img.parent(); 259 $(options.descArea).css({left: $parent.offset().left + ($parent.outerWidth() - $parent.width()) / 2, top: $img.height() + o.top}); 260 } 261 }); 262 263 function getspecs($maginner, $bigimage){ //get specs function 264 var magsize={w:$magnifier.width(), h:$magnifier.height()} 265 var imagesize={w:w, h:h} 266 var power=(setting.zoomrange)? setting.zoomrange[0] : ($bigimage.width()/w).toFixed(5) 267 $tracker.data('specs', { 268 $statusdiv: $statusdiv, 269 statustimer: null, 270 magnifier: {$outer:$magnifier, $inner:$maginner, $image:$bigimage}, 271 magsize: magsize, 272 magpos: setting.magnifierpos, 273 imagesize: imagesize, 274 curpower: power, 275 coords: getcoords(), 276 csborder: $cursorshade.outerWidth(), 277 lo: setting.leftoffset, 278 ro: setting.rightoffset 279 }) 280 } 281 282 function getcoords(){ //get coords of thumb image function 283 var offset=$tracker.offset() //get image's tracker div's offset from document 284 return {left:offset.left, top:offset.top} 285 } 286 287 $tracker.mouseover(function(e){ 288 $cursorshade.add($magnifier).add($statusdiv).removeClass('featuredimagezoomerhidden'); 289 $tracker.data('premouseout', false); 290 }).mouseout(function(e){ 291 $cursorshade.add($magnifier).add($statusdiv.not('.preloadevt')).addClass('featuredimagezoomerhidden'); 292 $tracker.data('premouseout', true); 293 }).mousemove(function(e){ //save tracker mouse position for initial magnifier appearance, if needed 294 lastpage.pageX = e.pageX; 295 lastpage.pageY = e.pageY; 296 }); 297 298 $tracker.one('mouseover', function(e){ 299 var $maginner=$magnifier.find('div:eq(0)') 300 var $bigimage=$('<img src="'+setting.largeimage+'"/>').appendTo($maginner) 301 var largeloaded = featuredimagezoomer.loaded[$('<a href="'+setting.largeimage+'"></a>').get(0).href]; 302 var showstatus=setting.zoomrange && setting.zoomrange[1]>setting.zoomrange[0] 303 var imgcoords=getcoords() 304 if(!largeloaded){ 305 $img.stop(true, true).css({opacity:0.1}) //"dim" image while large image is loading 306 $statusdiv.css({left:imgcoords.left+w/2-$statusdiv.width()/2, top:imgcoords.top+h/2-$statusdiv.height()/2, visibility:'visible'}) 307 } 308 $bigimage.bind('loadevt', function(event, e){ //magnified image ONLOAD event function (to be triggered later) 309 if(e.type === 'error'){ 310 $img.css({opacity: 1}).data('added').remove(); 311 var src = $('<a href="' + $bigimage.attr('src') + '"></a>').get(0).href; 312 if(window.console && console.error){ 313 console.error('Cannot find Featured Image Zoomer larger image: ' + src); 314 } else { 315 alert('Cannot find Featured Image Zoomer larger image:\n\n' + src); 316 } 317 return; 318 } 319 featuredimagezoomer.loaded[this.src] = true; 320 $img.css({opacity:1}) //restore thumb image opacity 321 $statusdiv.empty().css({border:'1px solid black', background:'#C0C0C0', padding:'4px', font:'bold 13px Arial', opacity:0.8}).hide().removeClass('preloadevt'); 322 if($tracker.data('premouseout')){ 323 $statusdiv.addClass('featuredimagezoomerhidden'); 324 } 325 if (setting.zoomrange){ //if set large image to a specific power 326 var nd=[w*setting.zoomrange[0], h*setting.zoomrange[0]] //calculate dimensions of new enlarged image 327 $bigimage.css({width:nd[0], height:nd[1]}) 328 } 329 getspecs($maginner, $bigimage) //remember various info about thumbnail and magnifier 330 $magnifier.css({display:'none', visibility:'visible'}) 331 $tracker.mouseover(function(e){ //image onmouseover 332 $tracker.data('specs').coords=getcoords() //refresh image coords (from upper left edge of document) 333 fiz.showimage($tracker, $magnifier, showstatus) 334 }) 335 $tracker.mousemove(function(e){ //image onmousemove
336 fiz.moveimage($tracker, $maginner, $cursorshade, e) 337 }) 338 if (!$tracker.data('premouseout')){ 339 fiz.showimage($tracker, $magnifier, showstatus); 340 fiz.moveimage($tracker, $maginner, $cursorshade, lastpage); 341 } 342 $tracker.mouseout(function(e){ //image onmouseout 343 fiz.hideimage($tracker, $magnifier, showstatus) 344 }).css({cursor: fiz.magnifycursor}); 345 if (setting.zoomrange && setting.zoomrange[1]>setting.zoomrange[0]){ //if zoom range enabled 346 $tracker.bind('DOMMouseScroll mousewheel', function(e){ 347 fiz.magnifyimage($tracker, e, setting.zoomrange); 348 e.preventDefault(); 349 }); 350 } else if(setting.disablewheel){ 351 $tracker.bind('DOMMouseScroll mousewheel', function(e){e.preventDefault();}); 352 } 353 }) //end $bigimage onload 354 if ($bigimage.get(0).complete){ //if image has already loaded (account for IE, Opera not firing onload event if so) 355 $bigimage.trigger('loadevt', {type: 'load'}) 356 } 357 else{ 358 $bigimage.bind('load error', function(e){$bigimage.trigger('loadevt', e)}) 359 } 360 }) 361 }, 362 363 iname: (function(){var itag = $('<img />'), iname = itag.get(0).tagName; itag.remove(); return iname;})(), 364 365 loaded: {}, 366 367 hashre: /^#/ 368 }); 369 370 $.fn.addimagezoom = function(options){ 371 var sel = this.selector, $thumbs = $(sel.replace(featuredimagezoomer.hashre, '.') + '.thumbs a'); 372 options = options || {}; 373 if(options.multizoom !== null && ($thumbs).size()){ 374 $thumbs.addmultizoom($.extend(options, {imgObj: sel, multizoom: null})); 375 return this; 376 } else if(options.multizoom){ 377 $(options.multizoom).addmultizoom($.extend(options, {imgObj: sel, multizoom: null})); 378 return this; 379 } else if (options.multizoom !== null){ 380 return this.each(function(){ 381 if (this.tagName !== featuredimagezoomer.iname) 382 return true; //skip to next matched element 383 $('<a href="' + this.src + '"></a>').addmultizoom($.extend(options, {imgObj: sel, multizoom: null, notmulti: true})); 384 }); 385 } 386 return this.each(function(){ //return jQuery obj 387 if (this.tagName !== featuredimagezoomer.iname) 388 return true; //skip to next matched element 389 featuredimagezoomer.init($(this), options); 390 }); 391 }; 392 393})(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.