vendor: 5,728 bytes, lines 1-220
1/*! 2 Zoom 1.7.13 3 license: MIT 4 http://www.jacklmoore.com/zoom 5*/ 6(function ($) { 7 var defaults = { 8 url: false, 9 callback: false, 10 target: false, 11 duration: 120, 12 on: 'mouseover', // other options: grab, click, toggle 13 touch: true, // enables a touch fallback 14 onZoomIn: false, 15 onZoomOut: false, 16 magnify: 1 17 }; 18 19 // Core Zoom Logic, independent of event listeners. 20 $.zoom = function(target, source, img, magnify) { 21 var targetHeight, 22 targetWidth, 23 sourceHeight, 24 sourceWidth, 25 xRatio, 26 yRatio, 27 offset, 28 position = $(target).css('position'), 29 $source = $(source); 30 31 // The parent element needs positioning so that the zoomed element can be correctly positioned within. 32 target.style.position = /(absolute|fixed)/.test(position) ? position : 'relative'; 33 target.style.overflow = 'hidden'; 34 35 img.style.width = img.style.height = ''; 36 37 $(img) 38 .addClass('zoomImg') 39 .css({ 40 position: 'absolute', 41 top: 0, 42 left: 0, 43 opacity: 0, 44 width: img.width * magnify, 45 height: img.height * magnify, 46 border: 'none', 47 maxWidth: 'none', 48 maxHeight: 'none' 49 }) 50 .appendTo(target); 51 52 return { 53 init: function() { 54 targetWidth = $(target).outerWidth(); 55 targetHeight = $(target).outerHeight(); 56 57 if (source === target) { 58 sourceWidth = targetWidth; 59 sourceHeight = targetHeight; 60 } else { 61 sourceWidth = $source.outerWidth(); 62 sourceHeight = $source.outerHeight(); 63 } 64 65 xRatio = (img.width - targetWidth) / sourceWidth; 66 yRatio = (img.height - targetHeight) / sourceHeight; 67 68 offset = $source.offset(); 69 }, 70 move: function (e) { 71 var left = (e.pageX - offset.left), 72 top = (e.pageY - offset.top); 73 74 top = Math.max(Math.min(top, sourceHeight), 0); 75 left = Math.max(Math.min(left, sourceWidth), 0); 76 77 img.style.left = (left * -xRatio) + 'px'; 78 img.style.top = (top * -yRatio) + 'px'; 79 } 80 }; 81 }; 82 83 $.fn.zoom = function (options) { 84 return this.each(function () { 85 var 86 settings = $.extend({}, defaults, options || {}), 87 //target will display the zoomed image 88 target = settings.target || this, 89 //source will provide zoom location info (thumbnail) 90 source = this, 91 $source = $(source), 92 img = document.createElement('img'), 93 $img = $(img), 94 mousemove = 'mousemove.zoom', 95 clicked = false, 96 touched = false, 97 $urlElement; 98 99 // If a url wasn't specified, look for an image element. 100 if (!settings.url) { 101 $urlElement = $source.find('img'); 102 if ($urlElement[0]) { 103 settings.url = $urlElement.data('src') || $urlElement.attr('src'); 104 } 105 if (!settings.url) { 106 return; 107 } 108 } 109 110 (function(){ 111 var position = target.style.position; 112 var overflow = target.style.overflow; 113 114 $source.one('zoom.destroy', function(){ 115 $source.off(".zoom"); 116 target.style.position = position; 117 target.style.overflow = overflow; 118 $img.remove(); 119 }); 120 121 }()); 122 123 img.onload = function () { 124 var zoom = $.zoom(target, source, img, settings.magnify); 125 126 function start(e) { 127 zoom.init(); 128 zoom.move(e); 129 130 // Skip the fade-in for IE8 and lower since it chokes on fading-in 131 // and changing position based on mousemovement at the same time. 132 $img.stop() 133 .fadeTo($.support.opacity ? settings.duration : 0, 1, $.isFunction(settings.onZoomIn) ? settings.onZoomIn.call(img) : false); 134 } 135 136 function stop() { 137 $img.stop() 138 .fadeTo(settings.duration, 0, $.isFunction(settings.onZoomOut) ? settings.onZoomOut.call(img) : false); 139 } 140 141 // Mouse events 142 if (settings.on === 'grab') { 143 $source 144 .on('mousedown.zoom', 145 function (e) { 146 if (e.which === 1) { 147 $(document).one('mouseup.zoom', 148 function () { 149 stop(); 150 151 $(document).off(mousemove, zoom.move); 152 } 153 ); 154 155 start(e); 156 157 $(document).on(mousemove, zoom.move); 158 159 e.preventDefault(); 160 } 161 } 162 ); 163 } else if (settings.on === 'click') { 164 $source.on('click.zoom', 165 function (e) { 166 if (clicked) { 167 // bubble the event up to the document to trigger the unbind. 168 return; 169 } else { 170 clicked = true; 171 start(e); 172 $(document).on(mousemove, zoom.move); 173 $(document).one('click.zoom', 174 function () { 175 stop(); 176 clicked = false; 177 $(document).off(mousemove, zoom.move); 178 } 179 ); 180 return false; 181 } 182 } 183 ); 184 } else if (settings.on === 'toggle') { 185 $source.on('click.zoom', 186 function (e) { 187 if (clicked) { 188 stop(); 189 } else { 190 start(e); 191 } 192 clicked = !clicked; 193 } 194 ); 195 } else if (settings.on === 'mouseover') { 196 zoom.init(); // Preemptively call init because IE7 will fire the mousemove handler before the hover handler. 197 198 $source 199 .on('mouseenter.zoom', start) 200 .on('mouseleave.zoom', stop) 201 .on(mousemove, zoom.move); 202 } 203 204 // Touch fallback 205 if (settings.touch) { 206 $source 207 .on('touchstart.zoom', function (e) { 208 e.preventDefault(); 209 if (touched) { 210 touched = false; 211 stop(); 212 } else { 213 touched = true; 214 start( e.originalEvent.touches[0] || e.originalEvent.changedTouches[0] ); 215 } 216 }) 217 .on('touchmove.zoom', function (e) { 218 e.preventDefault(); 219 zoom.move( e.originalEvent.touches[0] || e.originalEvent.changedTouches[0] ); 220 });
221 } 222 223 if ($.isFunction(settings.callback)) { 224 settings.callback.call(img); 225 } 226 }; 227 228 img.src = settings.url; 229 }); 230 }; 231 232 $.fn.zoom.defaults = defaults; 233}(window.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.