diff --git a/js/script.js b/js/script.js index 88530e7..3645f00 100644 --- a/js/script.js +++ b/js/script.js @@ -4,55 +4,51 @@ * cc by-nc-sa */ $(function(){ - var rotimageMoving = false; - - $("#rotimage").mouseover(function() { - if (!rotimageMoving) - { - rotimageMoving = true; - $("#rotimage").animate({ - height: "200px", - }, 300, "swing", function() { - rotimageMoving = false; - }); - } - }); - $("#rotimage").mouseout(function() { - if (!rotimageMoving) - { - rotimageMoving = true; - $("#rotimage").animate({ - height: "100px", - }, 300, "swing", function() { - rotimageMoving = false; - }); - } - }); - - $.get("/at", function(data) { - var jdata = JSON.parse(data); - var users = jdata.users.length; - - if (users > 0) - { - var text = 'According to our instruments there '; - if (users == 1) - text += 'is one person'; - else - text += 'are ' + users + ' people'; - text += ' at the hackerspace right now.'; - - $("#status-tooltip p").html(text); - $("#status img").attr("src", "/img/status-open.png"); - $("#status-tooltip").css("display", "block"); - $("#status").css("display", "block"); - } - else - { - $("#status img").attr("src", "/img/status-closed.png"); - $("#status").css("display", "block"); - } + var el = $("#rotimage"); + el.mouseenter(function() { + el.stop().animate({ + height: "200px", + }, 300, "swing"); }); + el.mouseleave(function() { + el.stop().animate({ + height: "100px", + }, 300, "swing"); + }); + + var at = function() { + $.get("/at", function(data) { + var jdata = JSON.parse(data); + var users = jdata.users.length; + var tooltip = $('#status-tooltip'); + var text = 'According to our instruments there '; + if (users == 1) + text += 'is one person'; + else if(users == 0) + text += 'is no one'; + else + text += 'are ' + users + ' people'; + text += ' at the hackerspace right now.'; + + $("#status-tooltip p").html(text); + if(users > 0) { + $("#status img").attr("src", "/img/status-open.png"); + tooltip.removeClass('status-tooltip-closed'); + tooltip.addClass('status-tooltip-open'); + } + else { + $("#status img").attr("src", "/img/status-closed.png"); + tooltip.removeClass('status-tooltip-open'); + tooltip.addClass('status-tooltip-closed'); + } + + $("#status").css('display', 'inline-block'); + $("#status-tooltip").css('display', 'inline-block'); + + }); + }; + setInterval(at, 1e3 * 300); + at(); }); diff --git a/test/static.py b/test/static.py index 110290c..2680c9a 100644 --- a/test/static.py +++ b/test/static.py @@ -8,6 +8,10 @@ def index(): @app.route('/at') def at(): +# return '{"users": []}' +# return '{"users": [[],[],[]]}' return urllib.urlopen("http://at.hackerspace.pl/api").read() -app.run() +if __name__ == '__main__': + app.debug = True + app.run(host='::')