This repository has been archived by the owner on Dec 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
79 lines (73 loc) · 2.36 KB
/
app.js
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
function Player (name, points) {
this.name = name;
this.points = points;
this.setName = function(name) {
this.name = name;
};
this.setPoints = function(points){
this.points = points;
};
this.addPoint = function(){
this.points++;
};
this.persist = function(id){
if(id === 1){
// Check browser support
if (typeof(Storage) != "undefined") {
localStorage.setItem("player1_name", this.name);
localStorage.setItem("player1_points", this.points);
} else {
alert("Sorry, your browser does not support Web Storage...");
}
} else
if(id === 2){
// Check browser support
if (typeof(Storage) != "undefined") {
localStorage.setItem("player1_name", this.name);
localStorage.setItem("player1_points", this.points);
} else {
alert("Sorry, your browser does not support Web Storage...");
}
}
};
this.loadData = function(id){
if(id === 1){
if (typeof(Storage) != "undefined") {
// Retrieve
this.name = localStorage.getItem("player1_name");
this.points = localStorage.getItem("player1_points");
} else {
alert("Sorry, your browser does not support Web Storage...");
}
} else if(id === 2){
// Retrieve
this.name = localStorage.getItem("player1_name");
this.points = localStorage.getItem("player1_points");
} else {
alert("Sorry, your browser does not support Web Storage...");
}
};
this.showData = function(id){
if(id === 1){
$('#1name').empty().append(this.name);
$('#p1points').empty().append(this.points);
} else
if(id === 2){
$('#2name').empty().append(this.name);
$('#p2points').empty().append(this.points);
}
};
}
jQuery(document).ready(function($) {
events();
});
function playerSelectorAddPoints(){
if(activePane === 1){
player1.events();
}else if(activePane === 2){
player2.events();
}
}
var player1 = new Player('Player 1',0);
var player2 = new Player('Player 2',0);
var activePane = 1;