-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
632 lines (450 loc) · 23.1 KB
/
index.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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
// activeFilters
var activeFilters = [];
var limitedArray = [];
var limitedFullArray = [];
var filteredArray = [];
var startResults = 0;
var endResults = 20;
// Initally shuffle json data for cards
// shuffle(myJson);
// Define the languages of search on render
languageRender("English", "Hebrew", "Spanish")
hospitalRender("UPMC St Margaret", "UPMC Mercy", "UPMC Presbyterian", "UPMC Magee Womens Hospital")
// Fake loading function. T is the time in milliseconds
function fakeLoading(t){
document.getElementById("loaderDiv").scrollIntoView();
document.getElementById("loaderDiv").style.cssText = "display: flex"
document.getElementById("results").style.cssText = "display: none"
setTimeout(() => {
document.getElementById("results").style.cssText = "display: block";
document.getElementById("loaderDiv").style.cssText = "display: none";
}, t);
} fakeLoading(4000); // Load for 4s by default
function dataInitalize(start ,end, ANPfilt) {
document.getElementById("results").innerHTML = ""
// Initalize first 20 results but not the data
if(arguments.length == 2){
limitedFullArray = myJson
limitedArray = myJson.filter((x, i) => i >= start && i < end)
}else{
limitedFullArray = myJson.filter((x, i) => x.acceptingNewPatients == true);
limitedArray = myJson.filter((x, i) => x.acceptingNewPatients == true).filter((x, i) => i >= start && i < end)
}
document.getElementById("results").innerHTML = '<h4 id="numResults">' + limitedFullArray.length + ' Results</h4>'
start == 0 ? document.getElementById("results").innerHTML += '<a href="https://myupmc.upmc.com/anywhere-care/" target="_blank"><div class="ANC-Card"><p>I\'m looking for virtual care via <span>UPMC AnywhereCare</span>.</p></div></a>' : null
for(let i = 0; i < limitedArray.length; i++){
document.getElementById("results").innerHTML += '<a href="#"><div class="provider"><div class="leftColumn"><h2 class="name">Lastname, Firstname MI, MD</h2><div class="spacer"><h3>Internal Medicine</h3><span class="np"></span></div></div><div class="rightColumn"><h4>Pine Richland Medical Associates</h4><div><address>9999 Poplar Street <br>Pittsburgh, PA 15222</address><phone>(412) 412-4124</phone></div><div class="milesDist"><span class="letter">B</span><span class="distance"> 0.75 miles away</span></div></div></div></a>'
}
let dist = document.getElementsByClassName('distance');
let na = document.getElementsByClassName('name');
let add = document.querySelectorAll('address');
let pho = document.querySelectorAll('phone');
let np = document.querySelectorAll('.np');
let prac = document.querySelectorAll('.rightColumn h4');
let lett = document.querySelectorAll('.letter');
limitedArray.forEach((v, i) => {
na[i].innerHTML = limitedArray[i].name + ", MD"; // Render name
add[i].innerHTML = limitedArray[i].address; // Render address
pho[i].innerHTML = limitedArray[i].phone; // Render phone number
prac[i].innerHTML = limitedArray[i].practice; // Render practice name
lett[i].innerHTML = String.fromCharCode(97 + i).toUpperCase();
// Render accepting new patients
if(limitedArray[i].acceptingNewPatients == true){
np[i].innerHTML = '<i class="fa fa-check" aria-hidden="true"><span class="np">Accepting new patients</span></i>'
}
// Render distances
if(limitedArray[i].distance == 1){
dist[i].innerHTML = limitedArray[i].distance + " mile away";
}else{
dist[i].innerHTML = limitedArray[i].distance + " miles away";
}
})
} dataInitalize(startResults, endResults);
// For floating button logic to toggle map and list view
var showingMap = false;
document.addEventListener('DOMContentLoaded', function () {
var mapToggles = document.getElementsByClassName("mapListToggle");
for( let i = 0; i < mapToggles.length; i++){
mapToggles[i].addEventListener("click", mobileToggle);
}
});
function mobileToggle(){
let results = document.getElementById('leftColumn');
let map = document.getElementById('map');
let container = document.getElementById('row');
if(showingMap){
map.style.cssText = "display: none;"
results.style.cssText = 'display: inherit;'
container.style.cssText = 'flex-direction: column;'
showingMap = false;
}else{
results.style.cssText = "display: none;"
map.style.cssText = "display: inherit;"
container.style.cssText = 'flex-direction: column-reverse;'
showingMap = true;
}
}
// Reset inline styles greater than tablet
window.addEventListener('resize', reportWindowSize);
function reportWindowSize(){
if(window.innerWidth > 768){
document.getElementById('leftColumn').removeAttribute('style');
document.getElementById('map').removeAttribute('style');
document.getElementById('row').removeAttribute('style');
}else{
}
}
// Alert when clicking edit search
function clickEdit(){
let radius = document.getElementById('radius')
alert("You successfully edited the search. You may continue with the test.");
radius.innerText = "10 miles";
fakeLoading(2000);
}
document.getElementById('editSearch').addEventListener('click', () => clickEdit());
document.getElementById('radius').addEventListener('click', () => clickEdit());
document.getElementById("drType").addEventListener("click", () => alert("You successfully edited the search. You may continue with the test."))
document.getElementById("location").addEventListener("click", () => alert("You successfully edited the search. You may continue with the test."))
// Shrinks search header at scroll position 100
function scrollFunction() {
if (window.scrollY < 100 && window.innerWidth > 768) {
document.getElementById('searchHead').style.cssText = "font-size: 28px; white-space: normal; padding-top: 10;";
document.getElementById('searchFiltersHead').style.cssText = "flex-direction: column;";
document.getElementById('editSearch').style.cssText = "margin-left: 0;";
document.querySelectorAll('#filter .option').forEach(e => {
e.style.cssText = "font-size: 14px"
})
document.querySelectorAll('#chips .chip').forEach(e => {
e.style.cssText = "font-size: 14px"
})
} else if(window.scrollY > 100 && window.innerWidth > 768) {
document.getElementById('searchHead').style.cssText = "font-size: 18px; white-space: normal; width: auto;";
document.getElementById('searchFiltersHead').style.cssText = "flex-direction: row-reverse; justify-content: flex-end; align-items: baseline; padding-top: 0;";
document.getElementById('editSearch').style.cssText = "margin-left: 18px;";
document.querySelectorAll('#filter .option').forEach(e => {
e.style.cssText = "font-size: 12px"
})
document.querySelectorAll('#chips .chip').forEach(e => {
e.style.cssText = "font-size: 12px"
})
}
} window.onscroll = function() {scrollFunction()};
function filterScroll(){
// let moreLeft = document.querySelector("#filter .option.More").getBoundingClientRect().left;
// let moreTop = document.querySelector("#filter .option.More").getBoundingClientRect().top;
// document.getElementById("moreMenu").style.cssText="top: " + moreTop +"; left:"+moreLeft+";"
const moreMenu = document.getElementById("moreMenu")
const filters = document.getElementById("filter")
moreMenu.style.cssText = "";
if((moreMenu.offsetLeft + moreMenu.offsetWidth - 10) >= filters.offsetWidth){
moreMenu.style.cssText="right: 0;";
// console.log("stick to right")
}
}
document.getElementById('filter').onscroll = () => filterScroll()
function clickMore(){
const moreMenu = document.getElementById("moreMenu")
const arrow = document.getElementsByClassName('arrow-up')[0];
const filters = document.getElementById("filter")
moreMenu.classList.toggle("hidden")
window.getComputedStyle(arrow).visibility == 'hidden' ? arrow.style.cssText="visibility: visible" : arrow.style.cssText="visibility: hidden"
moreMenu.style.cssText = "";
if((moreMenu.offsetLeft + moreMenu.offsetWidth - 10) >= filters.offsetWidth){
moreMenu.style.cssText="right: 0;";
// console.log("stick to right")
}
}document.querySelector("#filter .option.More").addEventListener("click", () => clickMore())
// For Clear All filter chip
function clearAllFilters(){
activeFilters = [];
dataInitalize(0, 20)
managePaginationLength();
document.querySelectorAll('#filter .option').forEach((e) => {
e.classList.remove("active")
})
document.getElementById("moreMenu").classList.add("hidden");
document.getElementsByClassName('arrow-up')[0].style.cssText="visibility: hidden;";
document.querySelectorAll('#filter .option .container').forEach((e) => {
e.classList.remove("active")
})
document.getElementById("chips").innerHTML = ''
document.getElementById('map').style.cssText = 'top: 150px; height: calc(100vh - 150px);'
fakeLoading(800);
}
function languageRender(...langs){
let validList = document.getElementById("validLanguages");
let invalidList = document.getElementById("invalidLanguages");
let invalidListHidden = document.getElementById('invalidLanguagesHidden')
let langArr = languages
var index;
for (var i=0; i<langs.length; i++) {
index = langArr.indexOf(langs[i]);
if (index > -1) {
langArr.splice(index, 1);
}
}
validList.innerHTML = '';
invalidList.innerHTML = '';
for(let i = 0; i < langs.length; i++){
// if (i == 0){
// validList.innerHTML += `<label class="control control-radio">${langs[i]}<input type="radio" name="radio" checked="checked" name="group2" value="option2"/><div class="control_indicator"></div></label>`
// }else{
// validList.innerHTML+= `<label class="control control-radio">${langs[i]}<input type="radio" name="radio" name="group2" value="option2"/><div class="control_indicator"></div></label>`
// }
validList.innerHTML+= `<label class="control control-radio">${langs[i]}<input type="radio" name="radio" name="group2" value="option2"/><div class="control_indicator"></div></label>`
}
for(let i = 0; i < langArr.length; i++){
if(i < 5){
invalidList.innerHTML += `<label class="control control-radio disabled">
${langArr[i]}
<input type="radio" name="radio" name="group2" value="option2" disabled/>
<div class="control_indicator"></div>
</label>`
}else{
invalidListHidden.innerHTML += `<label class="control control-radio disabled">
${langArr[i]}
<input type="radio" name="radio" name="group2" value="option2" disabled/>
<div class="control_indicator"></div>
</label>`
}
}
document.querySelector("#languageMore form").innerHTML+='<Button type="button" id="langButton" style="flex: 1; border: 2px solid #AF4591; border-radius: 4px; width: 100%; height: 40px; font-size: 14px; color: #AF4591; font-weight: 600; background-color: transparent; cursor: pointer;">View More Languages</Button>'
}
function showAllLanguages() {
let button = document.getElementById("langButton");
let hiddenList = document.getElementById('invalidLanguagesHidden');
hiddenList.classList.toggle("hidden");
if(hiddenList.classList.contains("hidden")){
button.innerText = "View More Languages"
}else{
button.innerText = "View Less Languages"
}
}document.getElementById("langButton").addEventListener("click", () => showAllLanguages());
function hospitalRender(...hosp){
let validList = document.getElementById("validHospitals");
let invalidList = document.getElementById("invalidHospitals");
let invalidListHidden = document.getElementById('invalidHospitalsHidden')
let hospArr = hospitals;
var index;
for (var i=0; i<hosp.length; i++) {
index = hospArr.indexOf(hosp[i]);
if (index > -1) {
hospArr.splice(index, 1);
}
}
validList.innerHTML = '';
invalidList.innerHTML = '';
for(let i = 0; i < hosp.length; i++){
// if (i == 0){
// validList.innerHTML += `<label class="control control-radio">${hosp[i]}<input type="radio" name="radio" checked="checked" name="group2" value="option2"/><div class="control_indicator"></div></label>`
// }else{
// validList.innerHTML+= `<label class="control control-radio">${hosp[i]}<input type="radio" name="radio" name="group2" value="option2"/><div class="control_indicator"></div></label>`
// }
validList.innerHTML+= `<label class="control control-radio">${hosp[i]}<input type="radio" name="radio" name="group2" value="option2"/><div class="control_indicator"></div></label>`
}
for(let i = 0; i < hospArr.length; i++){
if(i < 5){
invalidList.innerHTML += `<label class="control control-radio disabled">
${hospArr[i]}
<input type="radio" name="radio" name="group2" value="option2" disabled/>
<div class="control_indicator"></div>
</label>`
}else{
invalidListHidden.innerHTML += `<label class="control control-radio disabled">
${hospArr[i]}
<input type="radio" name="radio" name="group2" value="option2" disabled/>
<div class="control_indicator"></div>
</label>`
}
}
document.querySelector("#hospitalMore form").innerHTML+='<Button type="button" id="hospButton" style="flex: 1; border: 2px solid #AF4591; border-radius: 4px; width: 100%; height: 40px; font-size: 14px; color: #AF4591; font-weight: 600; background-color: transparent; cursor: pointer;">View More Hospitals</Button>'
}
function showAllHospitals() {
let button = document.getElementById("hospButton");
let hiddenList = document.getElementById('invalidHospitalsHidden');
hiddenList.classList.toggle("hidden");
if(hiddenList.classList.contains("hidden")){
button.innerText = "View More Hospitals"
}else{
button.innerText = "View Less Hospitals"
}
}document.getElementById("hospButton").addEventListener("click", () => showAllHospitals());
function windowResize(){
const moreMenu = document.getElementById("moreMenu")
const filters = document.getElementById("filter")
moreMenu.style.cssText = "";
if((moreMenu.offsetLeft + moreMenu.offsetWidth - 10) >= filters.offsetWidth){
moreMenu.style.cssText="right: 0;";
}
}window.addEventListener("resize", () => windowResize());
// For clicking on the 'X' of the chip. E is the "X" that is clicked
// and e.parentNode is the entire chip
function closeChip(e){
// console.log(e.parentNode)
// console.log(e)
e.parentNode.classList.add('hidden')
document.querySelector("#filter .option."+e.parentNode.innerText.split(" ").toString()).classList.remove("active")
document.querySelector("#filter .option." + e.parentNode.innerText.split(" ")[0].toString() + " .container").classList.remove("active");
fakeLoading(800);
if(e.parentNode.classList.contains("More")){
document.getElementById("moreMenu").classList.add("hidden");
document.getElementsByClassName('arrow-up')[0].style.cssText="visibility: hidden;";
}
let splicePoint = activeFilters.findIndex((x) => x == e.parentNode.innerText);
activeFilters.splice(splicePoint, 1);
if(activeFilters.includes("Accepting New Patients")){
dataInitalize(0, 20, true)
managePaginationLength();
}else{
dataInitalize(0, 20)
managePaginationLength();
}
if(activeFilters.length == 0){
document.getElementById('map').style.cssText = 'top: 150px; height: calc(100vh - 150px);'
document.getElementById("chips").innerHTML = ''
}else{
document.getElementById('map').style.cssText = 'top: 180px; height: calc(100vh - 180px);'
}
}
// Activates and hides filter settings
function clickFilter(e){
// console.log(e.classList.contains('active'))
e.querySelector('.container').classList.toggle('active')
e.classList.toggle('active');
// console.log(e.classList.contains('More'))
if(!activeFilters.includes(e.querySelector('.container p').innerText) && !e.classList.contains('More')){
activeFilters.push(e.querySelector('.container p').innerText);
fakeLoading(800);
}else{
if(!e.classList.contains('More')){
let splicePoint = activeFilters.findIndex((x) => x == e.querySelector('.container p').innerText)
activeFilters.splice(splicePoint, 1);
fakeLoading(800);
}
}
if(activeFilters.length == 0){
document.getElementById('map').style.cssText = 'top: 150px; height: calc(100vh - 150px);'
}else{
document.getElementById('map').style.cssText = 'top: 180px; height: calc(100vh - 180px);'
}
// Check for ANP
if(activeFilters.includes("Accepting New Patients")){
dataInitalize(0, 20, true)
managePaginationLength();
}else{
dataInitalize(0, 20)
managePaginationLength();
}
// console.log(activeFilters);
document.getElementById("chips").innerHTML = '';
for(let i = 0; i < activeFilters.length; i++){
document.getElementById("chips").innerHTML += '<div class="chip ' + activeFilters[i].split(" ")[0].toString() + '"><p>' + activeFilters[i] + '</p><a href="#searchFilters" onClick="closeChip(this)" class="close" style="padding: 8px;"><i class="fa fa-close" aria-hidden="true"></i></a></div>';
}
if(activeFilters.length !== 0){
document.getElementById("chips").innerHTML += '<a href="#searchFilters" onClick="clearAllFilters()" class="chip Clear"><p>Clear All</p></a>'
}else{
document.getElementById("chips").innerHTML = ''
}
}
// Call this function to fix pagination length when changing data
function managePaginationLength(){
document.getElementById("nums").innerHTML = "";
startResults = 0;
endResults = 20;
let length = Math.ceil(limitedFullArray.length/20);
for(let i = 0; i < length; i++){
if(i == 0){
document.getElementById("nums").innerHTML += '<a onClick="clickFunction(this)" href="#searchFilters"><h5 class="navLink 1 active">1</h5></a>'
}else{
document.getElementById("nums").innerHTML += '<a onClick="clickFunction(this)" href="#searchFilters"><h5 class="navLink ' + parseInt(i+1) + '">' + parseInt(i+1) + '</h5></a>'
}
}
let navArrows = document.getElementsByClassName('nav');
navArrows[0].classList.add('disabled')
navArrows[1].classList.remove('disabled')
}
// Pagination click function
function clickFunction(element){
var allNums = document.getElementsByClassName('navLink');
var t = element.getElementsByTagName('h5');
var target = t[0];
navArrows = document.getElementsByClassName('nav');
// this.classList.add("active");
if(element.classList.contains('nav') && element.classList.contains('disabled')){
}else if(element.classList.contains('navNext')){
navArrows[0].classList.remove('disabled');
// shuffle(myJson);
// dataInitalize();
for( var i = 0; i < allNums.length; i++){
if(allNums[i].classList.contains('active')){
startResults += 20;
endResults += 20;
// console.log(startResults + " " + endResults)
activeFilters.includes("Accepting New Patients") ? dataInitalize(startResults, endResults, true) : dataInitalize(startResults, endResults);
allNums[i].classList.remove('active');
allNums[i+1].classList.add('active');
break;
}
}
if(allNums[allNums.length-1].classList.contains('active')){
navArrows[1].classList.add('disabled')
navArrows[0].classList.remove('disabled')
}else{
navArrows[1].classList.remove('disabled')
}
}else if(element.classList.contains('navPrev')){
navArrows[1].classList.remove('disabled');
// shuffle(myJson);
// dataInitalize();
for( var i = 0; i < allNums.length; i++){
if(allNums[i].classList.contains('active')){
startResults -= 20;
endResults -= 20;
// console.log(startResults + " " + endResults)
activeFilters.includes("Accepting New Patients") ? dataInitalize(startResults, endResults, true) : dataInitalize(startResults, endResults);
allNums[i].classList.remove('active');
allNums[i-1].classList.add('active');
break;
}
}
if(allNums[0].classList.contains('active')){
navArrows[0].classList.add('disabled')
navArrows[1].classList.remove('disabled')
}else{
navArrows[0].classList.remove('disabled')
}
}else{
if(target.classList.contains('active')){
}else{
// shuffle(myJson);
// dataInitalize();
for( var i = 0; i < allNums.length; i++){
allNums[i].classList.remove('active');
}
target.classList.add('active');
if(target == allNums[0]){
startResults = 0;
endResults = 20;
// console.log(startResults + " " + endResults)
activeFilters.includes("Accepting New Patients") ? dataInitalize(startResults, endResults, true) : dataInitalize(startResults, endResults);
navArrows[0].classList.add('disabled')
navArrows[1].classList.remove('disabled')
}else if(target == allNums[allNums.length - 1]){
startResults = (allNums.length - 1) * 20;
endResults = limitedFullArray.length;
// console.log(startResults + " " + endResults)
activeFilters.includes("Accepting New Patients") ? dataInitalize(startResults, endResults, true) : dataInitalize(startResults, endResults);
navArrows[0].classList.remove('disabled')
navArrows[1].classList.add('disabled')
}else{
for(var i = 0; i < navArrows.length; i++){
navArrows[i].classList.remove('disabled')
}
startResults = (parseInt(target.innerText)-1) * 20
endResults = (parseInt(target.innerText)-1) * 20 + 20
// console.log(startResults + " " + endResults)
activeFilters.includes("Accepting New Patients") ? dataInitalize(startResults, endResults, true) : dataInitalize(startResults, endResults);
}
}
}
}