-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
149 lines (124 loc) · 4.6 KB
/
index.html
File metadata and controls
149 lines (124 loc) · 4.6 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
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
<!DOCTYPE html>
<html lang="en">
<meta charset="utf8">
<title>Preferences</title>
<meta name="viewport" content="width=device-width, user-scalable=no, maximum-scale=1.0">
<link href="index.css" rel="stylesheet" />
<style>
body, input {
// background: #eee;
font-family: Helvetica, Arial, sans-serif;
font-size: 16px;
font-weight: 200;
max-width: 40em;
margin: 0 auto;
padding: 0px;
color: #777;
}
input {
-webkit-appearance: none;
overflow: visible;
border: 0px;
}
</style>
<body>
<ol id="slippylist">
<li>alpha<span class="instant"> </span></li>
<li>bravo<span class="instant"> </span></li>
<li>charlie<span class="instant"> </span></li>
<li>delta<span class="instant"> </span></li>
<li>echo<span class="instant"> </span></li>
<li>foxtrot<span class="instant"> </span></li>
<li>golf<span class="instant"> </span></li>
<!--
"Ooh la-la"s, "Oh, hell yes"es, "I can't wait"s, "I gotta see you again"ses.
<li class="demo-no-reorder">Swipe,</li>
<li class="demo-no-swipe">hold & reorder <span class="instant">or instantly</span></li>
<li>or either</li>
<li class="demo-no-swipe demo-no-reorder">or none of them.</li>
<li>interaction <input type="range"></li>
<li class="demo-allow-select"><span class="demo-no-reorder">and selectable text, even though animating elements with selected text is a bit weird.</span></li>
-->
</ol>
<a href="#" id="reload">
<svg viewBox="0 0 32 32" style="width: 56px; height: 56px;"><circle cx="16" cy="16" r="11" style="stroke-dasharray: 55.676, 13.439; stroke-dashoffset: -23.0383; stroke: rgb(200, 200, 200); stroke-linecap: round; opacity: 1; stroke-width: 3; fill: none;"></circle><polygon points="21.75,16 32.25,16 27,21.25" style="fill: rgb(200, 200, 200); transform: rotate(410deg); transform-origin: 16px 16px 0px; opacity: 1;"></polygon></svg>
</a>
<script src="d3.v4.min.js"></script>
<script src="preferences.js?17091917"></script>
<script src="slip.js"></script>
<script>
A.usedUp = []; // indexes we've seen
A.N = 7;
// A.leaves
var ol = document.getElementById('slippylist');
ol.addEventListener('slip:beforereorder', function(e){
if (/demo-no-reorder/.test(e.target.className)) {
e.preventDefault();
}
}, false);
ol.addEventListener('slip:beforeswipe', function(e){
if (e.target.nodeName == 'INPUT' || /demo-no-swipe/.test(e.target.className)) {
e.preventDefault();
}
}, false);
ol.addEventListener('slip:beforewait', function(e){
if (e.target.className.indexOf('instant') > -1) e.preventDefault();
}, false);
ol.addEventListener('slip:afterswipe', function(e){
console.log(e);
var idx = getUnusedIdx(A.usedUp);
//e.target = document.createElement("li");
e.target.innerHTML = `${A.leaves[idx]}<span class="instant"> </span>`;
// e.target.contenteditable = "true";
// e.target.parentNode.appendChild(e.target);
// e.target.parentNode.appendChild(e.target);
}, false);
ol.addEventListener('slip:reorder', function(e){
e.target.parentNode.insertBefore(e.target, e.detail.insertBefore);
return false;
}, false);
new Slip(ol);
reload();
d3.select("#reload").on('click', function(){
reload();
});
function reload() {
document.querySelector("#slippylist").innerHTML = "";
// Get a random list of N items
var idx;
for (var i = 0; i < A.N; i++) {
idx = getUnusedIdx(A.usedUp);
console.log(idx);
document.querySelector("#slippylist").innerHTML += `<li contenteditable="true">${A.leaves[idx]}<span class="instant"> </span></li>`;
}
}
// getUnusedIdx(A.usedUp, getRandomInt(0, A.leaves.length - 1));
// getUnusedIdx(A.usedUp);
function getUnusedIdx(idxArray) {
function getIt(idxArray) {
var idx = getRandomInt(0, A.leaves.length - 1);
// If it's fresh, mark it and return it
console.log(idx);
if (idxArray.indexOf(idx) === -1) {
idxArray.push(idx);
return idx;
} else { // try again
return getIt(idxArray);
}
}
return getIt(idxArray);
}
/*function factorial (n) {
function fact(n, acc) {
if (n < 2) {
return acc;
} else {
return fact(n-1, n * acc);
}
}
return fact(n, 1)
}*/
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
</script>