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