-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogressbar.html
More file actions
184 lines (146 loc) · 4.12 KB
/
Copy pathprogressbar.html
File metadata and controls
184 lines (146 loc) · 4.12 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Progressbar Component</title>
</head>
<body>
<!-- component call -->
<progress-bar-loader
data-stop="40"
data-time="3"
data-wait="1"
>
</progress-bar-loader>
<!-- component template -->
<template class="template-loader">
<style>
.loaderContainer {
width: 100%;
height:6px;
position: relative;
display: inline-flex;
}
.bar-loader {
width:0;
display: block;
position: absolute;
height: 4px;
background-color:#e53935;
-webkit-box-shadow: 0px 0px 15px 5px rgba(244, 67, 54, .75);
-moz-box-shadow: 0px 0px 15px 5px rgba(244, 67, 54, .75);
box-shadow: 0px 0px 15px 5px rgba(244, 67, 54, .75);
transition: width 1s;
-webkit-transition: width 1s;
}
.circleLoader {
width: 15px;
height: 15px;
border-radius: 50%;
float: right;
background-color:#e53935;
top: -6px;
position: absolute;
right: 0px;
-webkit-box-shadow: 0px 0px 15px 5px rgba(244, 67, 54, .75);
-moz-box-shadow: 0px 0px 15px 5px rgba(244, 67, 54, .75);
box-shadow: 0px 0px 15px 5px rgba(244, 67, 54, .75);
}
</style>
<div class="loaderContainer">
<span class="bar-loader">
<span class="circleLoader"></span>
</span>
</div>
</template>
<!-- component core -->
<script>
(() => {
'use strict';
class ProgressBarComponent extends HTMLElement {
constructor(){
super();
//loading template to attach shadowdom
const template = document.querySelector('template.template-loader');
//cloning tpl
const shadowRoot = this.attachShadow({mode:'open'});
//adding tpl to shadow root
shadowRoot.appendChild(document.importNode(template.content,true));
//appending to shadow
document.body.appendChild(shadowRoot);
}
//setters & getters
get stopsAt(){
return parseInt(this.getAttribute('data-stop'));
}
set stopsAt(val) {
if(val) {
this.setAttribute('data-stop',val);
}else {
this.setAttribute('data-stop',100);
}
}
get timeExecution() {
return parseInt(this.getAttribute('data-time'));
}
set timeExecution(val) {
if(val) {
this.setAttribute('data-time',parseInt(val));
}else {
this.setAttribute('data-time',5);
}
}
get waitingSecs(){
return parseInt(this.getAttribute('data-wait'));
}
set waitingSecs(val) {
if(val) {
this.setAttribute('data-wait',val);
} else {
this.setAttribute('data-wait',0);
}
}
// functionality
animate(stopsAt,duration,waitingSecs,bar) {
const everyTime = (duration*1000)/100;
let counter = 0;
let element = document.querySelector('.loaderContainer');
let interval = setInterval(()=>{
if (counter === stopsAt){
console.log('i should waith here ', waitingSecs, ' secs...');
clearInterval(interval);
setTimeout(()=>{
bar.style.width = 100 + '%';
console.log('done .....');
setTimeout(()=>document.body.removeChild(element),1100);
},waitingSecs*1000);
} else if(counter === 100){
console.log('im finished');
setTimeout(()=>document.body.removeChild(element),
1000);
clearInterval(interval);
}
else {
counter++;
bar.style.width = counter + '%';
}
},everyTime);
}
connectedCallback() {
const mainContainer = document.querySelector('.loaderContainer');
const bar = document.body.querySelector('.bar-loader');
//doubt hacky things .... ????
this.stopsAt = this.stopsAt;
this.timeExecution = this.timeExecution;
this.waitingSecs = this.waitingSecs;
console.log("timeExecution : ",this.timeExecution, " stops at :",this.stopsAt, ' waitingSecs :',this.waitingSecs);
//animation method is called and begin the show :V
this.animate(this.stopsAt,this.timeExecution,this.waitingSecs,bar);
}
}
customElements.define('progress-bar-loader',ProgressBarComponent);
}
)(window.customElements);
</script>
</body>
</html>