Skip to content

Commit acbb089

Browse files
committed
Create getElement function
1 parent 8091560 commit acbb089

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

lib/Granim.js

+4-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
11
'use strict';
22

33
function Granim(options) {
4-
if(options.element instanceof HTMLCanvasElement)
5-
this.canvas = options.element
6-
else if (typeof options.element === "string")
7-
this.canvas = document.querySelector(options.element)
8-
else
9-
throw new Error('The element you used is neither a String, nor a HTMLCanvasElement');
10-
if(!this.canvas){
11-
throw new Error('`' + options.element + '` could not be found in the DOM');
12-
}
4+
this.getElement(options.element);
135
this.x1 = 0;
146
this.y1 = 0;
157
this.name = options.name || false;
@@ -22,6 +14,7 @@ function Granim(options) {
2214
this.previousTimeStamp = null;
2315
this.progress = 0;
2416
this.isPaused = false;
17+
this.isCleared = false;
2518
this.isPausedBecauseNotInView = false;
2619
this.iscurrentColorsSet = false;
2720
this.context = this.canvas.getContext('2d');
@@ -89,6 +82,8 @@ Granim.prototype.makeGradient = require('./makeGradient.js');
8982

9083
Granim.prototype.getDimensions = require('./getDimensions.js');
9184

85+
Granim.prototype.getElement = require('./getElement.js');
86+
9287
Granim.prototype.animateColors = require('./animateColors.js');
9388

9489
Granim.prototype.getLightness = require('./getLightness.js');

lib/getElement.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'use strict';
2+
3+
module.exports = function(element) {
4+
if (element instanceof HTMLCanvasElement) {
5+
this.canvas = element;
6+
7+
} else if (typeof element === "string") {
8+
this.canvas = document.querySelector(element);
9+
10+
} else {
11+
throw new Error('The element you used is neither a String, nor a HTMLCanvasElement');
12+
}
13+
14+
if (!this.canvas) {
15+
throw new Error('`' + element + '` could not be found in the DOM');
16+
}
17+
};

0 commit comments

Comments
 (0)