Sort of early start on roster page

This commit is contained in:
Eric Fredricksen
2010-06-27 22:01:12 -07:00
parent 8a121c1f7c
commit ca2f9b30c3
3 changed files with 63 additions and 1 deletions
+19
View File
@@ -120,6 +120,25 @@ function GenerateName() {
}
function loadRoster() {
if (!window.localStorage) {
return;
} else {
var roster = window.localStorage.getItem("roster");
roster = roster ? JSON.parse(roster) : [];
//if (!$.isArray(roster))
// roster = [];
return roster;
}
}
function storeRoster(roster) {
window.localStorage.setItem("roster", JSON.stringify(roster));
}
function addToRoster(newguy) {
storeRoster(loadRoster().concat([newguy]));
}
var K = {};
+1 -1
View File
@@ -144,7 +144,7 @@ function sold() {
$.each('STR,CON,DEX,INT,WIS,CHA'.split(','), function (index,value) {
newguy[value] = stats[value];
});
alert(JSON.stringify(newguy));
addToRoster(JSON.stringify(newguy));
}
function GenClick() {
+43
View File
@@ -0,0 +1,43 @@
<script src="jquery.js"></script>
<script src="config.js"></script>
<dl id=roster>
Here it goes
</dl>
<script>
$(document).ready(function () {
var roster = $("#roster");
roster.text("Loading...");
var games = loadRoster()
if (!games) {
roster.text("No local storage");
return;
}
$.each(games, function (index, element) {
var p = $("<dt/>");
p.appendTo(roster);
p.text(element.name);
p = $("<dd/>");
p.appendTo(roster);
p.text(JSON.stringify(element));
});
var b = $("<button>Test</button>");
b.appendTo(roster);
b.click(function () {
games.push({testy: "betsy"});
storeRoster(games);
});
var b = $("<button>Clear</button>");
b.appendTo(roster);
b.click(function () {
games = [];
storeRoster();
});
});
</script>