Skip to content

Commit e6fd7da

Browse files
committed
Version bump.
Fix for zoom container bug. Destroy zoom container if $destroy was too late.
1 parent 58cd80e commit e6fd7da

4 files changed

Lines changed: 53 additions & 17 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<a name="1.0.0"></a>
22

3+
# 1.1.18c (2016-07-06)
4+
- Fix for zoom container bug. Destroy zoom container if $destroy was too late.
5+
36
# 1.1.18b (2016-17-05)
47
- Fix for zoom container bug. Destroy old plugin before updating the the plugin when using dynamic options
58

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-ez-plus",
3-
"version": "1.1.18b",
3+
"version": "1.1.18c",
44
"author": {
55
"name": "Igor Lino",
66
"url": "http://igorlino.github.io/angular-elevatezoom-plus/"

js/angular-ezplus.js

Lines changed: 48 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
angular.module('ezplus', [])
55
.directive('ezPlus', ezPlus);
66

7-
function ezPlus() {
7+
function ezPlus($document) {
88
var service = {
99
restrict: 'A',
1010
scope: {
@@ -27,6 +27,8 @@
2727
link.$inject = ['$scope', '$element', '$attributes'];
2828
function link($scope, $element, $attributes) {
2929
var bootstrapped = false;
30+
var lastPlugin = null;
31+
var zoomIds = {};
3032
var options = {
3133
onComplete: function () {
3234
if ($scope.onComplete && $scope.onComplete()) {
@@ -86,13 +88,13 @@
8688
showZoom();
8789
});
8890
$scope.$on('ezp-disableZoom', function (e, msg) {
89-
var plugin = angular.element($element).data('ezPlus');
91+
var plugin = getZoomPlugin();
9092
if (plugin) {
9193
plugin.changeState('disable');
9294
}
9395
});
9496
$scope.$on('ezp-enableZoom', function (e, msg) {
95-
var plugin = angular.element($element).data('ezPlus');
97+
var plugin = getZoomPlugin();
9698
if (plugin) {
9799
plugin.changeState('enable');
98100
}
@@ -102,11 +104,11 @@
102104
if (!bootstrapped) {
103105
bootstrapped = true;
104106
} else {
105-
var plugin = angular.element($element).data('ezPlus');
107+
var plugin = getZoomPlugin();
106108
plugin.destroy();
107109
angular.extend(options, $scope.ezpOptions);
108110
if (plugin) {
109-
angular.element($element).ezPlus(options);
111+
preparePlugin($element, options);
110112
}
111113
}
112114
}, true);
@@ -116,15 +118,16 @@
116118
var smallUrl = (image && image.small) || '';
117119
var largeUrl = (image && image.large) || '';
118120

119-
var plugin = angular.element($element).data('ezPlus');
121+
var initialUrl = null;
122+
var plugin = getZoomPlugin();
120123
if (plugin) {
121124
if (image) {
122125
hideZoom();
123126
if (loader) {
124127
plugin.swaptheimage(loader, loader);
125128
}
126129

127-
var initialUrl = getInitialUrl(smallUrl);
130+
initialUrl = getInitialUrl(options, smallUrl);
128131
plugin.swaptheimage(initialUrl, largeUrl);
129132
showZoom();
130133
} else {
@@ -133,18 +136,18 @@
133136
} else {
134137
if (image) {
135138

136-
var initialUrl = getInitialUrl();
139+
initialUrl = getInitialUrl(options);
137140
if (initialUrl) {
138141
$element.attr('src', initialUrl);
139142
}
140143

141144
$element.attr('data-zoom-image', largeUrl);
142145

143-
angular.element($element).ezPlus(options);
146+
preparePlugin($element, options);
144147
}
145148
}
146149

147-
function getInitialUrl(defaultUrl) {
150+
function getInitialUrl(options, defaultUrl) {
148151
var initialUrl = defaultUrl;
149152
if (options.initial === 'thumb') {
150153
initialUrl = thumbUrl;
@@ -157,16 +160,46 @@
157160
}
158161
});
159162

160-
$scope.$on('$destroy', function () {
161-
var plugin = angular.element($element).data('ezPlus');
163+
$scope.$on('$destroy', destroyPlugin);
164+
165+
function destroyPlugin() {
166+
var plugin = getZoomPlugin();
162167
if (plugin) {
163168
plugin.destroy();
164169
}
165-
});
170+
171+
//in case the $destroy is called after the actual plugin element was removed, otherwise zoom containers
172+
//will be visible.
173+
for (var zoomId in zoomIds) {
174+
if (zoomIds.hasOwnProperty(zoomId)) {
175+
var zoomContainer = findZoomContainer(zoomId);
176+
zoomContainer.remove();
177+
}
178+
}
179+
zoomIds = {};
180+
}
181+
182+
function findZoomContainer(uuid) {
183+
return angular.element($document).find('[uuid=' + uuid + ']');
184+
}
185+
186+
function preparePlugin(element, options) {
187+
var plugin = angular.element(element).ezPlus(options);
188+
lastPlugin = plugin && plugin.length > 0 ? getZoomPlugin(plugin[0]) : null;
189+
if (lastPlugin) {
190+
zoomIds[lastPlugin.options.zoomId] = true;
191+
}
192+
return lastPlugin;
193+
}
194+
195+
function getZoomPlugin(element) {
196+
var plugin = angular.element(element ? element : $element).data('ezPlus');
197+
return plugin;
198+
}
166199

167200
function hideZoom() {
168201
var action = 'hide';
169-
var plugin = angular.element($element).data('ezPlus');
202+
var plugin = getZoomPlugin();
170203
if (plugin) {
171204
plugin.showHideZoomContainer(action);
172205
/*plugin.showHideWindow(action);
@@ -177,7 +210,7 @@
177210

178211
function showZoom() {
179212
var action = 'show';
180-
var plugin = angular.element($element).data('ezPlus');
213+
var plugin = getZoomPlugin();
181214
if (plugin) {
182215
/*plugin.showHideLens(action);
183216
plugin.showHideTint(action);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-ez-plus",
3-
"version": "1.1.18b",
3+
"version": "1.1.18c",
44
"title": "Angular EZ Plus",
55
"description": "Angular directive for ElevateZoom Plus.",
66
"keywords": [

0 commit comments

Comments
 (0)