Skip to content

Commit f87ce2e

Browse files
committed
preparation for separation of hover effects
1 parent 1c86168 commit f87ce2e

File tree

7 files changed

+92
-87
lines changed

7 files changed

+92
-87
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,5 @@ typings/
7777
# documentation
7878
docs/
7979

80+
# vscode
81+
.vscode

blocks/card/Card--main.js

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,17 @@
11
import CardAbstract from './CardAbstract.js';
22

33
/**
4-
* automates the 3d effect for card blocks with the --main modifier
4+
* automates event based effects for card blocks with the --main
5+
* modifier
56
* @extends CardAbstract
67
*/
78
export default class CardMain extends CardAbstract {
89
/**
910
* @returns {void}
1011
*/
1112
constructor() {
12-
super('--main');
13-
}
14-
15-
/**
16-
* empty post transform function
17-
* @override
18-
* @protected
19-
* @returns {void}
20-
*/
21-
_postTransformFunction() {
22-
//in a card with the '--main' modfier, nothing happens after the
23-
//transformation
13+
// in main cards, nothing happens
14+
// after the transformation, thus the empty function
15+
super('--main', () => {});
2416
}
2517
}

blocks/card/Card--projects.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
11
import LA
22
from '../../js/math/LinearAlgebra.js';
33
import TF
4-
from '../../js/transformation/TransformationFunctions.js';
4+
from '../../js/transformationNew/TransformationFunctions.js';
55

66
import CardAbstract from './CardAbstract.js';
77

88
/**
9-
* automates the 3d effect for card blocks with the --projects modifier
9+
* automates event based effects for card blocks with the --projects
10+
* modifier
1011
* @extends CardAbstract
1112
*/
1213
export default class CardProjects extends CardAbstract {
1314
/**
1415
* @returns {void}
1516
*/
1617
constructor() {
17-
super('--projects');
18+
super(
19+
'--projects',
20+
CardProjects._postTransformFunction,
21+
CardProjects._transformationFunction
22+
);
1823
}
1924

2025
/**
@@ -30,7 +35,7 @@ export default class CardProjects extends CardAbstract {
3035
* @returns {String} transformation with adjusted scale and 3d
3136
* rotation
3237
*/
33-
_transformationFunction(args) {
38+
static _transformationFunction(args) {
3439
const rotAxis = LA.vector(args.transformOrigin, args.mousePosition),
3540
rotation =
3641
TF.advBellCurve(
@@ -64,7 +69,7 @@ export default class CardProjects extends CardAbstract {
6469
* transformed
6570
* @returns {void}
6671
*/
67-
_postTransformFunction(event, element) {
72+
static _postTransformFunction(event, element) {
6873
const parent = element.domElement.parentElement,
6974
background = element.surroundingBackground(
7075
'var(--c0)',

blocks/card/Card.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
import CardAbstract from './CardAbstract.js';
22

33
/**
4-
* automates the 3d effect for card blocks without modifiers
4+
* automates event based effects for card blocks without modifiers
55
* @extends CardAbstract
66
*/
77
export default class Card extends CardAbstract {
8-
/**
9-
* empty post transform function
10-
* @override
11-
* @protected
12-
* @returns {void}
13-
*/
14-
_postTransformFunction() {
15-
//in a card without a modfier, nothing happens after the
16-
//transformation
8+
constructor() {
9+
// in cards without modifiers, nothing happens
10+
// after the transformation, thus the empty function
11+
super('', () => {});
1712
}
1813
}

blocks/card/CardAbstract.js

Lines changed: 21 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import TC
2-
from '../../js/transformationNew/TransformationController.js';
1+
import CT
2+
from './CardTransformable.js';
33
import TF
4-
from '../../js/transformation/TransformationFunctions.js';
4+
from '../../js/transformationNew/TransformationFunctions.js';
55
import LA
66
from '../../js/math/LinearAlgebra.js';
77

@@ -11,19 +11,27 @@ import LA
1111
* @abstract
1212
* @extends TransformationController
1313
*/
14-
export default class cardAbstract extends TC {
14+
export default class cardAbstract {
1515
/**
1616
* @param {String} [modifier = ''] Modifier of the card block.
1717
* Default '' means mo modifier.
18+
* @param {function} postTransformFunction for examples, see
19+
* {js/transformation/TransformableElement/
20+
* PostTransformFunctions.js}
1821
* @returns {void}
1922
*/
20-
constructor(modifier = '') {
21-
super(
22-
document.body,
23-
`.card${modifier} > .card__inner`
24-
);
23+
constructor(
24+
modifier = '',
25+
postTransformFunction,
26+
transformationFunction = cardAbstract._transformationFunction) {
27+
28+
this._throwIfAbstractClass();
2529

26-
console.log(this);
30+
this._ct = new CT(
31+
modifier,
32+
postTransformFunction,
33+
transformationFunction
34+
);
2735
}
2836

2937
/**
@@ -38,7 +46,7 @@ export default class cardAbstract extends TC {
3846
* @returns {string} transformation with adjusted scale and 3d
3947
* rotation
4048
*/
41-
_transformationFunction(args) {
49+
static _transformationFunction(args) {
4250
const
4351
rotAxis = LA.vector(args.transformOrigin, args.mousePosition),
4452
rotation =
@@ -69,38 +77,15 @@ export default class cardAbstract extends TC {
6977
};
7078
}
7179

72-
/**
73-
* in any implementation, override this function with a function that
74-
* does what should happen after transforming the element (eg.
75-
* setting the correct background to the parent element)
76-
* @see {PostTransformFunctions}
77-
* @abstract
78-
* @protected
79-
* @param {event} event - event that caused the transformation
80-
* @param {TransformableElement} element - element that was
81-
* transformed
82-
* @returns {void}
83-
*/
84-
_postTransformFunction(event, element) {
85-
//look for implementation examples in
86-
// 'js/transformation/TransformableElement/
87-
// PostTransformFunctions.js'
88-
this._throwIfAbstractFunction();
89-
}
90-
9180
/**
9281
* more specific version of {TransformationController}'s
9382
* mousemoveEventTransform that already specifies where to find the
9483
* passed transformation functions and what elements it applies to
9584
* @see TransformationController
9685
* @returns {void}
9786
*/
98-
mousemoveEventTransform() {
99-
super.mousemoveEventTransform(
100-
this._transformationFunction,
101-
'*',
102-
this._postTransformFunction
103-
);
87+
mousemoveEvent() {
88+
this._ct.mousemoveEventTransform();
10489
}
10590

10691
/**
@@ -114,24 +99,4 @@ export default class cardAbstract extends TC {
11499
throw new Error('cannot call functions in abstract class');
115100
}
116101
}
117-
118-
/**
119-
* Helper function that always throws an error. Override the method
120-
* which calls this to avoid that.
121-
* @private
122-
* @throws {Error} 'cannot call functions in abstract class' if class
123-
* name ends on 'Abstract'
124-
* @throws {Error} 'cannot call function in child class of abstract
125-
* class that does not override the abstract function' in any other
126-
* case
127-
* @returns {void}
128-
*/
129-
_throwIfAbstractFunction() {
130-
this._throwIfAbstractClass();
131-
132-
throw new Error(
133-
'cannot call function in child class of abstract class that ' +
134-
'does not override the abstract function'
135-
);
136-
}
137102
}

blocks/card/CardTransformable.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import TC
2+
from '../../js/transformationNew/TransformationController.js';
3+
4+
/**
5+
* Base for the transformation controller for card blocks, which automates
6+
* the 3d effect
7+
* @abstract
8+
* @extends TransformationController
9+
*/
10+
export default class cardTransformable extends TC {
11+
/**
12+
* @param {String} [modifier = ''] Modifier of the card block.
13+
* Default '' means mo modifier.
14+
* @returns {void}
15+
*/
16+
constructor(
17+
modifier = '',
18+
postTransformFunction,
19+
transformationFunction) {
20+
21+
super(
22+
document.body,
23+
`.card${modifier} > .card__inner`
24+
);
25+
26+
this._postTransformFunction = postTransformFunction;
27+
this._transformationFunction = transformationFunction;
28+
29+
console.log(this);
30+
}
31+
32+
/**
33+
* more specific version of {TransformationController}'s
34+
* mousemoveEventTransform that already specifies where to find the
35+
* passed transformation functions and what elements it applies to
36+
* @see TransformationController
37+
* @returns {void}
38+
*/
39+
mousemoveEventTransform() {
40+
super.mousemoveEventTransform(
41+
this._transformationFunction,
42+
'*',
43+
this._postTransformFunction
44+
);
45+
}
46+
}

blocks/card/card.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import CardProjects from './Card--projects.js';
44

55

66
window.addEventListener('load', () => {
7-
new CardProjects().mousemoveEventTransform();
8-
new CardMain().mousemoveEventTransform();
9-
new Card().mousemoveEventTransform();
7+
new CardProjects().mousemoveEvent();
8+
new CardMain().mousemoveEvent();
9+
new Card().mousemoveEvent();
1010
});

0 commit comments

Comments
 (0)