-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
270 lines (248 loc) · 9.98 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
"use strict";
const DOM = {
timeline: "timeline",
timelineStepper: "timeline__stepper",
timelineStep: "timeline__step",
timelineStepTitle: "timeline__step-title",
timelineStepActive: "is-active",
timelineStepActiveMarker: "timeline__step-active-marker",
timelineSlidesContainer: "timeline__slides",
timelineSlide: "timeline__slide",
timelineSlideActive: "is-active",
};
const STEP_ACTIVE_MARKEP_CUSTOM_PROPS = {
width: "--slide-width",
posX: "--slide-pos-x",
posY: "--slide-pos-y",
};
const SLIDES_CONTAINER_CUSTOM_PROPS = {
height: "--slides-container-height",
};
const timeline = document.querySelector(`.${DOM.timeline}`);
const timelineStepper = timeline === null || timeline === void 0 ? void 0 : timeline.querySelector(`.${DOM.timelineStepper}`);
const timelineStepTitle = timeline === null || timeline === void 0 ? void 0 : timeline.querySelector(`.${DOM.timelineStepTitle}`);
const timelineSlidesContainer = timeline === null || timeline === void 0 ? void 0 : timeline.querySelector(`.${DOM.timelineSlidesContainer}`);
const timelineSlides = timeline && Array.from(timeline.querySelectorAll(`.${DOM.timelineSlide}`));
window.addEventListener("load", () => {
createStepActiveMarker();
activateCurrentSlide();
});
window.addEventListener("resize", () => {
recalcStepActiveMarkerProps();
});
timeline === null || timeline === void 0 ? void 0 : timeline.addEventListener("click", (event) => {
const { target } = event;
if (!target ||
!(target instanceof Element) ||
!target.closest(`.${DOM.timelineStep}`)) {
return;
}
const currentStep = target.closest(`.${DOM.timelineStep}`);
if (!currentStep) {
return;
}
deactivateSteps();
activateCurrentStep(currentStep);
recalcStepActiveMarkerProps();
deactivateSlides();
activateCurrentSlide();
});
function deactivateSteps() {
const steps = document.querySelectorAll(`.${DOM.timelineStep}`);
steps === null || steps === void 0 ? void 0 : steps.forEach((elem) => elem.classList.remove(`${DOM.timelineStepActive}`));
}
function activateCurrentStep(currentStep) {
currentStep === null || currentStep === void 0 ? void 0 : currentStep.classList.add(`${DOM.timelineStepActive}`);
}
function deactivateSlides() {
timelineSlides === null || timelineSlides === void 0 ? void 0 : timelineSlides.forEach((elem) => elem.classList.remove(`${DOM.timelineSlideActive}`));
}
function activateCurrentSlide() {
const currentSlide = getCurrentSlide();
if (!currentSlide) {
return;
}
const currentSlideHeight = getCurrentSlideHeight(currentSlide);
setSlideContainerHeight(currentSlideHeight);
currentSlide.classList.add(`${DOM.timelineSlideActive}`);
}
function createStepActiveMarker() {
const stepActiveMarker = document.createElement("div");
stepActiveMarker.classList.add(`${DOM.timelineStepActiveMarker}`);
timelineStepper === null || timelineStepper === void 0 ? void 0 : timelineStepper.appendChild(stepActiveMarker);
const positionProps = getStepActiveMarkerProps();
if (!positionProps) {
return;
}
setStepActiveMarkerProps(Object.assign({ stepActiveMarker }, positionProps));
}
function recalcStepActiveMarkerProps() {
const stepActiveMarker = timeline === null || timeline === void 0 ? void 0 : timeline.querySelector(`.${DOM.timelineStepActiveMarker}`);
const stepActiveMarkerProps = getStepActiveMarkerProps();
if (!stepActiveMarkerProps) {
return;
}
setStepActiveMarkerProps(Object.assign({ stepActiveMarker }, stepActiveMarkerProps));
}
function setStepActiveMarkerProps({ stepActiveMarker, posX, posY, width, }) {
stepActiveMarker.style.setProperty(`${STEP_ACTIVE_MARKEP_CUSTOM_PROPS.width}`, `${width}px`);
stepActiveMarker.style.setProperty(`${STEP_ACTIVE_MARKEP_CUSTOM_PROPS.posX}`, `${posX}px`);
if (typeof posY === "number") {
stepActiveMarker.style.setProperty(`${STEP_ACTIVE_MARKEP_CUSTOM_PROPS.posY}`, `${posY}px`);
}
}
function getStepActiveMarkerProps() {
const { currentStep } = getCurrentStep();
if (!currentStep) {
return null;
}
const width = getElementWidth(currentStep);
const posX = getStepActiveMarkerPosX(currentStep);
const posY = getStepActiveMarkerPosY();
if (typeof posX !== "number" || typeof posY !== "number") {
return null;
}
return { posX, posY, width };
}
function getCurrentStep() {
const timelineSteps = Array.from(document.querySelectorAll(`.${DOM.timelineStep}`));
const currentStep = timelineSteps.find((element) => element.classList.contains(`${DOM.timelineStepActive}`));
const currentStepIndex = currentStep &&
timelineSteps.findIndex((element) => element.classList.contains(`${DOM.timelineStepActive}`));
return { currentStep, currentStepIndex };
}
function getCurrentSlide() {
const { currentStepIndex } = getCurrentStep();
if (typeof currentStepIndex !== "number" || !timelineSlides) {
return null;
}
return timelineSlides[currentStepIndex];
}
function setSlideContainerHeight(height) {
timelineSlidesContainer === null || timelineSlidesContainer === void 0 ? void 0 : timelineSlidesContainer.style.setProperty(`${SLIDES_CONTAINER_CUSTOM_PROPS.height}`, `${height}px`);
}
function getCurrentSlideHeight(currentSlide) {
return currentSlide.clientHeight;
}
function getStepActiveMarkerPosY() {
const timelineTitlePosY = timelineStepTitle === null || timelineStepTitle === void 0 ? void 0 : timelineStepTitle.getBoundingClientRect().top;
const timelineStepperPosY = timelineStepper === null || timelineStepper === void 0 ? void 0 : timelineStepper.getBoundingClientRect().top;
if (!timelineTitlePosY || !timelineStepperPosY) {
return null;
}
return timelineTitlePosY - timelineStepperPosY;
}
function getStepActiveMarkerPosX(currentStep) {
const timelineStepperPosX = timelineStepper === null || timelineStepper === void 0 ? void 0 : timelineStepper.getBoundingClientRect().left;
const currentStepPosX = currentStep.getBoundingClientRect().left;
if (!timelineStepperPosX) {
return null;
}
return currentStepPosX - timelineStepperPosX;
}
function getElementWidth(elem) {
return elem.clientWidth;
}
document.addEventListener("DOMContentLoaded", function() {
const aboutLink = document.querySelector("a[href='#about']");
aboutLink.addEventListener("click", function(event) {
event.preventDefault();
const aboutSection = document.getElementById("about");
aboutSection.scrollIntoView({ behavior: "smooth" });
});
});
(function() {
'use strict';
var Progress = function( element ) {
this.context = element.getContext( "2d" );
this.refElement = element.parentNode;
this.loaded = 0;
this.start = 4.72;
this.width = this.context.canvas.width;
this.height = this.context.canvas.height;
this.total = parseInt( this.refElement.dataset.percent, 10 );
this.timer = null;
this.diff = 0;
this.init();
};
Progress.prototype = {
init: function() {
var self = this;
self.timer = setInterval(function() {
self.run();
}, 25);
},
run: function() {
var self = this;
self.diff = ( ( self.loaded / 100 ) * Math.PI * 2 * 10 ).toFixed( 2 );
self.context.clearRect( 0, 0, self.width, self.height );
self.context.lineWidth = 4;
self.context.fillStyle = "#000";
self.context.strokeStyle = "#D6AC4B";
self.context.textAlign = "center";
self.context.fillText( self.loaded + "%", self.width * .5, self.height * .5 + 2, self.width );
self.context.beginPath();
self.context.arc( 35, 35, 30, self.start, self.diff / 10 + self.start, false );
self.context.stroke();
if( self.loaded >= self.total ) {
clearInterval( self.timer );
}
self.loaded++;
}
};
var CircularSkillBar = function( elements ) {
this.bars = document.querySelectorAll( elements );
if( this.bars.length > 0 ) {
this.init();
}
};
CircularSkillBar.prototype = {
init: function() {
this.tick = 25;
this.progress();
},
progress: function() {
var self = this;
var index = 0;
var firstCanvas = self.bars[0].querySelector( "canvas" );
var firstProg = new Progress( firstCanvas );
var timer = setInterval(function() {
index++;
var canvas = self.bars[index].querySelector( "canvas" );
var prog = new Progress( canvas );
if( index == self.bars.length ) {
clearInterval( timer );
}
}, self.tick * 100);
}
};
var button = document.getElementById("softs");
button.addEventListener( "click", function() {
var circularBars = new CircularSkillBar( "#sbars .sbar" );
},false);
document.addEventListener( "DOMContentLoaded", function() {
var circularBars = new CircularSkillBar( "#hbars .hbar" );
});
})();
$(document).ready(function () {
$("#hards").click(function(){
$(".sbar")
.filter(function(){ return ! $(this).is(":hidden"); })
.fadeOut(200, function(){
$('.hbar,.hbars').fadeIn(300);
});
$('#softs').removeClass("bactive");
$('#hards').addClass("bactive");
});
$("#softs").click(function(){
$(".hbar")
.filter(function(){ return ! $(this).is(":hidden"); })
.fadeOut(200, function(){
$('.sbar,.sbars').fadeIn(300);
});
$('#hards').removeClass("bactive");
$('#softs').addClass("bactive");
});
});
var copy = document.querySelector(".logos-slide").cloneNode(true);
document.querySelector(".logos").appendChild(copy);