Skip to content

Commit 85e6324

Browse files
author
Tom Doan
committed
Update to v2.3.0
1 parent 436c661 commit 85e6324

File tree

4 files changed

+26
-44
lines changed

4 files changed

+26
-44
lines changed

README.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,24 +79,26 @@ $(document).ready(function() {
7979

8080
The options below can be set in a JavaScript object when calling `.magnify()`.
8181

82-
Name | Type | Default | Description
83-
------------------ | -------- | ------------ | -----------
84-
`src` | string | '' | URI of the large image that will be shown in the magnifying lens.
85-
`speed` | number | 100 | Fade-in/out animation speed in ms when the lens moves on/off the image.
86-
`timeout` | number | -1 | Wait period in ms before hiding the magnifying lens on touch devices. Set to `-1` to disable.
87-
`finalWidth` | number | | Width of the main image. Set this only if the image animates into view and has a different initial width. If the image doesn't animate, then you should set the image width in CSS or via the `width` attribute.
88-
`finalHeight` | number | | Height of the main image. Set this only if the image animates into view and has a different initial height. If the image doesn't animate, then you should set the image height in CSS or via the `height` attribute.
89-
`magnifiedWidth` | number | | Width of the image displayed inside the magnifying lens. Set this only if you want to override the large image's native width.
90-
`magnifiedHeight` | number | | Height of the image displayed inside the magnifying lens. Set this only if you want to override the large image's native height.
91-
`limitBounds` | boolean | false | Set this to `true` to keep the edge of the image within the magnifying lens.
92-
`mobileCloseEvent` | string | 'touchstart' | Custom event to fire when you tap on the mobile close button. Set this to `'click'` or `'touchend'` if it's conflicting with another event handler. This option is only applicable when the mobile plugin (jquery.magnify-mobile.js) is used.
93-
`afterLoad` | function | | Anonymous callback function to execute after magnification is loaded.
82+
Name | Type | Default | Description
83+
------------------- | -------- | ------------ | -----------
84+
`src` | string | '' | URI of the large image that will be shown in the magnifying lens.
85+
`speed` | number | 100 | Fade-in/out animation speed in ms when the lens moves on/off the image.
86+
`timeout` | number | -1 | Wait period in ms before hiding the magnifying lens on touch devices. Set to `-1` to disable.
87+
`touchBottomOffset` | number | 0 | Vertical touch point offset. Set this to something like `90` if you want to avoid your finger getting in the way of the magnifying lens on smartphones and tablets.
88+
`finalWidth` | number | | Width of the main image. Set this only if the image animates into view and has a different initial width. If the image doesn't animate, then you should set the image width in CSS or via the `width` attribute.
89+
`finalHeight` | number | | Height of the main image. Set this only if the image animates into view and has a different initial height. If the image doesn't animate, then you should set the image height in CSS or via the `height` attribute.
90+
`magnifiedWidth` | number | | Width of the image displayed inside the magnifying lens. Set this only if you want to override the large image's native width.
91+
`magnifiedHeight` | number | | Height of the image displayed inside the magnifying lens. Set this only if you want to override the large image's native height.
92+
`limitBounds` | boolean | false | Set this to `true` to keep the edge of the image within the magnifying lens.
93+
`mobileCloseEvent` | string | 'touchstart' | Custom event to fire when you tap on the mobile close button. Set this to `'click'` or `'touchend'` if it's conflicting with another event handler. This option is only applicable when the mobile plugin (jquery.magnify-mobile.js) is used.
94+
`afterLoad` | function | | Anonymous callback function to execute after magnification is loaded.
9495

9596
Options can also be set directly in the `<img>` tag by adding the following data attributes, which will take precedence over the corresponding options set inside an object:
9697

9798
- `data-magnify-src` - equivalent to `src`
9899
- `data-magnify-speed` - equivalent to `speed`
99100
- `data-magnify-timeout` - equivalent to `timeout`
101+
- `data-magnify-touchbottomoffset` - equivalent to `touchBottomOffset`
100102
- `data-magnify-finalwidth` - equivalent to `finalWidth`
101103
- `data-magnify-finalheight` - equivalent to `finalHeight`
102104
- `data-magnify-magnifiedwidth` - equivalent to `magnifiedWidth`

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "magnify",
33
"description": "A lightweight jQuery magnifying glass zoom plugin.",
4-
"version": "2.2.0",
4+
"version": "2.3.0",
55
"main": [
66
"dist/css/magnify.css",
77
"dist/js/jquery.magnify.js"

dist/js/jquery.magnify.js

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
'src': '',
1414
'speed': 100,
1515
'timeout': -1,
16+
'touchBottomOffset': 0,
1617
'finalWidth': null,
1718
'finalHeight': null,
1819
'magnifiedWidth': null,
1920
'magnifiedHeight': null,
20-
'touchBottom': true,
2121
'limitBounds': false,
2222
'mobileCloseEvent': 'touchstart',
2323
'afterLoad': function(){}
@@ -83,6 +83,13 @@
8383
if (oDataAttr['limitBounds']==='true') oOptions['limitBounds'] = true;
8484
if (typeof window[oDataAttr['afterLoad']]==='function') oOptions.afterLoad = window[oDataAttr['afterLoad']];
8585

86+
// Implement touch point bottom offset only on mobile devices
87+
if (/\b(Android|BlackBerry|IEMobile|iPad|iPhone|Mobile|Opera Mini)\b/.test(navigator.userAgent)) {
88+
if (!isNaN(+oDataAttr['touchBottomOffset'])) oOptions['touchBottomOffset'] = +oDataAttr['touchBottomOffset'];
89+
} else {
90+
oOptions['touchBottomOffset'] = 0;
91+
}
92+
8693
// Save any inline styles for resetting
8794
$image.data('originalStyle', $image.attr('style'));
8895

@@ -160,35 +167,8 @@
160167
//
161168
// We deduct the positions of .magnify from the mouse or touch positions relative to
162169
// the document to get the mouse or touch positions relative to the container.
163-
164-
// Mobile only offset touch point to be at the bottom not on the center
165-
var isMobile = {
166-
Android: function() {
167-
return navigator.userAgent.match(/Android/i);
168-
},
169-
BlackBerry: function() {
170-
return navigator.userAgent.match(/BlackBerry/i);
171-
},
172-
iOS: function() {
173-
return navigator.userAgent.match(/iPhone|iPad|iPod/i);
174-
},
175-
Opera: function() {
176-
return navigator.userAgent.match(/Opera Mini/i);
177-
},
178-
Windows: function() {
179-
return navigator.userAgent.match(/IEMobile/i);
180-
},
181-
any: function() {
182-
return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
183-
}
184-
};
185-
if(isMobile.any() && oOptions.touchBottom === true) {
186-
nX = (e.pageX || e.originalEvent.touches[0].pageX) - oContainerOffset['left'],
187-
nY = ((e.pageY || e.originalEvent.touches[0].pageY) - oContainerOffset['top']) -90;
188-
} else {
189-
nX = (e.pageX || e.originalEvent.touches[0].pageX) - oContainerOffset['left'],
190-
nY = (e.pageY || e.originalEvent.touches[0].pageY) - oContainerOffset['top'];
191-
}
170+
nX = (e.pageX || e.originalEvent.touches[0].pageX) - oContainerOffset['left'],
171+
nY = ((e.pageY || e.originalEvent.touches[0].pageY) - oContainerOffset['top']) - oOptions['touchBottomOffset'];
192172
// Toggle magnifying lens
193173
if (!$lens.is(':animated')) {
194174
if (nX>nBoundX && nX<nImageWidth-nBoundX && nY>nBoundY && nY<nImageHeight-nBoundY) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "magnify",
3-
"version": "2.2.0",
3+
"version": "2.3.0",
44
"description": "A lightweight jQuery magnifying glass zoom plugin.",
55
"keywords": [
66
"jquery-plugin",

0 commit comments

Comments
 (0)