Skip to content

Commit

Permalink
fix: Cannot use with multiple instances (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandremoore committed Jul 30, 2018
1 parent 9afd318 commit 919fb5b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
15 changes: 7 additions & 8 deletions src/directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@ import * as clampy_ from '@clampy-js/clampy/dist/clampy.umd.js';
// import * as elementResizeDetectorMaker_ from 'element-resize-detector';

// https://github.com/rollup/rollup/issues/670#issuecomment-284621537
const clampy = (clampy_).default || clampy_;
const clampy = clampy_.default || clampy_;
// const elementResizeDetectorMaker = (elementResizeDetectorMaker_).default || elementResizeDetectorMaker_;

// const resizeDetector = elementResizeDetectorMaker({ strategy: 'scroll' });
var initialContent;
var clampValue;

function setInitialContent(el) {
if (initialContent === undefined) {
initialContent = el.innerHTML.trim();
if (el.clampInitialContent === undefined) {
el.clampInitialContent = el.innerHTML.trim();
}
}

Expand All @@ -27,8 +26,8 @@ function clampElement(el, clamp) {

setInitialContent(el);

if (initialContent !== undefined) {
el.innerHTML = initialContent;
if (el.clampInitialContent !== undefined) {
el.innerHTML = el.clampInitialContent;
}

const options = {
Expand All @@ -37,7 +36,7 @@ function clampElement(el, clamp) {
// Clampy will try to use native clamp if available in the browser
// however this can leads to unexpected results so we need to explicitely
// disable it.
useNativeClamp: false,
useNativeClamp: false
};

// Set the opactity to 0 to avoid content to flick when clamping.
Expand Down Expand Up @@ -81,5 +80,5 @@ export default {
window.removeEventListener('resize', () => {
clampElement(el, clampValue);
});
},
}
};
9 changes: 4 additions & 5 deletions vue-clampy.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,12 +294,11 @@ var clampy = clampy_umd$1 || clampy_;
// const elementResizeDetectorMaker = (elementResizeDetectorMaker_).default || elementResizeDetectorMaker_;

// const resizeDetector = elementResizeDetectorMaker({ strategy: 'scroll' });
var initialContent;
var clampValue;

function setInitialContent(el) {
if (initialContent === undefined) {
initialContent = el.innerHTML.trim();
if (el.clampInitialContent === undefined) {
el.clampInitialContent = el.innerHTML.trim();
}
}

Expand All @@ -315,8 +314,8 @@ function clampElement(el, clamp) {

setInitialContent(el);

if (initialContent !== undefined) {
el.innerHTML = initialContent;
if (el.clampInitialContent !== undefined) {
el.innerHTML = el.clampInitialContent;
}

var options = {
Expand Down

0 comments on commit 919fb5b

Please sign in to comment.