Skip to content

Commit

Permalink
Add destroy() method; normalize line endings
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Doan committed Jul 18, 2016
1 parent 1aab082 commit a01be53
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
**/.*
*.json
LICENSE
README.md
README.md
1 change: 0 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,30 @@ Name | Type | Default | Description
`timeout` | number | -1 | The wait period in ms before hiding the magnifying lens on touch devices. Set to `-1` to disable.
`onload` | function | | Callback function to execute after magnification is loaded.

## Methods

To use a public method, you need to assign the element that you called `.magnify()` on from step 3 to a variable. Sample usage:

```html
<script>
$(document).ready(function() {
// Enable zoom
var $zoom = $('.zoom').magnify();
// Disable zoom
$zoom.destroy();
});
</script>
```

Name | Description
----------- | -----------
`destroy()` | Disable zoom and reset to the original state.

## Installation

Choose from one of the following methods:

- `git clone https://github.com/thdoan/magnify.git`
- `bower install magnify`
- `npm install magnify`
- [Download ZIP](https://github.com/thdoan/magnify/archive/master.zip)
- [Download ZIP](https://github.com/thdoan/magnify/archive/master.zip)
4 changes: 2 additions & 2 deletions 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.6",
"version": "1.6.7",
"main": [
"dist/css/magnify.css",
"dist/js/jquery.magnify.js"
Expand Down Expand Up @@ -30,4 +30,4 @@
"dependencies": {
"jquery": ">=1.7.0"
}
}
}
2 changes: 1 addition & 1 deletion dist/css/magnify.css
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ html.magnifying > body {
text-align: center;
text-shadow: 0 0 2px rgba(51, 51, 51, 0.8);
text-transform: none;
}
}
2 changes: 1 addition & 1 deletion dist/js/jquery.magnify-mobile.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,4 @@
});
}
});
}(jQuery));
}(jQuery));
28 changes: 21 additions & 7 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.6 by Tom Doan (http://thdoan.github.io/magnify/)
* jQuery Magnify Plugin v1.6.7 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 @@ -11,11 +11,11 @@
$.fn.magnify = function(oOptions) {

var oSettings = $.extend({
/* Default options */
speed: 100,
timeout: -1,
onload: function(){}
}, oOptions),
/* Default options */
speed: 100,
timeout: -1,
onload: function(){}
}, oOptions),
init = function(el) {
// Initiate
var $image = $(el),
Expand All @@ -40,6 +40,9 @@
// Disable zooming if no valid zoom image source
if (!sImgSrc) return;

// Save any inline styles for resetting
$image.data('originalStyle', $image.attr('style'));

// Activate magnification:
// 1. Try to get zoom image dimensions
// 2. Proceed only if able to get zoom image dimensions OK
Expand Down Expand Up @@ -171,10 +174,21 @@
elImage.src = sImgSrc;
};

// Turn off zoom and reset to original state
this.destroy = function() {
this.each(function() {
var $this = $(this),
sStyle = $this.data('originalStyle');
if (sStyle) $this.attr('style', sStyle);
else $this.removeAttr('style');
$this.unwrap('.magnify').prevAll('.magnify-lens').remove();
});
}

return this.each(function() {
// Initiate magnification powers
init(this);
});

};
}(jQuery));
}(jQuery));
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "magnify",
"version": "1.6.6",
"version": "1.6.7",
"description": "A simple, lightweight jQuery magnifying glass zoom plugin.",
"keywords": [
"jquery-plugin",
Expand All @@ -22,4 +22,4 @@
"type": "git",
"url": "https://github.com/thdoan/magnify.git"
}
}
}

0 comments on commit a01be53

Please sign in to comment.