Skip to content

Commit

Permalink
Fix issue #18
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Doan committed Aug 10, 2016
1 parent 1863d7d commit 473c55f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "magnify",
"description": "A simple, lightweight jQuery magnifying glass zoom plugin.",
"version": "1.6.7",
"version": "1.6.8",
"main": [
"dist/css/magnify.css",
"dist/js/jquery.magnify.js"
Expand Down
42 changes: 36 additions & 6 deletions dist/js/jquery.magnify.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* jQuery Magnify Plugin v1.6.7 by Tom Doan (http://thdoan.github.io/magnify/)
* jQuery Magnify Plugin v1.6.8 by Tom Doan (http://thdoan.github.io/magnify/)
* Based on http://thecodeplayer.com/walkthrough/magnifying-glass-for-images-using-jquery-and-css3
*
* jQuery Magnify by Tom Doan is licensed under the MIT License.
Expand All @@ -10,12 +10,34 @@
(function($) {
$.fn.magnify = function(oOptions) {

var oSettings = $.extend({
var $that = this, // Preserve scope
oSettings = $.extend({
/* Default options */
speed: 100,
timeout: -1,
onload: function(){}
}, oOptions),
// Based on debouncing function by John Hann (simplified)
// http://unscriptable.com/index.php/2009/03/20/debouncing-javascript-methods/
debounce = function(func) {
var timeout; // Handle to setTimeout async task (detection period)
// Return the new debounced function which executes the original
// function only once until the detection period expires
return function debounced() {
var obj = this, // Reference to original context object
args = arguments; // Arguments at execution time
// Execute after some delay
function delayed() {
func.apply(obj, args);
// Clear timeout handle
timeout = null;
}
// Stop any current detection period
if (timeout) clearTimeout(timeout);
// Reset the detection period
timeout = setTimeout(delayed, 100);
};
},
init = function(el) {
// Initiate
var $image = $(el),
Expand Down Expand Up @@ -71,12 +93,12 @@
$lens = $container.children('.magnify-lens');
// Remove the "Loading..." text
$lens.removeClass('loading');
// This code is inside the .load() function, which is important.
// The width and height of the object would return 0 if accessed
// before the image is fully loaded.
// Cache offsets and dimensions for improved performance
// NOTE: This code is inside the load() function, which is
// important. The width and height of the object would return 0 if
// accessed before the image is fully loaded.
nMagnifiedWidth = elImage.width;
nMagnifiedHeight = elImage.height;
// Cache offset and dimensions for improved performance
oContainerOffset = $container.offset();
nContainerWidth = $container.width();
nContainerHeight = $container.height();
Expand Down Expand Up @@ -185,6 +207,14 @@
});
}

// Handle window resizing
$(window).resize(debounce(function() {
$that.destroy();
$that.each(function() {
init(this);
})
}));

return this.each(function() {
// Initiate magnification powers
init(this);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "magnify",
"version": "1.6.7",
"version": "1.6.8",
"description": "A simple, lightweight jQuery magnifying glass zoom plugin.",
"keywords": [
"jquery-plugin",
Expand Down

0 comments on commit 473c55f

Please sign in to comment.