BUGFIX: fix password for password recovery (was not random enough)
[e-DoKo.git] / js / game.js
1 /* some code to highlight the current trick and to switch between different tricks */
2 /* which trick is currently highlighted*/
3 var current=0;
4
5 /* do the higlighting */
6 function hl(num) {
7     var i;
8     for(i=0;i<14;i++){  $("#trick"+i).hide(); $("#tricks"+i).removeClass('active'); }
9     $("#trick"+num).css('display', 'block');
10     $("#tricks"+num).addClass('active');
11     current=num;
12
13     if(document.getElementById("tricks0"))
14         min=0;
15     else
16         min=1;
17
18     if(document.getElementById("tricks13"))
19         max=13;
20     else
21         max=12;
22
23     if(current==min)
24         $("#prevtr").addClass('disabled');
25     else
26         $("#prevtr").removeClass('disabled');
27     if(current==max)
28         $("#nexttr").addClass('disabled');
29     else
30         $("#nexttr").removeClass('disabled');
31
32 }
33
34 /* highlight the last trick, useful when a page is called the first time*/
35 function high_last(){
36     if(document.getElementById){
37         var i;
38         for(i=13;i>=0;i--) {
39             if(document.getElementById("trick"+i))
40                 {
41                     hl(i);
42                     current=i;
43                     break;
44                 }
45         }
46     }
47 }
48
49 /* highlight the next trick */
50 function hl_next()
51 {
52     if(document.getElementById("trick"+(current+1)))
53         hl(current+1);
54 }
55
56 /* highlight the previous trick */
57 function hl_prev()
58 {
59     if(document.getElementById("trick"+(current-1)))
60         hl(current-1);
61 }
62
63 /* check for swipes */
64 var down_x = null;
65 var up_x = null;
66
67 /* advance trick according to swipe direction */
68 function do_swipe()
69 {
70     if ((down_x - up_x) > 50)  { hl_prev(); }
71     if ((up_x - down_x) > 50)  { hl_next(); }
72 }
73
74
75 $(document).ready(
76     function()
77     {
78         $("#ScoreTable").tablesorter({ widgets: ['zebra']});
79
80         $(".gameshidesession").click( function () {
81             $(this).parent().children(".gamessession").hide(300);
82             $(this).parent().children(".gamesshowsession").show();
83             $(this).hide();
84         });
85
86         $(".gamesshowsession").click( function () {
87             $(this).parent().children(".gamessession").show(300);
88             $(this).parent().children(".gameshidesession").show();
89             $(this).hide();
90         });
91
92         $(".gameshowall").click( function () {
93             $(".gamessession").show(300);
94             $(".gamesshowsession").hide();
95             $(".gameshidesession").show();
96         });
97         $(".gamehideall").click( function () {
98             $(".gamessession").hide(300);
99             $(".gamesshowsession").show();
100             $(".gameshidesession").hide();
101         });
102
103         $(".message div div").parent().click ( function() { $(this).hide(); });
104
105         /* look for swipes left/right */
106         $("div.table").mousedown(function(e){
107             down_x = e.pageX;
108         });
109         $("div.table").mouseup(function(e){
110             up_x = e.pageX;
111             do_swipe();
112         });
113         $("div.table").bind('touchstart', function(e){
114             down_x = e.originalEvent.touches[0].pageX;
115         });
116         $("div.table").bind('touchmove', function(e){
117             up_x = e.originalEvent.touches[0].pageX;
118         });
119         $("div.table").bind('touchend', function(e){
120             do_swipe();
121         });
122
123     });