Skip to content

Commit 5e6d413

Browse files
committed
Add ESLint and reformat files
1 parent e68bc39 commit 5e6d413

28 files changed

+1065
-286
lines changed

.eslintrc.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
module.exports = {
2+
'rules': {
3+
'quotes': [1, 'single'],
4+
'semi': [1, 'always'],
5+
'strict': [1, 'global'],
6+
'indent': [1, 'tab', {
7+
'SwitchCase': 1,
8+
'VariableDeclarator': 0,
9+
'CallExpression': { 'arguments': 1 },
10+
}],
11+
'no-whitespace-before-property': 2,
12+
'keyword-spacing': [1, {
13+
before: true,
14+
after: true,
15+
overrides: { 'switch': { after: false } }
16+
}],
17+
'array-bracket-spacing': [1, 'never'],
18+
'object-curly-spacing': [1, 'always'],
19+
'space-before-function-paren': [1, 'never'],
20+
'no-console': 1,
21+
'no-debugger': 1,
22+
'no-extra-semi': 1,
23+
'semi-spacing': 1,
24+
'no-unneeded-ternary': 1,
25+
'no-mixed-spaces-and-tabs': [1, 'smart-tabs'],
26+
}
27+
};

.travis.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
language: node_js
22
node_js:
3-
- "8.11.2"
4-
- "6"
3+
- "10.13.0"
4+
- "8.12.0"
5+
- "6.14.4"
56
script:
67
- gulp && npm test
78
after_success:

dist/granim.js

+62-88
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ function Granim(options) {
3434
this.isCanvasInWindowView = false;
3535
this.firstScrollInit = true;
3636
this.animating = false;
37+
this.gradientLength = this.states[this.activeState].gradients[0].length;
3738
if (options.image && options.image.source) {
3839
this.image = {
3940
source: options.image.source,
@@ -42,7 +43,6 @@ function Granim(options) {
4243
blendingMode: options.image.blendingMode || false
4344
};
4445
}
45-
4646
this.events = {
4747
start: new CustomEvent('granim:start'),
4848
end: new CustomEvent('granim:end'),
@@ -56,7 +56,7 @@ function Granim(options) {
5656
},
5757
bubbles: false,
5858
cancelable: false
59-
})
59+
});
6060
}
6161
};
6262
this.callbacks = {
@@ -82,6 +82,7 @@ function Granim(options) {
8282

8383
if (this.isPausedWhenNotInView) {
8484
this.onScroll();
85+
8586
} else {
8687
if (!this.image) {
8788
this.refreshColorsAndPos();
@@ -95,65 +96,36 @@ function Granim(options) {
9596
this.canvas.dispatchEvent(this.events.start);
9697
}
9798

98-
Granim.prototype.onResize = require('./onResize.js');
99-
100-
Granim.prototype.onScroll = require('./onScroll.js');
101-
102-
Granim.prototype.validateInput = require('./validateInput.js');
103-
104-
Granim.prototype.triggerError = require('./triggerError.js');
105-
99+
Granim.prototype.animateColors = require('./animateColors.js');
100+
Granim.prototype.changeBlendingMode = require('./changeBlendingMode.js');
101+
Granim.prototype.changeDirection = require('./changeDirection.js');
102+
Granim.prototype.changeState = require('./changeState.js');
103+
Granim.prototype.clear = require('./clear.js');
106104
Granim.prototype.convertColorToRgba = require('./convertColorToRgba.js');
107-
108-
Granim.prototype.prepareImage = require('./prepareImage.js');
109-
105+
Granim.prototype.destroy = require('./destroy.js');
110106
Granim.prototype.eventPolyfill = require('./eventPolyfill.js');
111-
112107
Granim.prototype.getColor = require('./getColor.js');
113-
114-
Granim.prototype.getColorPos = require('./getColorPos.js');
115-
116108
Granim.prototype.getColorDiff = require('./getColorDiff.js');
117-
109+
Granim.prototype.getColorPos = require('./getColorPos.js');
118110
Granim.prototype.getColorPosDiff = require('./getColorPosDiff.js');
119-
120-
Granim.prototype.setDirection = require('./setDirection.js');
121-
122-
Granim.prototype.setColors = require('./setColors.js');
123-
124-
Granim.prototype.getElement = require('./getElement.js');
125-
126-
Granim.prototype.getDimensions = require('./getDimensions.js');
127-
128-
Granim.prototype.getLightness = require('./getLightness.js');
129-
130111
Granim.prototype.getCurrentColors = require('./getCurrentColors.js');
131-
132112
Granim.prototype.getCurrentColorsPos = require('./getCurrentColorsPos.js');
133-
134-
Granim.prototype.animateColors = require('./animateColors.js');
135-
136-
Granim.prototype.refreshColorsAndPos = require('./refreshColorsAndPos.js');
137-
113+
Granim.prototype.getDimensions = require('./getDimensions.js');
114+
Granim.prototype.getElement = require('./getElement.js');
115+
Granim.prototype.getLightness = require('./getLightness.js');
138116
Granim.prototype.makeGradient = require('./makeGradient.js');
139-
117+
Granim.prototype.onResize = require('./onResize.js');
118+
Granim.prototype.onScroll = require('./onScroll.js');
140119
Granim.prototype.pause = require('./pause.js');
141-
142-
Granim.prototype.play = require('./play.js');
143-
144-
Granim.prototype.clear = require('./clear.js');
145-
146-
Granim.prototype.destroy = require('./destroy.js');
147-
148120
Granim.prototype.pauseWhenNotInView = require('./pauseWhenNotInView.js');
149-
121+
Granim.prototype.play = require('./play.js');
122+
Granim.prototype.prepareImage = require('./prepareImage.js');
123+
Granim.prototype.refreshColorsAndPos = require('./refreshColorsAndPos.js');
124+
Granim.prototype.setColors = require('./setColors.js');
125+
Granim.prototype.setDirection = require('./setDirection.js');
150126
Granim.prototype.setSizeAttributes = require('./setSizeAttributes.js');
151-
152-
Granim.prototype.changeDirection = require('./changeDirection.js');
153-
154-
Granim.prototype.changeBlendingMode = require('./changeBlendingMode.js');
155-
156-
Granim.prototype.changeState = require('./changeState.js');
127+
Granim.prototype.triggerError = require('./triggerError.js');
128+
Granim.prototype.validateInput = require('./validateInput.js');
157129

158130
module.exports = Granim;
159131

@@ -217,20 +189,21 @@ module.exports = function(timestamp) {
217189
this.animation = requestAnimationFrame(this.animateColors.bind(this));
218190

219191
// Callback and Event
220-
if (this.callbacks.onGradientChange) this.callbacks.onGradientChange({
221-
isLooping: isLooping,
222-
colorsFrom: this.states[this.activeState].gradients[this.channelsIndex],
223-
colorsTo: nextGradient,
224-
activeState: this.activeState
225-
});
226-
227-
this.canvas.dispatchEvent(this.events.gradientChange({
192+
if (this.callbacks.onGradientChange) {
193+
this.callbacks.onGradientChange({
228194
isLooping: isLooping,
229195
colorsFrom: this.states[this.activeState].gradients[this.channelsIndex],
230196
colorsTo: nextGradient,
231197
activeState: this.activeState
232-
})
233-
);
198+
});
199+
}
200+
201+
this.canvas.dispatchEvent(this.events.gradientChange({
202+
isLooping: isLooping,
203+
colorsFrom: this.states[this.activeState].gradients[this.channelsIndex],
204+
colorsTo: nextGradient,
205+
activeState: this.activeState
206+
}));
234207

235208
// Else if it was the last gradient on the list and the loop mode is off
236209
} else {
@@ -322,7 +295,7 @@ module.exports = function() {
322295
};
323296

324297
},{}],7:[function(require,module,exports){
325-
'use strict'
298+
'use strict';
326299

327300
var regex = {
328301
hexa: /^#(?:[0-9a-fA-F]{3}){1,2}$/,
@@ -382,7 +355,7 @@ function identifyColorType(color) {
382355
if (match) return colorTypes[i];
383356
}
384357
return false;
385-
};
358+
}
386359

387360
function hexToRgba(hex) {
388361
// Expand shorthand form (e.g. '03F') to full form (e.g. '0033FF')
@@ -397,7 +370,7 @@ function hexToRgba(hex) {
397370
parseInt(result[3], 16),
398371
1
399372
] : null;
400-
};
373+
}
401374

402375
function hue2rgb(p, q, t) {
403376
if (t < 0) t += 1;
@@ -406,7 +379,7 @@ function hue2rgb(p, q, t) {
406379
if (t < 1 / 2) return q;
407380
if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
408381
return p;
409-
};
382+
}
410383

411384
function hslaToRgb(h, s, l, a) {
412385
var r, g, b, q, p;
@@ -420,7 +393,7 @@ function hslaToRgb(h, s, l, a) {
420393
b = hue2rgb(p, q, h - 1/3);
421394
}
422395
return [Math.round(r * 255), Math.round(g * 255), Math.round(b * 255), a];
423-
};
396+
}
424397

425398
},{}],8:[function(require,module,exports){
426399
'use strict';
@@ -435,7 +408,7 @@ module.exports = function() {
435408
'use strict';
436409

437410
module.exports = function() {
438-
if ( typeof window.CustomEvent === "function" ) return;
411+
if ( typeof window.CustomEvent === 'function' ) return;
439412

440413
function CustomEvent(event, params) {
441414
params = params || { bubbles: false, cancelable: false, detail: undefined };
@@ -468,11 +441,11 @@ module.exports = function(gradientColor) {
468441
'use strict';
469442

470443
module.exports = function(colorA, colorB) {
471-
var i;
444+
var i = 0;
472445
var colorDiff = [];
473446

474-
for (i = 0; i < 4; i++) {
475-
colorDiff.push(colorB[i] - colorA[i])
447+
for (i; i < 4; i++) {
448+
colorDiff.push(colorB[i] - colorA[i]);
476449
}
477450

478451
return colorDiff;
@@ -487,9 +460,7 @@ module.exports = function(gradientColor, i) {
487460

488461
} else {
489462
// Ensure first and last position to be 0 and 100
490-
return parseFloat(
491-
!i ? 0 : ((1 / (this.states[this.activeState].gradients[0].length - 1)) * i
492-
).toFixed(2));
463+
return parseFloat(!i ? 0 : ((1 / (this.gradientLength - 1)) * i).toFixed(2));
493464
}
494465
};
495466

@@ -511,7 +482,7 @@ module.exports = function() {
511482
currentColors.push([]);
512483

513484
for (j = 0; j < 4; j++) {
514-
currentColors[i].push(this.currentColors[i][j])
485+
currentColors[i].push(this.currentColors[i][j]);
515486
}
516487
}
517488

@@ -548,7 +519,7 @@ module.exports = function(element) {
548519
if (element instanceof HTMLCanvasElement) {
549520
this.canvas = element;
550521

551-
} else if (typeof element === "string") {
522+
} else if (typeof element === 'string') {
552523
this.canvas = document.querySelector(element);
553524

554525
} else {
@@ -593,9 +564,9 @@ module.exports = function() {
593564
'use strict';
594565

595566
module.exports = function() {
596-
var gradient = this.setDirection(),
597-
elToSetClassOnClass = document.querySelector(this.elToSetClassOn).classList,
598-
i = 0;
567+
var gradient = this.setDirection();
568+
var elToSetClassOnClass = document.querySelector(this.elToSetClassOn).classList;
569+
var i = 0;
599570
this.context.clearRect(0, 0, this.x1, this.y1);
600571

601572
if (this.image) {
@@ -682,7 +653,7 @@ module.exports = function() {
682653

683654
if (_this.isCanvasInWindowView) {
684655
if (!_this.isPaused || _this.firstScrollInit) {
685-
if (_this.image && !_this.isImgLoaded) {return}
656+
if (_this.image && !_this.isImgLoaded) {return;}
686657
_this.isPausedBecauseNotInView = false;
687658
_this.play('isPlayedBecauseInView');
688659
_this.firstScrollInit = false;
@@ -765,9 +736,9 @@ module.exports = function() {
765736
var imageAxisPosition;
766737
switch(imageAlignIndex) {
767738
case 'center':
768-
imageAxisPosition = imgOriginalWidthOrHeight > canvasWidthOrHeight ?
769-
-(imgOriginalWidthOrHeight - canvasWidthOrHeight) / 2 :
770-
(canvasWidthOrHeight - imgOriginalWidthOrHeight) / 2;
739+
imageAxisPosition = imgOriginalWidthOrHeight > canvasWidthOrHeight
740+
? -(imgOriginalWidthOrHeight - canvasWidthOrHeight) / 2
741+
: (canvasWidthOrHeight - imgOriginalWidthOrHeight) / 2;
771742
_this.imagePosition[axis] = imageAxisPosition;
772743
_this.imagePosition[axis === 'x' ? 'width' : 'height'] = imgOriginalWidthOrHeight;
773744
break;
@@ -848,7 +819,7 @@ module.exports = function(progressPercent) {
848819
// Generate gradient color position
849820
activeChannelPos = parseFloat((_this.activeColorsPos[i] +
850821
(_this.activeColorsPosDiff[i] / 100 * progressPercent)
851-
).toFixed(4))
822+
).toFixed(4));
852823

853824
if (activeChannelPos <= 1 && activeChannelPos >= 0) {
854825
_this.currentColorsPos[i] = activeChannelPos;
@@ -877,7 +848,7 @@ module.exports = function() {
877848
}
878849

879850
// Set blank properties
880-
this.channels[this.activeState].push([{ }]);
851+
this.channels[this.activeState].push([{}]);
881852
this.channels[this.activeState][this.channelsIndex].colors = [];
882853
this.channels[this.activeState][this.channelsIndex].colorsDiff = [];
883854
this.channels[this.activeState][this.channelsIndex].colorsPos = [];
@@ -953,6 +924,7 @@ module.exports = function() {
953924

954925
case 'radial':
955926
return ctx.createRadialGradient(this.x1 / 2, this.y1 / 2, this.x1 / 2, this.x1 / 2, this.y1 / 2, 0);
927+
956928
case 'custom':
957929
return ctx.createLinearGradient(
958930
getCustomCoordinateInPixels(this.customDirection.x0, this.x1),
@@ -967,7 +939,7 @@ function getCustomCoordinateInPixels(coordinate, size) {
967939
return coordinate.indexOf('%') > -1
968940
? size / 100 * parseInt(coordinate.split('%')[0], 10)
969941
: parseInt(coordinate.split('px')[0], 10);
970-
};
942+
}
971943

972944
},{}],29:[function(require,module,exports){
973945
'use strict';
@@ -1000,27 +972,29 @@ module.exports = function(inputType) {
1000972
'difference', 'exclusion', 'hue', 'saturation', 'color', 'luminosity'];
1001973
var directionValues = ['diagonal', 'left-right', 'top-bottom', 'radial', 'custom'];
1002974

1003-
switch (inputType) {
975+
switch(inputType) {
1004976
case 'image':
1005977
// Validate image.position
1006978
if ((!Array.isArray(this.image.position) || this.image.position.length !== 2) ||
1007979
xPositionValues.indexOf(this.image.position[0]) === -1 ||
1008980
yPositionValues.indexOf(this.image.position[1]) === -1
1009-
) { this.triggerError('image.position') }
981+
) { this.triggerError('image.position'); }
1010982
// Validate image.stretchMode
1011983
if (this.image.stretchMode) {
1012984
if ((!Array.isArray(this.image.stretchMode) || this.image.stretchMode.length !== 2) ||
1013985
stretchModeValues.indexOf(this.image.stretchMode[0]) === -1 ||
1014986
stretchModeValues.indexOf(this.image.stretchMode[1]) === -1
1015-
) { this.triggerError('image.stretchMode') }
987+
) { this.triggerError('image.stretchMode'); }
1016988
}
1017989
break;
990+
1018991
case 'blendingMode':
1019992
if (blendingModeValues.indexOf(this.image.blendingMode) === -1) {
1020993
this.clear();
1021994
this.triggerError('blendingMode');
1022995
}
1023996
break;
997+
1024998
case 'direction':
1025999
if (directionValues.indexOf(this.direction) === -1) {
10261000
this.triggerError('direction');
@@ -1071,7 +1045,7 @@ function areDefinedInPixelsOrPercentage(array) {
10711045
i++;
10721046
}
10731047
return definedInPixelsOrPercentage;
1074-
};
1048+
}
10751049

10761050
},{}],32:[function(require,module,exports){
10771051
window.Granim = require('./lib/Granim.js');

0 commit comments

Comments
 (0)