https://www.ilovehalloween.com/wp-content/plugins/pointelle-slider/js/jquery.focuspoint.js?ver=3.1.5
1/** 2 * jQuery FocusPoint; version: 1.1.1 3 * Author: http://jonathonmenz.com 4 * Source: https://github.com/jonom/jquery-focuspoint 5 * Copyright (c) 2014 J. Menz; MIT License 6 * @preserve 7 */ 8; 9(function($) { 10 11 var defaults = { 12 reCalcOnWindowResize: true, 13 throttleDuration: 17 //ms - set to 0 to disable throttling 14 }; 15 16 //Setup a container instance 17 var setupContainer = function($el) { 18 var imageSrc = $el.find('img').attr('src'); 19 $el.data('imageSrc', imageSrc); 20 21 resolveImageSize(imageSrc, function(err, dim) { 22 $el.data({ 23 imageW: dim.width, 24 imageH: dim.height 25 }); 26 adjustFocus($el); 27 }); 28 }; 29 30 //Get the width and the height of an image 31 //by creating a new temporary image 32 var resolveImageSize = function(src, cb) { 33 //Create a new image and set a 34 //handler which listens to the first 35 //call of the 'load' event. 36 $('<img />').one('load', function() { 37 //'this' references to the new 38 //created image 39 cb(null, { 40 width: this.width, 41 height: this.height 42 }); 43 }).attr('src', src); 44 }; 45 46 //Create a throttled version of a function 47 var throttle = function(fn, ms) { 48 var isRunning = false; 49 return function() { 50 var args = Array.prototype.slice.call(arguments, 0); 51 if (isRunning) return false; 52 isRunning = true; 53 setTimeout(function() { 54 isRunning = false; 55 fn.apply(null, args); 56 }, ms); 57 }; 58 }; 59 60 //Calculate the new left/top values of an image 61 var calcShift = function(conToImageRatio, containerSize, imageSize, focusSize, toMinus) { 62 var containerCenter = Math.floor(containerSize / 2); //Container center in px 63 var focusFactor = (focusSize + 1) / 2; //Focus point of resize image in px 64 var scaledImage = Math.floor(imageSize / conToImageRatio); //Can't use width() as images may be display:none 65 var focus = Math.floor(focusFactor * scaledImage); 66 if (toMinus) focus = scaledImage - focus; 67 var focusOffset = focus - containerCenter; //Calculate difference between focus point and center 68 var remainder = scaledImage - focus; //Reduce offset if necessary so image remains filled 69 var containerRemainder = containerSize - containerCenter; 70 if (remainder < containerRemainder) focusOffset -= containerRemainder - remainder; 71 if (focusOffset < 0) focusOffset = 0; 72 73 return (focusOffset * -100 / containerSize) + '%'; 74 }; 75 76 //Re-adjust the focus 77 var adjustFocus = function($el) { 78 var imageW = $el.data('imageW'); 79 var imageH = $el.data('imageH'); 80 var imageSrc = $el.data('imageSrc'); 81 82 if (!imageW && !imageH && !imageSrc) { 83 return setupContainer($el); //Setup the container first 84 } 85 86 var containerW = $el.width(); 87 var containerH = $el.height(); 88 var focusX = parseFloat($el.data('focusX')); 89 var focusY = parseFloat($el.data('focusY')); 90 var $image = $el.find('img').first(); 91 92 //Amount position will be shifted 93 var hShift = 0; 94 var vShift = 0; 95 96 if (!(containerW > 0 && containerH > 0 && imageW > 0 && imageH > 0)) { 97 return false; //Need dimensions to proceed 98 } 99 100 //Which is over by more? 101 var wR = imageW / containerW; 102 var hR = imageH / containerH; 103 104 //Reset max-width and -height 105 $image.css({ 106 'max-width': '', 107 'max-height': '' 108 }); 109 110 //Minimize image while still filling space 111 if (imageW > containerW && imageH > containerH) { 112 $image.css((wR > hR) ? 'max-height' : 'max-width', '100%'); 113 } 114 115 if (wR > hR) { 116 hShift = calcShift(hR, containerW, imageW, focusX); 117 } else if (wR < hR) { 118 vShift = calcShift(wR, containerH, imageH, focusY, true); 119 } 120 121 $image.css({ 122 top: vShift, 123 left: hShift 124 }); 125 }; 126 127 var $window = $(window); 128 129 var focusPoint = function($el, settings) { 130 var thrAdjustFocus = settings.throttleDuration ? 131 throttle(function(){adjustFocus($el);}, settings.throttleDuration) 132 : function(){adjustFocus($el);};//Only throttle when desired 133 var isListening = false; 134 135 adjustFocus($el); //Focus image in container 136 137 //Expose a public API 138 return { 139 140 adjustFocus: function() { 141 return adjustFocus($el); 142 }, 143 144 windowOn: function() { 145 if (isListening) return; 146 //Recalculate each time the window is resized 147 $window.on('resize', thrAdjustFocus); 148 return isListening = true; 149 }, 150 151 windowOff: function() { 152 if (!isListening) return; 153 //Stop listening to the resize event 154 $window.off('resize', thrAdjustFocus); 155 isListening = false;
156 return true; 157 } 158 159 }; 160 }; 161 162 $.fn.focusPoint = function(optionsOrMethod) { 163 //Shortcut to functions - if string passed assume method name and execute 164 if (typeof optionsOrMethod === 'string') { 165 return this.each(function() { 166 var $el = $(this); 167 $el.data('focusPoint')[optionsOrMethod](); 168 }); 169 } 170 //Otherwise assume options being passed and setup 171 var settings = $.extend({}, defaults, optionsOrMethod); 172 return this.each(function() { 173 var $el = $(this); 174 var fp = focusPoint($el, settings); 175 //Stop the resize event of any previous attached 176 //focusPoint instances 177 if ($el.data('focusPoint')) $el.data('focusPoint').windowOff(); 178 $el.data('focusPoint', fp); 179 if (settings.reCalcOnWindowResize) fp.windowOn(); 180 }); 181 182 }; 183 184 $.fn.adjustFocus = function() { 185 //Deprecated v1.2 186 return this.each(function() { 187 adjustFocus($(this)); 188 }); 189 }; 190 191})(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.