Skip to content

Commit

Permalink
fix: resize listener attachment/removing reference to the same function
Browse files Browse the repository at this point in the history
  • Loading branch information
rndmerle committed Oct 4, 2018
1 parent 8989b9a commit 0a52dfd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
14 changes: 7 additions & 7 deletions src/directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ function setInitialContent(el) {
}
}

function clampOnResize(el, clampValue) {
clampElement(el, clampValue);
}

function clampElement(el, clamp) {
// We use element-resize-detector to trigger the ellipsis.
// Element-resize-detector adds an inner div to monitor
Expand All @@ -58,7 +62,7 @@ function clampElement(el, clamp) {

defaults = _extends({}, defaults, { clamp: clamp ? clamp : 'auto' });

// Set the opactity to 0 to avoid content to flick when clamping.
// Set the opacity to 0 to avoid content to flick when clamping.
el.style.opacity = '0';
const result = clampy.clamp(el, defaults);

Expand All @@ -79,9 +83,7 @@ export default {
// });

// Also re-clamp on window resize
window.addEventListener('resize', () => {
clampElement(el, clampValue);
});
window.addEventListener('resize', clampOnResize);

clampElement(el, clampValue);
},
Expand All @@ -96,8 +98,6 @@ export default {

// Remove all listeners
// resizeDetector.removeAllListeners(el);
window.removeEventListener('resize', () => {
clampElement(el, clampValue);
});
window.removeEventListener('resize', clampOnResize);
}
};
14 changes: 7 additions & 7 deletions vue-clampy.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,10 @@ function setInitialContent(el) {
}
}

function clampOnResize(el, clampValue) {
clampElement(el, clampValue);
}

function clampElement(el, clamp) {
// We use element-resize-detector to trigger the ellipsis.
// Element-resize-detector adds an inner div to monitor
Expand All @@ -345,7 +349,7 @@ function clampElement(el, clamp) {

defaults = _extends({}, defaults, { clamp: clamp ? clamp : 'auto' });

// Set the opactity to 0 to avoid content to flick when clamping.
// Set the opacity to 0 to avoid content to flick when clamping.
el.style.opacity = '0';
var result = clampy.clamp(el, defaults);

Expand All @@ -366,9 +370,7 @@ var VueClampy$1 = {
// });

// Also re-clamp on window resize
window.addEventListener('resize', function () {
clampElement(el, clampValue);
});
window.addEventListener('resize', clampOnResize);

clampElement(el, clampValue);
},
Expand All @@ -381,9 +383,7 @@ var VueClampy$1 = {

// Remove all listeners
// resizeDetector.removeAllListeners(el);
window.removeEventListener('resize', function () {
clampElement(el, clampValue);
});
window.removeEventListener('resize', clampOnResize);
}
};

Expand Down

0 comments on commit 0a52dfd

Please sign in to comment.