forked from shafiul/minesweeper
/
ranking.html
67 lines (51 loc) · 2.21 KB
/
ranking.html
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
<html>
<head>
<title>Minesweeper - The Open Web HTML5 Game!</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="scripts/jquery.js" ></script>
<script src="scripts/common.js" ></script>
<script src="scripts/jquery.mobile-1.2.0.js" ></script>
<script src="scripts/Ranking.js" ></script>
<link rel="stylesheet" href="style/jquery.mobile-1.2.0.css" type="text/css" />
</head>
<body>
<div data-role="page" data-theme="c">
<div data-role="header" >
<a href="index.html" data-icon="home">Home</a>
<h1>Hall of Fame</h1>
</div><!-- /header -->
<div data-role="content">
<h4>Top Scores</h4>
<ul id="rankList" data-role="listview"></ul>
<br />
<a href="#" id="clearBtn" data-role="button" data-inline="true" data-icon="delete" data-theme="b" >Clear all</a>
</div><!-- /content -->
</div><!-- /page -->
<script>
// Populate top-score listview
var rankOb = new Ranking();
var allData = rankOb.getAll();
var markup = '';
if(allData){
for(var i=0; i<allData.length; i++){
markup += '<li>' + allData[i].playerName + '<span class="ui-li-count">' + allData[i].numMines
+ 'mines, ' + allData[i].penalty.toFixed(2) + ' penalty</span>' + '</li>';
}
}else{
markup = '<li>No record found</li>';
// Also disable the button
$('#clearBtn').addClass('ui-disabled');
}
$('#rankList').html(markup);
// Event Binding
$('#clearBtn').tap(function(event){
console.log('clr btn clicked');
if(confirm('Are you sure to clear all data? This can not be undone.')){
localStorage.removeItem(rankOb.storageKey);
window.location.reload();
}
});
</script>
</body>
</html>