summaryrefslogtreecommitdiffstats
path: root/js/game.js
blob: 06457bea4b6a1104c7286ab5ca027ca968ee8432 (plain)
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
/* some code to highlight the current trick and to switch between different tricks */
/* which trick is currently highlighted*/
var current=0;

/* do the higlighting */
function hl(num) {
    var i;
    for(i=0;i<14;i++){	$("#trick"+i).hide(); $("#tricks"+i).removeClass('active'); }
    $("#trick"+num).css('display', 'block');
    $("#tricks"+num).addClass('active');
    current=num;

    if(document.getElementById("tricks0"))
	min=0;
    else
	min=1;

    if(document.getElementById("tricks13"))
	max=13;
    else
	max=12;

    if(current==min)
	$("#prevtr").addClass('disabled');
    else
	$("#prevtr").removeClass('disabled');
    if(current==max)
	$("#nexttr").addClass('disabled');
    else
	$("#nexttr").removeClass('disabled');

}

/* highlight the last trick, useful when a page is called the first time*/
function high_last(){
    if(document.getElementById){
	var i;
	for(i=13;i>=0;i--) {
	    if(document.getElementById("trick"+i))
		{
		    hl(i);
		    current=i;
		    break;
		}
	}
    }
}

/* highlight the next trick */
function hl_next()
{
    if(document.getElementById("trick"+(current+1)))
	hl(current+1);
}

/* highlight the previous trick */
function hl_prev()
{
    if(document.getElementById("trick"+(current-1)))
	hl(current-1);
}

/* check for swipes */
var down_x = null;
var up_x = null;

/* advance trick according to swipe direction */
function do_swipe()
{
    if ((down_x - up_x) > 50)  { hl_prev(); }
    if ((up_x - down_x) > 50)  { hl_next(); }
}


$(document).ready(
    function()
    {
	$("#ScoreTable").tablesorter({ widgets: ['zebra']});

	$(".gameshidesession").click( function () {
	    $(this).parent().children(".gamessession").hide(300);
	    $(this).parent().children(".gamesshowsession").show();
	    $(this).hide();
	});

	$(".gamesshowsession").click( function () {
	    $(this).parent().children(".gamessession").show(300);
	    $(this).parent().children(".gameshidesession").show();
	    $(this).hide();
	});

	$(".gameshowall").click( function () {
	    $(".gamessession").show(300);
	    $(".gamesshowsession").hide();
	    $(".gameshidesession").show();
	});
	$(".gamehideall").click( function () {
	    $(".gamessession").hide(300);
	    $(".gamesshowsession").show();
	    $(".gameshidesession").hide();
	});

	$(".message div div").parent().click ( function() { $(this).hide(); });
    });

/* look for swipes left/right */
$().ready(function(){
	$("div.table").mousedown(function(e){
	    down_x = e.pageX;
	});
	$("div.table").mouseup(function(e){
	    up_x = e.pageX;
	    do_swipe();
	});
	$("div.table").bind('touchstart', function(e){
	    down_x = e.originalEvent.touches[0].pageX;
	});
	$("div.table").bind('touchmove', function(e){
	    up_x = e.originalEvent.touches[0].pageX;
	});
	$("div.table").bind('touchend', function(e){
	    do_swipe();
	});
});