From 44381ae3cfff7ac0c9e69aeb71ff190d46c6b86a Mon Sep 17 00:00:00 2001 From: Growiel Date: Thu, 19 May 2016 10:17:56 +0900 Subject: [PATCH 1/2] Fix Hammerjs unbind events Making the hammerjs instance a property of cropbox so we can properly unbind the events in .remove(); --- jquery.cropbox.js | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/jquery.cropbox.js b/jquery.cropbox.js index bcb8b1d..f01dbfa 100644 --- a/jquery.cropbox.js +++ b/jquery.cropbox.js @@ -57,16 +57,17 @@ this.updateOptions(); if (typeof $.fn.hammer === 'function' || typeof Hammer !== 'undefined') { - var hammerit, dragData; + this.hammerit; + var dragData; if (typeof $.fn.hammer === 'function') - hammerit = this.$image.hammer().data('hammer'); // Get the hammer instance after it has been created. + this.hammerit = this.$image.hammer().data('hammer'); // Get the hammer instance after it has been created. else - hammerit = Hammer(this.$image.get(0)); + this.hammerit = Hammer(this.$image.get(0)); // Enable panning in all directions without any threshold. - hammerit.get('pan').set({ direction: Hammer.DIRECTION_ALL, threshold: 0 }); + this.hammerit.get('pan').set({ direction: Hammer.DIRECTION_ALL, threshold: 0 }); // Enable pinching. - hammerit.get('pinch').set({ enable: true }); - hammerit.on('panleft panright panup pandown', function(e) { + this.hammerit.get('pinch').set({ enable: true }); + this.hammerit.on('panleft panright panup pandown', function(e) { if (!dragData) dragData = { startX: self.img_left, @@ -158,13 +159,8 @@ }, remove: function () { - var hammerit; - if (typeof $.fn.hammer === 'function') - hammerit = this.$image.data('hammer'); // Get hammer instance object. - else if (typeof Hammer !== 'undefined') - hammerit = Hammer(this.$image.get(0)); - if (hammerit) - hammerit.off('panleft panright panup pandown panend pancancel doubletap pinchin pinchout'); + if (this.hammerit) + this.hammerit.off('panleft panright panup pandown panend pancancel doubletap pinchin pinchout'); this.$frame.off('.' + pluginName); this.$image.off('.' + pluginName); this.$image.css({width: '', left: '', top: ''}); From e714ddab3789779abb6eb11844ed809a35ec14df Mon Sep 17 00:00:00 2001 From: Growiel Date: Thu, 19 May 2016 11:07:22 +0900 Subject: [PATCH 2/2] Removed un-necessary this.hammerit --- jquery.cropbox.js | 1 - 1 file changed, 1 deletion(-) diff --git a/jquery.cropbox.js b/jquery.cropbox.js index f01dbfa..f772048 100644 --- a/jquery.cropbox.js +++ b/jquery.cropbox.js @@ -57,7 +57,6 @@ this.updateOptions(); if (typeof $.fn.hammer === 'function' || typeof Hammer !== 'undefined') { - this.hammerit; var dragData; if (typeof $.fn.hammer === 'function') this.hammerit = this.$image.hammer().data('hammer'); // Get the hammer instance after it has been created.