Skip to content

Commit 2bc1d6e

Browse files
authored
Fix callback (#16)
* Fixing callback bug * Update Demo * Code cleanup * Add gh-pages
1 parent 8af214b commit 2bc1d6e

File tree

8 files changed

+6830
-135
lines changed

8 files changed

+6830
-135
lines changed

lib/index.js

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen
3232

3333
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
3434

35-
console.log(_tween2.default);
36-
3735
var EASING = {
3836
'ease': _tween2.default.Easing.Quadratic.InOut,
3937
'ease-in': _tween2.default.Easing.Cubic.In,
@@ -52,12 +50,12 @@ var MtSvgLines = function (_React$Component) {
5250

5351
var _this = _possibleConstructorReturn(this, (MtSvgLines.__proto__ || Object.getPrototypeOf(MtSvgLines)).call(this, props));
5452

55-
_this._onTweenUpdate = function () {
56-
_this._setStrokeDashoffset(_this._pathElems, _this._tweenData);
57-
_this._animate(); // go again..
53+
_this.onTweenUpdate = function () {
54+
_this.setStrokeDashoffset(_this._pathElems, _this._tweenData);
55+
_this.animate(); // go again..
5856
};
5957

60-
_this._onAnimComplete = function () {
58+
_this.onAnimComplete = function () {
6159
_this.props.callback();
6260
_this._animStart = 0;
6361
};
@@ -95,12 +93,12 @@ var MtSvgLines = function (_React$Component) {
9593
}, {
9694
key: 'componentDidMount',
9795
value: function componentDidMount() {
98-
this._animate();
96+
this.animate();
9997
}
10098
}, {
10199
key: 'componentDidUpdate',
102100
value: function componentDidUpdate() {
103-
this._animate();
101+
this.animate();
104102
}
105103
}, {
106104
key: 'render',
@@ -156,8 +154,8 @@ var MtSvgLines = function (_React$Component) {
156154
*/
157155

158156
}, {
159-
key: '_animate',
160-
value: function _animate() {
157+
key: 'animate',
158+
value: function animate() {
161159
var _this3 = this;
162160

163161
if (typeof window === 'undefined') {
@@ -185,7 +183,7 @@ var MtSvgLines = function (_React$Component) {
185183

186184
// parse out vars common for both modes
187185
var startDelay = typeof animate === 'number' ? animate : 0; // if numeric, treat as delay (ms)
188-
var numOfRepeats = parseInt(playback, 10) || 0;
186+
var numOfRepeats = parseInt(playback, 10) || 1;
189187

190188
/* ----- JS MODE ----- */
191189
if (isAnimJS) {
@@ -199,8 +197,8 @@ var MtSvgLines = function (_React$Component) {
199197
var isYoYo = playback.includes('alternate');
200198

201199
// acquire path elems and generate to/from data sets
202-
this._pathElems = this._selectPathElems();
203-
var pathData = this._getPathData(this._pathElems);
200+
this._pathElems = this.selectPathElems();
201+
var pathData = this.getPathData(this._pathElems);
204202
this._pathDataFrom = pathData.from;
205203
this._pathDataTo = pathData.to;
206204

@@ -210,11 +208,11 @@ var MtSvgLines = function (_React$Component) {
210208
this._tweenData = _extends({}, this._pathDataFrom);
211209

212210
// set paths' offsets to start positions
213-
this._setStrokeDasharray(this._pathElems, this._pathDataFrom);
214-
this._setStrokeDashoffset(this._pathElems, this._tweenData);
211+
this.setStrokeDasharray(this._pathElems, this._pathDataFrom);
212+
this.setStrokeDashoffset(this._pathElems, this._tweenData);
215213

216214
// init the tweener..
217-
var tween = new _tween2.default.Tween(this._tweenData).to(this._pathDataTo, duration).easing(EASING[timing]).repeat(numOfRepeats).yoyo(isYoYo).onUpdate(this._onTweenUpdate).onComplete(this._onAnimComplete);
215+
var tween = new _tween2.default.Tween(this._tweenData).to(this._pathDataTo, duration).easing(EASING[timing]).repeat(numOfRepeats).yoyo(isYoYo).onUpdate(this.onTweenUpdate).onComplete(this.onAnimComplete);
218216

219217
// kick off JS tweening..
220218
var t = setTimeout(function () {
@@ -228,7 +226,7 @@ var MtSvgLines = function (_React$Component) {
228226
var css = '';
229227

230228
// 1) determine number of path elems in svg
231-
var pathLenghts = this._getPathLengths();
229+
var pathLenghts = this.getPathLengths();
232230
var pathQty = pathLenghts.length || 1;
233231

234232
// 2) calc all timing values
@@ -238,13 +236,13 @@ var MtSvgLines = function (_React$Component) {
238236

239237
// 3) concat generated CSS, one path at a time..
240238
pathLenghts.forEach(function (length, index) {
241-
css += _this3._getPathCSS(index, length, startDelay, pathStaggerDelay, pathDrawDuration);
239+
css += _this3.getPathCss(index, length, startDelay, pathStaggerDelay, pathDrawDuration);
242240
});
243241

244242
// set up on-complete timer
245243
var _t = setTimeout(function () {
246244
clearTimeout(_t);
247-
_this3._onAnimComplete();
245+
_this3.onAnimComplete();
248246
}, startDelay + duration * numOfRepeats);
249247

250248
// set state (re-render)
@@ -274,13 +272,13 @@ var MtSvgLines = function (_React$Component) {
274272
*/
275273

276274
}, {
277-
key: '_selectPathElems',
275+
key: 'selectPathElems',
278276

279277

280278
/*
281279
* Acquire selection of SVG 'path' elems contained within
282280
*/
283-
value: function _selectPathElems() {
281+
value: function selectPathElems() {
284282
var svgEl = this._svgWrapper.getElementsByTagName('svg')[0];
285283
return svgEl ? svgEl.querySelectorAll('path') : [];
286284
}
@@ -293,14 +291,14 @@ var MtSvgLines = function (_React$Component) {
293291
*/
294292

295293
}, {
296-
key: '_getPathData',
297-
value: function _getPathData(pathElems) {
294+
key: 'getPathData',
295+
value: function getPathData(pathElems) {
298296
var _this4 = this;
299297

300298
var pathData = { from: {}, to: {} };
301299

302300
[].forEach.call(pathElems, function (pathEl, i) {
303-
if (!_this4._hasSkipAttr(pathEl.attributes)) {
301+
if (!_this4.hasSkipAttr(pathEl.attributes)) {
304302
var pathLengh = (0, _utils.trimFloat)(pathEl.getTotalLength() || 0);
305303
pathData.to[i] = 0;
306304
pathData.from[i] = pathLengh;
@@ -315,8 +313,8 @@ var MtSvgLines = function (_React$Component) {
315313
*/
316314

317315
}, {
318-
key: '_hasSkipAttr',
319-
value: function _hasSkipAttr(attributes) {
316+
key: 'hasSkipAttr',
317+
value: function hasSkipAttr(attributes) {
320318
var result = false;
321319

322320
// path.attributes is an obj with indexed keys, so we must iterate over them
@@ -340,8 +338,8 @@ var MtSvgLines = function (_React$Component) {
340338
*/
341339

342340
}, {
343-
key: '_setStrokeDasharray',
344-
value: function _setStrokeDasharray(pathElems, pathData) {
341+
key: 'setStrokeDasharray',
342+
value: function setStrokeDasharray(pathElems, pathData) {
345343
[].forEach.call(pathElems, function (pathEl, i) {
346344
if (pathData[i]) {
347345
pathEl.style.strokeDasharray = pathData[i];
@@ -354,8 +352,8 @@ var MtSvgLines = function (_React$Component) {
354352
*/
355353

356354
}, {
357-
key: '_setStrokeDashoffset',
358-
value: function _setStrokeDashoffset(pathElems, pathData) {
355+
key: 'setStrokeDashoffset',
356+
value: function setStrokeDashoffset(pathElems, pathData) {
359357
[].forEach.call(pathElems, function (pathEl, i) {
360358
if (pathData[i]) {
361359
pathEl.style.strokeDashoffset = pathData[i];
@@ -368,13 +366,13 @@ var MtSvgLines = function (_React$Component) {
368366
*/
369367

370368
}, {
371-
key: '_getPathLengths',
372-
value: function _getPathLengths() {
369+
key: 'getPathLengths',
370+
value: function getPathLengths() {
373371
var _this5 = this;
374372

375-
var pathElems = this._selectPathElems();
373+
var pathElems = this.selectPathElems();
376374
return [].map.call(pathElems, function (pathEl) {
377-
return _this5._hasSkipAttr(pathEl.attributes) ? 0 : (0, _utils.trimFloat)(pathEl.getTotalLength() || 0);
375+
return _this5.hasSkipAttr(pathEl.attributes) ? 0 : (0, _utils.trimFloat)(pathEl.getTotalLength() || 0);
378376
});
379377
}
380378

@@ -383,8 +381,8 @@ var MtSvgLines = function (_React$Component) {
383381
*/
384382

385383
}, {
386-
key: '_getPathCSS',
387-
value: function _getPathCSS(index, length, startDelay, staggerDelay, duration) {
384+
key: 'getPathCss',
385+
value: function getPathCss(index, length, startDelay, staggerDelay, duration) {
388386
var classKey = this.state.classKey;
389387
var _props3 = this.props,
390388
timing = _props3.timing,

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"scripts": {
2323
"start": "webpack-dev-server --content-base src/demos/",
2424
"build": "rimraf public && webpack --progress --profile --colors",
25+
"deploy": "gh-pages -d public",
2526
"lint": "eslint src",
2627
"dist": "babel src --out-dir lib --ignore demos",
2728
"prepublish": "npm run dist"
@@ -56,6 +57,7 @@
5657
"eslint-plugin-standard": "^3.0.1",
5758
"extract-text-webpack-plugin": "^3.0.0",
5859
"file-loader": "^0.11.2",
60+
"gh-pages": "^1.1.0",
5961
"html-webpack-plugin": "^2.22.0",
6062
"node-sass": "^4.5.1",
6163
"postcss-loader": "^2.0.6",
@@ -65,6 +67,7 @@
6567
"react-hot-loader": "^1.3.0",
6668
"rimraf": "^2.5.3",
6769
"sass-loader": "^6.0.3",
70+
"standard": "^11.0.1",
6871
"style-loader": "^0.18.2",
6972
"url-loader": "^0.5.7",
7073
"webpack": "^3.4.1",

public/198c3f51bb9eef0d4a89.min.js

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@import url(http://fonts.googleapis.com/css?family=Lato:200,300,700);body {
2+
font: 200 normal 16px 'Lato', sans-serif;
3+
background-color: #FFF; }
4+
5+
@media (max-width: 380px) {
6+
.column, .column-short {
7+
width: 100% !important; } }

public/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
<title>Mt React Component</title>
88
<meta name="description" content="Mt React Component" />
99
<meta name="author" content="moarwick" />
10-
<link href="css/31fe4b16aaf57ce15b5e.min.css" rel="stylesheet"></head>
10+
<link href="css/198c3f51bb9eef0d4a89.min.css" rel="stylesheet"></head>
1111
<body>
1212
<div id="component"></div>
13-
<script type="text/javascript" src="31fe4b16aaf57ce15b5e.min.js"></script></body>
13+
<script type="text/javascript" src="198c3f51bb9eef0d4a89.min.js"></script></body>
1414
</html>

0 commit comments

Comments
 (0)