-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.html
134 lines (131 loc) · 3.99 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Card Sorting</title>
<style>
/* Reset */
body, html {
margin: 0;
padding: 0;
font-family: sans-serif;
}
* {
box-sizing: border-box;
}
.main-layout {
display: flex;
flex-direction: column;
align-items: center;
padding-top: 2em;
}
.main-layout > div {
width: 100%;
max-width: 600px;
margin-bottom: 1em;
font-size: 24px;
}
textarea {
padding: 0.5em;
width: 100%;
height: 20vh;
}
label {
cursor: pointer;
}
button {
margin-top: 1em;
margin-bottom: 1em;
padding: 0.3em 0.5em;
font-size: 24px;
cursor: pointer;
}
input[type="checkbox"] {
width: 20px;
height: 20px;
}
.link-container {
word-break: break-all;
padding-bottom: 2em;
}
hr {
opacity: .3;
}
</style>
</head>
<body>
<div class="main-layout">
<h1>
<span>Card Sorting</span>
<span>•</span>
<a href="https://github.com/indigane/cardsort/">Readme</a>
</h1>
<div>Enter card texts one per line or separated by commas</div>
<div>
<textarea class="card-text-input"></textarea>
</div>
<div>
<label>
<input class="is-randomized-checkbox" type="checkbox" />
<span>Randomize card order for each participant</span>
</label>
</div>
<div>
<hr />
</div>
<div>Enter category names one per line or separated by commas (optional)</div>
<div>
<textarea class="category-name-input"></textarea>
</div>
<div>
<label>
<input class="category-editing-checkbox" type="checkbox" checked />
<span>Allow category editing</span>
</label>
</div>
<button class="btn-create-link">Create a link for card sorting</button>
<div class="link-container"></div>
</div>
<script src="pako-2.0.4.min.js"></script>
<script src="common-scripts.js"></script>
<script>
const cardTextInput = document.querySelector('.card-text-input');
const categoryNameInput = document.querySelector('.category-name-input');
const categoryEditingCheckbox = document.querySelector('.category-editing-checkbox');
const isRandomizedCheckbox = document.querySelector('.is-randomized-checkbox');
const linkContainer = document.querySelector('.link-container');
const buttonCreateLink = document.querySelector('.btn-create-link');
buttonCreateLink.addEventListener('click', createLink);
async function createLink() {
const cardTexts = textToArray(cardTextInput.value);
const categoryNames = textToArray(categoryNameInput.value);
const data = {};
for (const categoryName of categoryNames) {
data[categoryName] = [];
}
data[uncategorizedKey] = cardTexts;
const settings = {};
settings.allowCategoryEditing = categoryEditingCheckbox.checked;
settings.isRandomized = isRandomizedCheckbox.checked;
data[settingsFlagsKey] = saveSettings(settings);
const dataString = await saveToString(data);
const baseUrl = window.location.href.replace(regexRemoveBasenameFromUrl, '/');
const url = baseUrl + 'card-sort.html#' + dataString;
linkContainer.innerHTML = `<a href="${url}">${url}</a>`;
}
function textToArray(text) {
let resultArray;
if (text.trim().includes('\n')) {
resultArray = text.split('\n');
}
else {
resultArray = text.split(',');
}
resultArray = resultArray.map(item => item.trim());
resultArray = resultArray.filter(item => !!item);
return resultArray;
}
</script>
</body>
</html>