From a01be53bb6d6f24ede7db487f5c7ddeedf3a558d Mon Sep 17 00:00:00 2001 From: Tom Doan Date: Mon, 18 Jul 2016 12:50:24 +0800 Subject: [PATCH] Add destroy() method; normalize line endings --- .npmignore | 2 +- LICENSE | 1 - README.md | 21 ++++++++++++++++++++- bower.json | 4 ++-- dist/css/magnify.css | 2 +- dist/js/jquery.magnify-mobile.js | 2 +- dist/js/jquery.magnify.js | 28 +++++++++++++++++++++------- package.json | 4 ++-- 8 files changed, 48 insertions(+), 16 deletions(-) diff --git a/.npmignore b/.npmignore index 15a067f..4fd36a3 100644 --- a/.npmignore +++ b/.npmignore @@ -1,4 +1,4 @@ **/.* *.json LICENSE -README.md \ No newline at end of file +README.md diff --git a/LICENSE b/LICENSE index 48a1dd7..d130785 100644 --- a/LICENSE +++ b/LICENSE @@ -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. - diff --git a/README.md b/README.md index 0843fd0..b2c44bf 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,25 @@ 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 + +``` + +Name | Description +----------- | ----------- +`destroy()` | Disable zoom and reset to the original state. + ## Installation Choose from one of the following methods: @@ -80,4 +99,4 @@ 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) \ No newline at end of file +- [Download ZIP](https://github.com/thdoan/magnify/archive/master.zip) diff --git a/bower.json b/bower.json index 3f2b7ca..d70f339 100644 --- a/bower.json +++ b/bower.json @@ -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" @@ -30,4 +30,4 @@ "dependencies": { "jquery": ">=1.7.0" } -} \ No newline at end of file +} diff --git a/dist/css/magnify.css b/dist/css/magnify.css index 502fee8..42c5d54 100644 --- a/dist/css/magnify.css +++ b/dist/css/magnify.css @@ -41,4 +41,4 @@ html.magnifying > body { text-align: center; text-shadow: 0 0 2px rgba(51, 51, 51, 0.8); text-transform: none; -} \ No newline at end of file +} diff --git a/dist/js/jquery.magnify-mobile.js b/dist/js/jquery.magnify-mobile.js index ea7f350..28a975e 100644 --- a/dist/js/jquery.magnify-mobile.js +++ b/dist/js/jquery.magnify-mobile.js @@ -96,4 +96,4 @@ }); } }); -}(jQuery)); \ No newline at end of file +}(jQuery)); diff --git a/dist/js/jquery.magnify.js b/dist/js/jquery.magnify.js index 9e15690..56df2cb 100644 --- a/dist/js/jquery.magnify.js +++ b/dist/js/jquery.magnify.js @@ -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. @@ -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), @@ -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 @@ -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)); \ No newline at end of file +}(jQuery)); diff --git a/package.json b/package.json index d5af5d6..9f094a3 100644 --- a/package.json +++ b/package.json @@ -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", @@ -22,4 +22,4 @@ "type": "git", "url": "https://github.com/thdoan/magnify.git" } -} \ No newline at end of file +}