Path: blob/main/ehtsite/assets/games/subway/js/loading.js
2252 views
/* eslint-disable prefer-template */1/* eslint-disable func-names */2/* eslint-disable no-var */34function LoadingBar()5{6var showing = false;7var width = 300;8var height = 30;9var border = 4;10var total = 0;1112var container = document.createElement('div');1314container.style.position = 'fixed';15container.style.width = width + 'px';16container.style.height = height + 'px';17container.style.zIndex = 999;1819var base = document.createElement('div');2021base.style.position = 'absolute';22base.style.width = width + 'px';23base.style.height = height + 'px';24base.style.backgroundColor = 'rgba(0, 0, 0, 0.75)';25container.appendChild(base);2627var bar = document.createElement('div');2829bar.style.position = 'absolute';30bar.style.left = border + 'px';31bar.style.top = border + 'px';32bar.style.width = (width - (border * 2)) + 'px';33bar.style.height = (height - (border * 2)) + 'px';34bar.style.backgroundColor = '#f65000';35container.appendChild(bar);3637var label = document.createElement('div');3839label.style.position = 'fixed';40label.style.width = width + 'px';41label.style.height = height + 'px';42label.style.lineHeight = height + 'px';43label.style.textAlign = 'center';44label.style.color = '#FFFFFF';45label.style.fontWeight = 'bold';46label.style.fontSize = '12px';47label.style.fontFamily = '"Verdana", sans-serif';48container.appendChild(label);4950function resize()51{52container.style.left = ((window.innerWidth * 0.5) - (width * 0.5)) + 'px';53container.style.top = ((window.innerHeight * 0.5) + 120) + 'px';54}5556function show()57{58if (showing) return;59showing = true;60document.body.appendChild(container);61window.addEventListener('resize', resize);62setProgress(0);63resize();64}6566function hide()67{68if (!showing) return;69showing = false;70container.remove();71window.removeEventListener('resize', resize);72}7374function setTotal(mbs)75{76total = mbs;77}7879function setProgress(ratio)80{81if (ratio < 0) ratio = 0;82if (ratio > 1) ratio = 1;8384var barMaxWidth = width - (border * 2);85var percent = Math.round(ratio * 100) + '%';8687bar.style.width = (barMaxWidth * ratio) + 'px';8889if (total)90{91var loaded = (total * ratio).toFixed(1);92var mbs = loaded + '/' + total + ' MB';9394label.innerText = percent + ' - ' + mbs;95}96else97{98label.innerText = percent;99}100}101102show();103this.show = show;104this.hide = hide;105this.setTotal = setTotal;106this.setProgress = setProgress;107}108109window.loadingBar = new LoadingBar();110111112