mirror of
https://github.com/Doodle3D/doodle3d-connect.git
synced 2024-12-25 01:53:48 +01:00
Better loading feedback
This commit is contained in:
parent
28108b2004
commit
5ed5767903
@ -0,0 +1,7 @@
|
|||||||
|
#preloader {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 814 B After Width: | Height: | Size: 814 B |
@ -14,11 +14,13 @@
|
|||||||
<link href="css/main.css" rel="stylesheet" media="screen">
|
<link href="css/main.css" rel="stylesheet" media="screen">
|
||||||
|
|
||||||
<script src="js/libs/jquery-1.8.3.min.js" type="text/javascript"></script>
|
<script src="js/libs/jquery-1.8.3.min.js" type="text/javascript"></script>
|
||||||
|
<script src="js/libs/spin.min.js" type="text/javascript"></script>
|
||||||
<script src="js/main.js" type="text/javascript"></script>
|
<script src="js/main.js" type="text/javascript"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<p>Hi, we found the following Doodle3D WiFi boxes near you:</p>
|
<p id="intro"></p>
|
||||||
<ul id="list">
|
<ul id="list"></ul>
|
||||||
</ul>
|
<div id="preloader"></div>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
1
js/libs/spin.min.js
vendored
Normal file
1
js/libs/spin.min.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
(function(t,e){if(typeof exports=="object")module.exports=e();else if(typeof define=="function"&&define.amd)define(e);else t.Spinner=e()})(this,function(){"use strict";var t=["webkit","Moz","ms","O"],e={},i;function o(t,e){var i=document.createElement(t||"div"),o;for(o in e)i[o]=e[o];return i}function n(t){for(var e=1,i=arguments.length;e<i;e++)t.appendChild(arguments[e]);return t}var r=function(){var t=o("style",{type:"text/css"});n(document.getElementsByTagName("head")[0],t);return t.sheet||t.styleSheet}();function s(t,o,n,s){var a=["opacity",o,~~(t*100),n,s].join("-"),f=.01+n/s*100,l=Math.max(1-(1-t)/o*(100-f),t),u=i.substring(0,i.indexOf("Animation")).toLowerCase(),d=u&&"-"+u+"-"||"";if(!e[a]){r.insertRule("@"+d+"keyframes "+a+"{"+"0%{opacity:"+l+"}"+f+"%{opacity:"+t+"}"+(f+.01)+"%{opacity:1}"+(f+o)%100+"%{opacity:"+t+"}"+"100%{opacity:"+l+"}"+"}",r.cssRules.length);e[a]=1}return a}function a(e,i){var o=e.style,n,r;i=i.charAt(0).toUpperCase()+i.slice(1);for(r=0;r<t.length;r++){n=t[r]+i;if(o[n]!==undefined)return n}if(o[i]!==undefined)return i}function f(t,e){for(var i in e)t.style[a(t,i)||i]=e[i];return t}function l(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var o in i)if(t[o]===undefined)t[o]=i[o]}return t}function u(t){var e={x:t.offsetLeft,y:t.offsetTop};while(t=t.offsetParent)e.x+=t.offsetLeft,e.y+=t.offsetTop;return e}function d(t,e){return typeof t=="string"?t:t[e%t.length]}var p={lines:12,length:7,width:5,radius:10,rotate:0,corners:1,color:"#000",direction:1,speed:1,trail:100,opacity:1/4,fps:20,zIndex:2e9,className:"spinner",top:"auto",left:"auto",position:"relative"};function c(t){if(typeof this=="undefined")return new c(t);this.opts=l(t||{},c.defaults,p)}c.defaults={};l(c.prototype,{spin:function(t){this.stop();var e=this,n=e.opts,r=e.el=f(o(0,{className:n.className}),{position:n.position,width:0,zIndex:n.zIndex}),s=n.radius+n.length+n.width,a,l;if(t){t.insertBefore(r,t.firstChild||null);l=u(t);a=u(r);f(r,{left:(n.left=="auto"?l.x-a.x+(t.offsetWidth>>1):parseInt(n.left,10)+s)+"px",top:(n.top=="auto"?l.y-a.y+(t.offsetHeight>>1):parseInt(n.top,10)+s)+"px"})}r.setAttribute("role","progressbar");e.lines(r,e.opts);if(!i){var d=0,p=(n.lines-1)*(1-n.direction)/2,c,h=n.fps,m=h/n.speed,y=(1-n.opacity)/(m*n.trail/100),g=m/n.lines;(function v(){d++;for(var t=0;t<n.lines;t++){c=Math.max(1-(d+(n.lines-t)*g)%m*y,n.opacity);e.opacity(r,t*n.direction+p,c,n)}e.timeout=e.el&&setTimeout(v,~~(1e3/h))})()}return e},stop:function(){var t=this.el;if(t){clearTimeout(this.timeout);if(t.parentNode)t.parentNode.removeChild(t);this.el=undefined}return this},lines:function(t,e){var r=0,a=(e.lines-1)*(1-e.direction)/2,l;function u(t,i){return f(o(),{position:"absolute",width:e.length+e.width+"px",height:e.width+"px",background:t,boxShadow:i,transformOrigin:"left",transform:"rotate("+~~(360/e.lines*r+e.rotate)+"deg) translate("+e.radius+"px"+",0)",borderRadius:(e.corners*e.width>>1)+"px"})}for(;r<e.lines;r++){l=f(o(),{position:"absolute",top:1+~(e.width/2)+"px",transform:e.hwaccel?"translate3d(0,0,0)":"",opacity:e.opacity,animation:i&&s(e.opacity,e.trail,a+r*e.direction,e.lines)+" "+1/e.speed+"s linear infinite"});if(e.shadow)n(l,f(u("#000","0 0 4px "+"#000"),{top:2+"px"}));n(t,n(l,u(d(e.color,r),"0 0 1px rgba(0,0,0,.1)")))}return t},opacity:function(t,e,i){if(e<t.childNodes.length)t.childNodes[e].style.opacity=i}});function h(){function t(t,e){return o("<"+t+' xmlns="urn:schemas-microsoft.com:vml" class="spin-vml">',e)}r.addRule(".spin-vml","behavior:url(#default#VML)");c.prototype.lines=function(e,i){var o=i.length+i.width,r=2*o;function s(){return f(t("group",{coordsize:r+" "+r,coordorigin:-o+" "+-o}),{width:r,height:r})}var a=-(i.width+i.length)*2+"px",l=f(s(),{position:"absolute",top:a,left:a}),u;function p(e,r,a){n(l,n(f(s(),{rotation:360/i.lines*e+"deg",left:~~r}),n(f(t("roundrect",{arcsize:i.corners}),{width:o,height:i.width,left:i.radius,top:-i.width>>1,filter:a}),t("fill",{color:d(i.color,e),opacity:i.opacity}),t("stroke",{opacity:0}))))}if(i.shadow)for(u=1;u<=i.lines;u++)p(u,-2,"progid:DXImageTransform.Microsoft.Blur(pixelradius=2,makeshadow=1,shadowopacity=.3)");for(u=1;u<=i.lines;u++)p(u);return n(e,l)};c.prototype.opacity=function(t,e,i,o){var n=t.firstChild;o=o.shadow&&o.lines||0;if(n&&e+o<n.childNodes.length){n=n.childNodes[e+o];n=n&&n.firstChild;n=n&&n.firstChild;if(n)n.opacity=i}}}var m=f(o("group"),{behavior:"url(#default#VML)"});if(!a(m,"transform")&&m.adj)h();else i=a(m,"animation");return c});
|
98
js/main.js
98
js/main.js
@ -1,52 +1,108 @@
|
|||||||
var retrieveListDelay; // retry setTimout instance
|
|
||||||
var retrieveListInterval = 5000;
|
var retrieveListInterval = 2000;
|
||||||
var boxTimeoutTime = 300;
|
var retrieveListDelay; // retry setTimout instance
|
||||||
|
var boxTimeoutTime = 300;
|
||||||
|
|
||||||
|
var numBoxesChecking = 0; // count how many boxes we are checking
|
||||||
|
var numBoxesFound = 0; // count how many boxes responded
|
||||||
|
|
||||||
var $list;
|
var $list;
|
||||||
|
var $intro;
|
||||||
|
var $preloader;
|
||||||
|
var spinner;
|
||||||
|
|
||||||
$(function() {
|
$(function() {
|
||||||
//console.log("ready");
|
//console.log("ready");
|
||||||
|
|
||||||
|
$intro = $("#intro");
|
||||||
|
$list = $("#list");
|
||||||
|
$preloader = $("#preloader");
|
||||||
|
|
||||||
|
var spinnerSettings = {
|
||||||
|
lines: 13, // The number of lines to draw
|
||||||
|
length: 5, // The length of each line
|
||||||
|
width: 3, // The line thickness
|
||||||
|
radius: 7, // The radius of the inner circle
|
||||||
|
corners: 1, // Corner roundness (0..1)
|
||||||
|
rotate: 0, // The rotation offset
|
||||||
|
direction: 1, // 1: clockwise, -1: counterclockwise
|
||||||
|
color: '#58C143', // #rgb or #rrggbb or array of colors
|
||||||
|
speed: 1, // Rounds per second
|
||||||
|
trail: 60, // Afterglow percentage
|
||||||
|
shadow: false, // Whether to render a shadow
|
||||||
|
hwaccel: false, // Whether to use hardware acceleration
|
||||||
|
className: 'spinner', // The CSS class to assign to the spinner
|
||||||
|
zIndex: 2e9, // The z-index (defaults to 2000000000)
|
||||||
|
top: 'auto', // Top position relative to parent in px
|
||||||
|
left: 'auto' // Left position relative to parent in px
|
||||||
|
};
|
||||||
|
spinner = new Spinner(spinnerSettings);
|
||||||
|
spinner.spin($preloader[0]);
|
||||||
|
|
||||||
retrieveList();
|
retrieveList();
|
||||||
|
|
||||||
$list = $("#list");
|
|
||||||
})
|
})
|
||||||
function retrieveList() {
|
function retrieveList() {
|
||||||
$.ajax({
|
$preloader.show();
|
||||||
url: "list.php",
|
//spinner.spin($preloader[0]);
|
||||||
dataType: 'json',
|
|
||||||
timeout: boxTimeoutTime,
|
$.ajax({
|
||||||
success: function(response){
|
url: "list.php",
|
||||||
//console.log("retrieveList response: ",response);
|
dataType: 'json',
|
||||||
if(response.status == "success") {
|
success: function(response){
|
||||||
updateList(response.data);
|
//console.log("retrieveList response: ",response);
|
||||||
}
|
if(response.status == "success") {
|
||||||
clearTimeout(retrieveListDelay);
|
updateList(response.data);
|
||||||
retrieveListDelay = setTimeout(retrieveList, retrieveListInterval);
|
}
|
||||||
}
|
|
||||||
}).fail(function() {
|
|
||||||
//console.log("retrieveList: failed");
|
|
||||||
clearTimeout(retrieveListDelay);
|
clearTimeout(retrieveListDelay);
|
||||||
retrieveListDelay = setTimeout(retrieveList, retrieveListInterval); // retry after delay
|
retrieveListDelay = setTimeout(retrieveList, retrieveListInterval);
|
||||||
});
|
}
|
||||||
|
}).fail(function() {
|
||||||
|
//console.log("retrieveList: failed");
|
||||||
|
clearTimeout(retrieveListDelay);
|
||||||
|
retrieveListDelay = setTimeout(retrieveList, retrieveListInterval); // retry after delay
|
||||||
|
});
|
||||||
}
|
}
|
||||||
function updateList(boxes) {
|
function updateList(boxes) {
|
||||||
$list.empty();
|
$list.empty();
|
||||||
|
numBoxesChecking = 0;
|
||||||
|
numBoxesFound = 0;
|
||||||
jQuery.each(boxes, function (index,box) {
|
jQuery.each(boxes, function (index,box) {
|
||||||
checkBox(box);
|
checkBox(box);
|
||||||
});
|
});
|
||||||
|
updateIntro();
|
||||||
}
|
}
|
||||||
function checkBox(box) {
|
function checkBox(box) {
|
||||||
|
numBoxesChecking++;
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "http://"+box.localip+"/d3dapi/network/status",
|
url: "http://"+box.localip+"/d3dapi/network/status",
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
|
timeout: boxTimeoutTime,
|
||||||
success: function(response){
|
success: function(response){
|
||||||
if(response.status == "success") {
|
if(response.status == "success") {
|
||||||
|
numBoxesFound++;
|
||||||
var url = "http://"+box.localip;
|
var url = "http://"+box.localip;
|
||||||
if(boxIsListed(url)) return;
|
if(boxIsListed(url)) return;
|
||||||
|
|
||||||
$list.append("<li><a href='"+url+"'>"+box.wifiboxid+"</a></li>");
|
$list.append("<li><a href='"+url+"'>"+box.wifiboxid+"</a></li>");
|
||||||
}
|
}
|
||||||
|
numBoxesChecking--;
|
||||||
|
updateIntro();
|
||||||
}
|
}
|
||||||
|
}).fail(function() {
|
||||||
|
numBoxesChecking--;
|
||||||
|
updateIntro();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function boxIsListed(url){
|
function boxIsListed(url){
|
||||||
return $list.find("a[href|='"+url+"']").length > 0;
|
return $list.find("a[href|='"+url+"']").length > 0;
|
||||||
|
}
|
||||||
|
function updateIntro() {
|
||||||
|
if(numBoxesChecking <= 0) {
|
||||||
|
if(numBoxesFound > 0) {
|
||||||
|
$intro.html("Found the following boxes near you:");
|
||||||
|
} else {
|
||||||
|
$intro.html("No boxes found near you.");
|
||||||
|
}
|
||||||
|
$preloader.fadeOut(1000);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user