Skip to content

Commit

Permalink
fix: setDefaults is not defined when passing options (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandremoore committed Jul 31, 2018
1 parent 919fb5b commit 6a08520
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 67 deletions.
37 changes: 28 additions & 9 deletions src/directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,32 @@ const clampy = clampy_.default || clampy_;
// const resizeDetector = elementResizeDetectorMaker({ strategy: 'scroll' });
var clampValue;

var _extends = Object.assign ||
function(target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];

for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}

return target;
};

var defaults = {
clamp: 'auto',
truncationChar: '…',
splitOnChars: ['.', '-', '–', '—', ' '],
useNativeClamp: false
};

export function setDefaults(options) {
defaults = _extends({}, defaults, options);
}

function setInitialContent(el) {
if (el.clampInitialContent === undefined) {
el.clampInitialContent = el.innerHTML.trim();
Expand All @@ -30,18 +56,11 @@ function clampElement(el, clamp) {
el.innerHTML = el.clampInitialContent;
}

const options = {
clamp: clamp ? clamp : 'auto',
truncationChar: '…',
// 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
};
defaults = _extends({}, defaults, { clamp: clamp ? clamp : 'auto' });

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

// Set the opacity back to 1 now that the content is clamped.
el.style.opacity = '1';
Expand Down
26 changes: 1 addition & 25 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,5 @@
import VueClampy from './directive';

var _extends = Object.assign ||
function(target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];

for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}

return target;
};

var defaults = {
clamp: 'auto',
truncationChar: '…',
splitOnChars: ['.', '-', '–', '—', ' ']
};

function setDefaults(options) {
defaults = _extends({}, defaults, options);
}
import { setDefaults } from './directive';

const install = function(Vue, options) {
if (options) setDefaults(options);
Expand Down
60 changes: 27 additions & 33 deletions vue-clampy.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,31 @@ var clampy = clampy_umd$1 || clampy_;
// const resizeDetector = elementResizeDetectorMaker({ strategy: 'scroll' });
var clampValue;

var _extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];

for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}

return target;
};

var defaults = {
clamp: 'auto',
truncationChar: '…',
splitOnChars: ['.', '-', '–', '—', ' '],
useNativeClamp: false
};

function setDefaults(options) {
defaults = _extends({}, defaults, options);
}

function setInitialContent(el) {
if (el.clampInitialContent === undefined) {
el.clampInitialContent = el.innerHTML.trim();
Expand All @@ -318,18 +343,11 @@ function clampElement(el, clamp) {
el.innerHTML = el.clampInitialContent;
}

var options = {
clamp: clamp ? clamp : 'auto',
truncationChar: '…',
// 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
};
defaults = _extends({}, defaults, { clamp: clamp ? clamp : 'auto' });

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

// Set the opacity back to 1 now that the content is clamped.
el.style.opacity = '1';
Expand Down Expand Up @@ -369,30 +387,6 @@ var VueClampy$1 = {
}
};

var _extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];

for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}

return target;
};

var defaults = {
clamp: 'auto',
truncationChar: '…',
splitOnChars: ['.', '-', '–', '—', ' ']
};

function setDefaults(options) {
defaults = _extends({}, defaults, options);
}

var install = function install(Vue, options) {
if (options) setDefaults(options);
Vue.directive('clampy', VueClampy$1);
Expand Down

0 comments on commit 6a08520

Please sign in to comment.