Skip to content

Commit a613644

Browse files
authored
Merge pull request #46 from goldst/perf
Perf
2 parents b8df613 + 1f587b3 commit a613644

File tree

8 files changed

+85
-19
lines changed

8 files changed

+85
-19
lines changed

blocks/card/CardAbstract.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,16 @@ export default class cardAbstract {
106106
this._cm.mousemoveEventShadow();
107107
}
108108

109+
/**
110+
* runs doEvent on both CardTransformable and CardMouseShadowed
111+
* @todo that's a bad description. change
112+
* @param {event} event
113+
*/
114+
doEvent(event) {
115+
this._ct.doEvent(event);
116+
this._cm.doEvent(event);
117+
}
118+
109119
/**
110120
* helper function that throws if class name ends with 'Abstract'
111121
* @private

blocks/card/card--projects.css

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@
2121
right: calc(var(--project-card--padding) + 0.5 * var(--_w));
2222
}
2323

24-
.card--projects .card__inner {
25-
transition: clip-path 0.5s;
26-
}
27-
2824
.card--projects:hover .card__inner {
2925
--_by: calc(var(--h) - 2 * var(--project-card--padding) - 25px);
3026
}

blocks/card/card.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
--_hover-scale: var(--card--hover-scale, 1.025);
1919

2020
height: var(--_h);
21-
transition: transform 0.5s;
2221
width: var(--_w);
2322
}
2423

@@ -38,6 +37,7 @@
3837

3938
.card:hover {
4039
transform: scale(var(--_hover-scale));
40+
transition: transform 0.5s;
4141
z-index: 100;
4242
}
4343

blocks/card/card.js

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

55

66
window.addEventListener('load', () => {
7-
new CardProjects().mousemoveEvent();
8-
new CardMain().mousemoveEvent();
9-
new Card().mousemoveEvent();
7+
const
8+
CP = new CardProjects(),
9+
CM = new CardMain(),
10+
C = new Card();
11+
12+
CP.mousemoveEvent();
13+
CM.mousemoveEvent();
14+
C.mousemoveEvent();
15+
16+
window.addEventListener('mousemove', (e) => {
17+
CP.doEvent(e);
18+
CM.doEvent(e);
19+
C.doEvent(e);
20+
});
1021
});

index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ <h1 class="card__title card--main__title">
3737
<a href="https://github.com/goldst" class="card--main__social-link card--main__social-link--github main-card__button main-card__button--github button button--s">
3838
GitHub
3939
</a>
40-
<a href="mailto:leonard-goldstein@outlook.de" class="card--main__social-link card--main__social-link--mail main-card__button button button--s">
40+
<a href="javascript:toMail('𝕝𝕖𝕠𝕟𝕒𝕣𝕕-𝕘𝕠𝕝𝕕𝕤𝕥𝕖𝕚𝕟@𝕠𝕦𝕥𝕝𝕠𝕠𝕜.𝕕𝕖')" class="card--main__social-link card--main__social-link--mail main-card__button button button--s">
4141
E-Mail
4242
</a>
4343
<a href="tel:0157-78218294" class="card--main__social-link card--main__social-link--tel main-card__button button button--s">
@@ -204,5 +204,6 @@ <h3 class="card__title project-card__title">
204204
</ul>
205205
</footer>
206206
<script src="blocks/index.js" type="module"></script>
207+
<script src="js/safety/safety.js"></script>
207208
</body>
208209
</html>

js/eventControl/EventController.js

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -188,23 +188,24 @@ export default class EventController {
188188
/**
189189
* Adds an eventListener for each DOM element that matches the
190190
* criteria.
191-
* @param {string} [eventType=mousemove] type of the event that
192-
* should be listened for
191+
* @param {string} eventType type of the event that
192+
* should be listened for. If null, you have to react to events
193+
* manually, running doEvent(event).
193194
* @param {function} [modificationFunction=args=>\[]] - returns
194195
* an array of css changes. args contain absolute transformation
195196
* origin and mouse position, both in arrays, and others.
196197
* See {TransformationFunctions} for examples and predefined
197198
* functions
198199
* @param {string} [additionalFilter='*'] - css query that has to
199-
* apply additionaly to the one passed in the constructor
200+
* apply additionally to the one passed in the constructor
200201
* @param {function} [postFunction = (event, element)=>{}] - optional
201202
* function that runs after the css change is successfully
202-
* handeled internally. See {PostTransformFunctions} for examples
203+
* handled internally. See {PostTransformFunctions} for examples
203204
* and predefined functions.
204205
* @returns {void}
205206
*/
206207
listenToChangeCss(
207-
eventType = 'mousemove',
208+
eventType,
208209
modificationFunction = args => [],
209210
additionalFilter = '*',
210211
postFunction = (controller, event, element) => {}
@@ -213,12 +214,39 @@ export default class EventController {
213214
this.eventControlElements
214215
.filter(ece => ece.domElement.matches(additionalFilter))
215216
.forEach(ece => {
216-
document.addEventListener(eventType, event => {
217+
/**
218+
* Function that will be run on events, when calling
219+
* doEvent or on events of eventType
220+
* @param {event} event
221+
*/
222+
const run = (event) => {
217223
this._modify(event, ece, modificationFunction);
218224
postFunction.call(this, event, ece);
219-
});
220-
}
221-
);
225+
};
226+
227+
if(eventType !== null) {
228+
document.addEventListener(eventType, run);
229+
}
230+
231+
ece.doEvent = run;
232+
});
233+
}
234+
235+
/**
236+
* runs modification functions and postfunctions for all
237+
* EventControlElements, if they have previously been passed via
238+
* listenToChangeCss
239+
* @param {event} event
240+
* @returns {void}
241+
*/
242+
doEvent(event) {
243+
this.eventControlElements
244+
.forEach(ece => {
245+
// only if doEvent was set by listenToChangeCss
246+
if(ece.doEvent !== undefined) {
247+
ece.doEvent(event);
248+
}
249+
});
222250
}
223251

224252
/**

js/safety/safety.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* takes an encrypted mail address, written in lower-case mathematical
3+
* double struck letters (𝕒-𝕫) and "normal" characters (all characters
4+
* with character codes under 122), converts it to a real mail address
5+
* and opens the mailto link if possible
6+
* @param {string} encrypted
7+
* @returns {void}
8+
*/
9+
function toMail(encrypted) {
10+
let decrypted = "";
11+
for(let i = 0; i < encrypted.length; i++) {
12+
if(encrypted.charCodeAt(i) > 122) {
13+
decrypted += String.fromCharCode(encrypted.charCodeAt(i+1) - 56561);
14+
i++;
15+
} else {
16+
decrypted += encrypted.charAt(i);
17+
}
18+
}
19+
window.open("mailto:" + decrypted, "_self");
20+
}

js/transformation/TransformationController.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export default class TransformationController extends EC {
4949
additionalFilter='*',
5050
postFunction = (event, element)=>{} ) {
5151
this.listenToChangeCss(
52-
'mousemove', transformationFunction,
52+
null, transformationFunction,
5353
additionalFilter, postFunction
5454
);
5555
}

0 commit comments

Comments
 (0)