-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
85 lines (72 loc) · 2.41 KB
/
index.js
File metadata and controls
85 lines (72 loc) · 2.41 KB
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
80
81
82
83
84
85
var express = require('express');
var jsdom = require('jsdom');
var http = require('http');
var path = require('path');
var fs = require('fs');
var url = require('url');
var app = express();
var jquery = require('jquery');
app.use('*', function (req, res, next) {
if (req.baseUrl === "") {
jsdom.env(__dirname + '/index.html', function (errors, window) {
var $ = (jquery)(window);
var loaded = load_character(req.query['set'], req.query['character'], $);
load_cards(req.query['base'], req.query['style'], $);
res.write($("html")[0].innerHTML);
res.end();
});
}
else {
next();
}
});
app.use(express.static(__dirname + '/'));
var server = app.listen(process.env.PORT || 8081, function () {
var host = server.address().address
var port = server.address().port
console.log("Battlecon Visual listening at http://%s:%s", host, port)
});
function documentToSource(doc) {
return doc.doctype.toString() + doc.innerHTML;
}
function call_jsdom(source, callback) {
jsdom.env(
source,
['jquery-1.7.1.min.js'],
function (errors, window) {
process.nextTick(
function () {
if (errors) {
throw new Error("There were errors: " + errors);
}
callback(window);
}
);
}
);
}
//----------------PRELOADED PAIRS CODE----------------
function load_character(set_name, char_name, $) {
if (typeof set_name != 'undefined' && typeof char_name != 'undefined') {
var to_append = "<script>$( document ).ready(function() {character_select(";
to_append += "'" + set_name + "/" + char_name + ".xml'";
to_append += ");});</script>";
$('body').append(to_append);
return true;
}
return false;
}
function load_cards(base_name, style_name, $) {
if (typeof base_name != 'undefined') {
var to_append_base = "<script>select_card(";
to_append_base += "'" + base_name + "'";
to_append_base += ");</script>";
$('body').append(to_append_base);
}
if (typeof style_name != 'undefined') {
var to_append_style = "<script>select_card(";
to_append_style += "'" + style_name + "'";
to_append_style += ");</script>";
$('body').append(to_append_style);
}
}