Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the same function reference when attaching and removing event listener #6

Merged
merged 1 commit into from
Oct 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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