Skip to content

Commit 6fb9176

Browse files
authored
transpile to ES5 (#14)
* transpile to ES5 (#13) * Bump version
1 parent fbf8665 commit 6fb9176

File tree

4 files changed

+53
-33
lines changed

4 files changed

+53
-33
lines changed

.babelrc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"presets": [
3+
[
4+
"env",
5+
{
6+
"modules": false
7+
}
8+
]
9+
],
10+
"plugins": ["external-helpers"]
11+
}

dist/vue-line-clamp.umd.js

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,83 +4,83 @@
44
(global.VueLineClamp = factory());
55
}(this, (function () { 'use strict';
66

7-
const css = 'display:block;display:-webkit-box;-webkit-box-orient:vertical;overflow:hidden;text-overflow:ellipsis';
8-
const currentValueProp = "vLineClampValue";
7+
var css = 'display:block;display:-webkit-box;-webkit-box-orient:vertical;overflow:hidden;text-overflow:ellipsis';
8+
var currentValueProp = "vLineClampValue";
99

1010
function defaultFallbackFunc(el, bindings, lines) {
11-
if(lines){
12-
let lineHeight = parseInt(bindings.arg);
11+
if (lines) {
12+
var lineHeight = parseInt(bindings.arg);
1313
if (isNaN(lineHeight)) {
1414
console.warn('line-height argument for vue-line-clamp must be a number (of pixels), falling back to 16px');
1515
lineHeight = 16;
1616
}
1717

18-
let maxHeight = lineHeight * lines;
18+
var maxHeight = lineHeight * lines;
1919

20-
el.style.maxHeight = maxHeight ? maxHeight+'px' : '';
20+
el.style.maxHeight = maxHeight ? maxHeight + 'px' : '';
2121
el.style.overflowX = 'hidden';
22-
el.style.lineHeight = lineHeight+'px'; // to ensure consistency
22+
el.style.lineHeight = lineHeight + 'px'; // to ensure consistency
2323
} else {
2424
el.style.maxHeight = el.style.overflowX = '';
2525
}
2626
}
2727

28-
const truncateText = function (el, bindings, useFallbackFunc) {
29-
let lines = parseInt(bindings.value);
28+
var truncateText = function truncateText(el, bindings, useFallbackFunc) {
29+
var lines = parseInt(bindings.value);
3030
if (isNaN(lines)) {
3131
console.error('Parameter for vue-line-clamp must be a number');
32-
return
33-
}
34-
else if (lines !== el[currentValueProp]) {
32+
return;
33+
} else if (lines !== el[currentValueProp]) {
3534
el[currentValueProp] = lines;
3635

3736
if (useFallbackFunc) {
3837
useFallbackFunc(el, bindings, lines);
39-
}
40-
else {
38+
} else {
4139
el.style.webkitLineClamp = lines ? lines : '';
4240
}
4341
}
4442
};
4543

46-
const VueLineClamp = {
47-
install (Vue, options) {
44+
var VueLineClamp = {
45+
install: function install(Vue, options) {
4846
options = Object.assign({
4947
importCss: false
5048
}, options);
5149

5250
if (options.importCss) {
53-
const stylesheets = window.document.styleSheets,
54-
rule = `.vue-line-clamp{${css}}`;
51+
var stylesheets = window.document.styleSheets,
52+
rule = '.vue-line-clamp{' + css + '}';
5553
if (stylesheets && stylesheets[0] && stylesheets.insertRule) {
5654
stylesheets.insertRule(rule);
5755
} else {
58-
let link = window.document.createElement('style');
56+
var link = window.document.createElement('style');
5957
link.id = 'vue-line-clamp';
6058
link.appendChild(window.document.createTextNode(rule));
6159
window.document.head.appendChild(link);
6260
}
6361
}
6462

65-
const useFallbackFunc =
66-
"webkitLineClamp" in document.body.style
67-
? undefined
68-
: options.fallbackFunc || defaultFallbackFunc;
63+
var useFallbackFunc = "webkitLineClamp" in document.body.style ? undefined : options.fallbackFunc || defaultFallbackFunc;
6964

7065
Vue.directive('line-clamp', {
7166
currentValue: 0,
72-
bind (el) {
67+
bind: function bind(el) {
7368
if (!options.importCss) {
7469
el.style.cssText += css;
75-
}
76-
else {
70+
} else {
7771
el.classList.add('vue-line-clamp');
7872
}
73+
},
7974

75+
inserted: function inserted(el, bindings) {
76+
return truncateText(el, bindings, useFallbackFunc);
77+
},
78+
updated: function updated(el, bindings) {
79+
return truncateText(el, bindings, useFallbackFunc);
8080
},
81-
inserted: (el, bindings) => truncateText(el, bindings, useFallbackFunc),
82-
updated: (el, bindings) => truncateText(el, bindings, useFallbackFunc),
83-
componentUpdated: (el, bindings) => truncateText(el, bindings, useFallbackFunc)
81+
componentUpdated: function componentUpdated(el, bindings) {
82+
return truncateText(el, bindings, useFallbackFunc);
83+
}
8484
});
8585
}
8686
};

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-line-clamp",
3-
"version": "1.2.2",
3+
"version": "1.2.3",
44
"description": "A simple, fast and lightweight directive for truncating multi line texts using \"cross-browser\" CSS strategies.",
55
"main": "dist/vue-line-clamp.cjs.js",
66
"module": "dist/vue-line-clamp.esm.js",
@@ -10,11 +10,16 @@
1010
"dev": "rollup -c -w",
1111
"test": "jest",
1212
"pretest": "npm run build",
13-
"serve": "npm run build && cp dist/. dev/dist -r && node node_modules/watch-http-server/bin/http-server ./dev -a localhost -o"
13+
"serve": "npm run build && cp dist/. dev/dist -r && node node_modules/watch-http-server/bin/http-server ./dev -a localhost -o",
14+
"prepublishOnly": "npm run build"
1415
},
1516
"devDependencies": {
17+
"babel-core": "^6.26.0",
18+
"babel-plugin-external-helpers": "^6.22.0",
19+
"babel-preset-env": "^1.6.1",
1620
"jest": "^22.1.4",
1721
"rollup": "^0.50.0",
22+
"rollup-plugin-babel": "^3.0.3",
1823
"rollup-plugin-commonjs": "^8.2.6",
1924
"rollup-plugin-node-resolve": "^3.0.0",
2025
"watch-http-server": "^0.7.6"

rollup.config.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import resolve from 'rollup-plugin-node-resolve'
22
import commonjs from 'rollup-plugin-commonjs'
3+
import babel from 'rollup-plugin-babel';
34
import pkg from './package.json'
45

56
export default [
@@ -13,7 +14,10 @@ export default [
1314
},
1415
plugins: [
1516
resolve(), // so Rollup can find dependencies
16-
commonjs() // so Rollup can convert dependencies to ES modules
17+
commonjs(), // so Rollup can convert dependencies to ES modules
18+
babel({
19+
exclude: 'node_modules/**'
20+
})
1721
]
1822
},
1923

@@ -30,4 +34,4 @@ export default [
3034
{ file: pkg.module, format: 'es' }
3135
]
3236
}
33-
]
37+
]

0 commit comments

Comments
 (0)