blob: d4e7c47a28fd175ada6584dec321937c66dfb836 (
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
|
var Osika = function() {
var that = this;
that.resultTemplate = jQuery('#resultTemplate').remove().html();
that.handleData = function(data) {
jQuery('#evaluate').val('Oceń');
jQuery('#evaluate').removeAttr('disabled');
if (data.error) {
jQuery('#result').html('<div class="error">'+data.error+'</div>');
}
else {
var html = Mustache.to_html(that.resultTemplate, data);
jQuery('#result').html(html);
}
};
that.getHand = function(hand) {
jQuery('#evaluate').val('Czekaj...');
jQuery('#evaluate').attr('disabled', 'disabled');
jQuery.getJSON(
'osika.php',
{
'h': hand,
'f': 'json'
},
that.handleData
);
location.hash = hand;
};
that.init = function() {
jQuery('#evaluate').unbind('click').click(function () {
var hand = jQuery('#suit0').val()+'|'+jQuery('#suit1').val()+'|'+jQuery('#suit2').val()+'|'+jQuery('#suit3').val();
that.getHand(hand);
return false;
});
if (location.hash) {
var hand = location.hash.substring(1).split('|');
for (h = 0; h < hand.length; h++) {
jQuery('#suit'+h).val(hand[h]);
}
that.getHand(location.hash.substring(1));
}
jQuery(window).on('hashchange', that.init);
};
that.init();
};
jQuery(document).ready(function () {
var o = new Osika();
});
|