-
-
Notifications
You must be signed in to change notification settings - Fork 35
/
settings.html
166 lines (130 loc) · 4.24 KB
/
settings.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="../css/base.css?bust=$GIT_COMMIT" />
<style>
td {
background-color: #eeeeee;
}
</style>
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script type="text/javascript">
"use strict";
var mainSchema = "CSLEDIT.mainSchema",
subSchemas = "CSLEDIT.subSchemas";
var updateView = function () {
var mainList = $('#mainSchemaList'),
subList = $('#subSchemasList'),
mainSchemaData = JSON.parse(localStorage.getItem(mainSchema)),
subSchemasData = JSON.parse(localStorage.getItem(subSchemas));
mainList.children().remove();
subList.children().remove();
if (mainSchemaData === null) {
mainList.append("<li>Main schema file not specified</li>");
} else {
$.each(mainSchemaData, function (name, data) {
mainList.append("<li>" + name + "</li>");
});
}
if (subSchemasData === null) {
subList.append("<li>No sub schemas specified</li>");
} else {
$.each(subSchemasData, function (name, data) {
subList.append("<li>" + name + "</li>");
});
}
displayLocalStorage();
}
var displayLocalStorage = function () {
var table = $('<table>'),
key,
value,
totalCharacters = 0;
if (localStorage.length > 0) {
table.append(
$('<tr>')
.append($('<td>').append("<strong>key</strong>"))
.append($('<td>').append("<strong>value</strong>"))
);
}
// list local storage contents
for (var i = 0; i < localStorage.length; i++) {
key = localStorage.key(i);
value = localStorage.getItem(key);
totalCharacters += value.length + key.length;
// elide value
if (value.length > 400) {
value = value.substring(0, 400) + "...";
}
console.log(sanitize(value));
table.append(
$('<tr>')
.append($('<td>').append(key))
.append($('<td>').append(sanitize(value)))
);
}
console.log("total = " + totalCharacters);
var thousandsOfCharacters = Math.round(totalCharacters / 1000);
$('#localStorage')
.html("")
.append("<p>Using " + thousandsOfCharacters + "k characters out of a possible 2500k (see " +
"<a href=http://dev-test.nemikor.com/web-storage/support-test>reference</a>)</p>")
.append(table);
};
var sanitize = function (input) {
return input
.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/"/g, """);
};
var readSchemaFiles = function (schemaKey, files) {
var schemaData = {};
$.each(files, function (i, file) {
var reader = new FileReader();
reader.onload = function (event) {
schemaData[file.name] = event.target.result;
localStorage.setItem(schemaKey, JSON.stringify(schemaData));
updateView();
};
reader.readAsText(file);
});
return schemaData;
};
$(document).ready(function () {
if (typeof(localStorage) === "undefined" || localStorage === null) {
$('body').html("localStorage not available in this environment");
}
$("#mainSchemaFile").change(function (event) {
readSchemaFiles(mainSchema, event.target.files);
});
$("#subSchemasFiles").change(function (event) {
readSchemaFiles(subSchemas, event.target.files);
});
$("#deleteSchema").click(function () {
localStorage.removeItem(mainSchema);
localStorage.removeItem(subSchemas);
updateView();
});
$("#resetEverything").click(function () {
localStorage.clear();
updateView();
});
updateView();
});
</script>
</head>
<body>
<h3>Current CSL schema files</h3>
<label for="mainSchemaFile">Main CSL Schema RNG File:</label><input id="mainSchemaFile" type="file"></input><br />
<ul id="mainSchemaList"></ul>
<label for="subSchemasFiles">Other CSL Schema RNG Files:</label><input id="subSchemasFiles" type="file" multiple="multiple"></input><br />
<ul id="subSchemasList"></ul>
<button id="deleteSchema">Delete All Files (reset schema to default)</button>
<h3>Current local storage</h3>
<div id=localStorage>
</div>
<button id="resetEverything">Delete all local settings (your style will be lost)</button>
<p>
</body>
</html>