Lose code supporting loading jquery. Check for no browser with !document.

This commit is contained in:
Eric Fredricksen
2010-07-14 22:24:53 -07:00
parent 7e9648e192
commit 2941fb29be
3 changed files with 36 additions and 71 deletions
+5 -3
View File
@@ -496,6 +496,7 @@ function ListBox(id, columns, fixedkeys) {
this.remove0 = function (n) {
if (game[this.id])
game[this.id].shift();
if (this.box)
this.box.find("tr").first().remove();
};
@@ -503,6 +504,7 @@ function ListBox(id, columns, fixedkeys) {
var t = game[this.id].shift();
game[this.id].shift();
game[this.id].unshift(t);
if (this.box)
this.box.find("tr").eq(1).remove();
};
@@ -543,7 +545,7 @@ function StrToIntDef(s, def) {
}
if (!navigator.v8)
if (document)
$(document).ready(FormCreate);
@@ -940,7 +942,7 @@ function FormCreate() {
AllLists = [Traits,Stats,Spells,Equips,Inventory,Plots,Quests];
if (!navigator.v8) {
if (document) {
Kill = $("#Kill");
$("#quit").click(quit);
@@ -986,7 +988,7 @@ function LoadCharacter() {
LoadGame(sheet);
if (!navigator.v8)
if (document)
$("#title").text("Progress Quest - " + GameSaveName());
if (window.location.href.indexOf("?quit#") > 0)
+7 -7
View File
@@ -3,7 +3,7 @@
function Roll(stat) {
stats[stat] = 3 + Random(6) + Random(6) + Random(6);
if (!navigator.v8)
if (document)
$("#"+stat).text(stats[stat]);
return stats[stat];
}
@@ -44,7 +44,7 @@ function RollEm() {
(total < (3 * 18)) ? 'silver' :
'white';
if (!navigator.v8) {
if (document) {
var Total = $("#Total");
Total.text(total);
Total.css("background-color", color);
@@ -70,7 +70,7 @@ function fill(e, a, n) {
var v = a[i].split("|")[0];
var check = (def == i) ? " checked " : " ";
if (def == i) traits[n] = v;
if (!navigator.v8) {
if (document) {
$("<div><input type=radio id='" + v + "' name=\"" + n + "\" value=\"" + v + "\" " +
check +"><label for='" + v + "'>" + v + "</label></div>").appendTo(e);
}
@@ -85,7 +85,7 @@ function NewGuyFormLoad() {
fill("#races", K.Races, "Race");
fill("#classes", K.Klasses, "Class");
if (!navigator.v8) {
if (document) {
$("#Reroll").click(RerollClick);
$("#Unroll").click(UnrollClick);
$("#RandomName").click(GenClick);
@@ -105,7 +105,7 @@ function NewGuyFormLoad() {
}
if (!navigator.v8)
if (document)
$(document).ready(NewGuyFormLoad);
/* Multiplayer:
@@ -191,7 +191,7 @@ function sold() {
]
};
if (!navigator.v8) {
if (document) {
newguy.Traits.Name = $("#Name").val();
newguy.Traits.Race = $("input:radio[name=Race]:checked").val();
newguy.Traits.Class = $("input:radio[name=Class]:checked").val();
@@ -219,7 +219,7 @@ function cancel() {
function GenClick() {
traits.Name = GenerateName();
if (!navigator.v8)
if (document)
$("#Name").attr("value", traits.Name);
}
+22 -59
View File
@@ -1,68 +1,39 @@
//!/usr/bin/env v8
function noop() {}
function nada() { return {}; }
var document = {
addEventListener: noop,
createElement: function () {
var result = {
style: {},
getElementsByTagName: nada,
appendChild: noop,
};
result.lastChild = result;
return result;
},
documentElement: {
insertBefore: noop,
removeChild: noop,
},
getElementById: nada,
createComment: noop,
createDocumentFragment: nada,
};
var window = {
location: {href: "#Woogle"},
localStorage: {
items: {},
items: null,
getItem: function(key) {
if (!this.items) {
try {
this.items = JSON.parse(read("local.storage"));
} catch (e) {
print(e);
this.items = {};
}
}
return this.items[key];
},
setItem: function (key, value) {
this.items[key] = value;
write("local.storage", JSON.stringify(this.items));
},
removeItem: function (key) {
delete this.items[key];
write("local.storage", JSON.stringify(this.items));
}
},
document: document,
addEventListener: noop,
};
var location = window.location;
var v8 = true;
var $ = function () {
return null;
return {
click: noop,
keypress: noop,
ready: noop,
unload: noop,
bind: noop,
text: noop,
appendTo: noop,
attr: noop,
focus: noop,
select: noop,
};
};
var $ = function () { return null; };
$.isFunction = function (obj) {
return toString.call(obj) === "[object Function]";
},
@@ -87,21 +58,10 @@ $.each = function (object, callback) {
return object;
}
var document = null;
var navigator = {
v8: true,
userAgent: "V8 Shell"
};
var alert = function (m) { print("ALERT: " + m); };
var randseed = function () {};
try {
window.localStorage.items = JSON.parse(read("local.storage"));
} catch (e) {
print(e);
window.localStorage.items = {};
}
var now = 0;
var timers = [{}];
function setInterval(callback, interval) {
@@ -109,10 +69,13 @@ function setInterval(callback, interval) {
return timers.length-1;
}
//load("jquery.js");
//var $ = window.$;
load("config.js");
var cs = 0;
for (var c in loadRoster())
cs++;
print(cs, "characters");
load("newguy.js");
NewGuyFormLoad();
sold();
@@ -129,11 +92,11 @@ timeGetTime = function () {
return now;
}
for (var i = 0; i < 1000; ++i) {
for (var i = 0; i < 100000; ++i) {
//assert(timers.id == 1);// TODO: this is for simplicity
now += timers[1].interval;
timers[1].callback();
}
SaveGame();
print(guy, game.elapsed, game.tasks, game.task);//JSON.stringify(loadSheet(guy)));
print(guy, game.elapsed, game.tasks, game.Traits.Level, game.task);//JSON.stringify(loadSheet(guy)));