-
Notifications
You must be signed in to change notification settings - Fork 11
/
builder2.html
791 lines (742 loc) · 23.9 KB
/
builder2.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="utf-8" />
<title>Build a panel show</title>
<link rel="stylesheet" media="all" href="style.css" type="text/css"/>
<style>
input[type=reset] { float: right; }
input#search, .searchresults { width: 100%; }
.searchresults {
position: absolute;
top: 2em;
z-index: 1000;
}
.searchresults ol {
margin: 0px;
padding: 0px;
}
.searchresults li {
border-bottom: 1px solid white;
display: block;
text-align: left;
background-color: #efefef;
color: #404040;
}
.searchresults li .name {
padding: 0 0.5em;
display: inline-block;
line-height: 2em;
}
.searchresults li .handle {
width: 1em;
height: 1em;
margin: 0.5em;
float: right;
}
.searchresults li .wiki {
background: white;
line-height: 1.5em;
padding: 0.25em;
color: black;
font-family: monospace;
}
li.male .handle { background-color: #0DBC37; }
li.female .handle { background-color: #722EA5; }
.searchresults li.selected, .searchresults li:hover {
background-color: black; color: #fefefe;
cursor: pointer;
}
.searchresults li div {
-moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box;
}
.searchresults li .name {
width: auto;
}
#episode {
background: #f9f9f9;
border: 1px solid #999;
border-radius: 4px;
padding: 1em;
margin-top: 0.5em;
}
#episode h2 { font-size: 1em; }
#episode > *:first-child { margin-top : 0; }
#episode .person {
display:inline-block;
margin-right: 0.25em;
margin-bottom: 0.25em;
line-height: 1em;
padding: 2px;
}
#episode .person > * { display: inline-block; padding: 0.5em; line-height: 1em; }
#episode .person .name {
float: left;
cursor: pointer;
}
#episode .person input {
background: transparent;
color: inherit;
min-width: 5em;
width: 5em;
border: 0;
text-align: center;
}
#episode .person .role { margin-right: 0.25em; }
#episode .person .close {
background-color: #cccccc;
color: black;
cursor: pointer;
border: 0px;
font-size: 1em;
}
#episode .person .close:hover {
background-color: #bbbbbb;
}
#notes{
float: right;
line-height: 2em;
}
textarea {
width: 100%;
min-height: 10em;
font-size: 1em;
font-family: monospace;
padding: 1em;
background-color: #efefef;
border: 0;
white-space: pre;
overflow-wrap: normal;
overflow-x: scroll;
}
.episode-output { border: 0px; line-height: 1em; font: inherit; background: transparent; width: 100%; }
.extract { opacity: 0.5; }
.row { display: flex; }
.row + .row { margin-top: 0.5em; }
.row-buttons { display: block; }
.row-top { display: grid; grid-gap: 1em; grid-template-columns: auto auto 1fr; }
.row-top > div { display: grid; grid-template-columns: auto 1fr; align-items: center; }
.row-top > div label { margin-right: 0.25em; }
.row-top > div > span { grid-column: 2; }
.searcher {
display: block;
position: relative;
width: 100%;
}
select, input { font: inherit; font-size: inherit; line-height: 1.5em; height: 2em; }
label { white-space: nowrap; }
label + div { margin-top: 0.5em; }
label + div:empty { margin-top: 0em; }
label:after { content: ":"; position: "relative"; }
fieldset { padding: 1em; border: 1px solid #999; }
fieldset legend { margin-left: 0em; padding: 0 0.5em; color: #999; }
.prev-value { color: #999; font-size: 0.8em; display: block; }
.prev-value:before { content: "Latest: "; position: "relative"; }
.prev-value:empty:before { content: ""; }
#show { margin-top: 0.5em; margin-bottom : 2em; }
#id { width: 6em; }
#url { width: 100%; }
input[type=text] { max-width: 100%; }
button, input[type=submit], input[type=reset] { font-size: 1em; margin-top: 0; cursor: pointer; height: 2em; }
#copy { float: right; margin-top: 0.5em; }
#source { margin-top: 0.5em; display: inline-block; }
</style>
</head>
<body>
<nav id="header">
<div class="padder">
<div class="title"><a href="index.html">Panel Show Db</a></div><ul id="menu"><li><a href="people/index.html">People</a></li><li><a href="https://github.com/slowe/panelshows/tree/master/data">Data</a></li></ul>
</div>
</nav>
<div class="page">
<h1>Build a panel show</h1>
<div>
<label for="shows">Select a panel show</label><select id="shows"></select>
</div>
<form id="episode" onsubmit="false">
<h2>Describe an episode</h2>
<div class="row row-top">
<div><label for="id">ID</label><input id="id" type="text"></input><span id="prev-id" class="prev-value"></span></div>
<div><label for="date">Date</label><input id="date" type="date"></input><span id="prev-date" class="prev-value"></span></div>
<div><label for="url">URL</label><input id="url" type="url"></input><span id="prev-url" class="prev-value"></span></div>
</div>
<div class="row">
<div>
<label for="search">Panellists</label>
<div id="people"></div>
</div>
</div>
<div class="row">
<div class="searcher">
<input type="text" id="search" value="" placeholder="e.g. Sandi Toksvig" autocomplete="off" />
<div class="searchresults"></div>
</div>
</div>
<div class="row row-buttons">
<input type="reset" id="reset" name="reset" value="Clear" />
<input type="submit" id="add" value="Add episode to programme" disabled="true" />
</div>
</form>
<section id="show">
<div id="notes"></div>
<textarea id="show-csv" readonly></textarea>
<button id="copy">Copy to clipboard</button>
</section>
<script>
// Create a database for people
function PeopleDB(){
this.data = {};
this.init = function(){
// Get main database of people
fetch("people/people.tsv",{})
.then(response => { return response.text(); })
.then(text => {
var i,c,cols,lines,head,id;
lines = text.split(/[\n\r]/);
// The header line contains the names for columns
for(i = 0; i < lines.length; i++){
cols = lines[i].split(/\t/);
if(i == 0){
cols[0] = cols[0].substr(2,);
head = cols;
}else{
id = cols[0];
if(id){
if(!this.data[id]) this.data[id] = {};
for(c = 1; c < cols.length; c++){
if(cols[c] != "") this.data[id][head[c]] = cols[c];
}
}
}
}
}).catch(error => {
console.error('Unable to load people');
});
// Get databse of rankings
fetch("people/ranked.csv",{})
.then(response => { return response.text(); })
.then(text => {
var i,c,cols,lines,head,id,showbits,bits,s,key;
lines = text.split(/[\n\r]/);
for(i = 0; i < lines.length; i++){
if(lines[i] != ""){
cols = lines[i].split(/,(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))/);
id = cols[0];
if(id){
if(!this.data[id]) this.data[id] = {};
if(!this.data[id].pronoun && cols[2]) this.data[id].pronoun = cols[2];
if(!this.data[id].gender && cols[3]) this.data[id].gender = cols[3];
if(!this.data[id].dob && cols[4]) this.data[id].dob = cols[4];
if(!this.data[id].n && cols[5]) this.data[id].n = parseInt(cols[5]);
if(!this.data[id].shows && cols[6]) this.data[id].shows = cols[6];
if(!this.data[id].wikipedia) this.data[id].wikipedia = cols[7]||"";
if(this.data[id].shows){
showbits = (this.data[id].shows) ? this.data[id].shows.replace(/;$/,"").split(";") : new Array();
this.data[id].shows = {};
for(s = 0 ; s < showbits.length; s++){
bits = showbits[s].split(/:/);
this.data[id].shows[bits[0]] = parseInt(bits[1]);
}
}
}
}
}
}).catch(error => {
console.error('Unable to load people rankings');
});
return this;
}
this.init();
return this;
}
// Create a database for shows
function ShowDB(el){
this.data = {};
this.lookup = {};
this.show = "";
var _obj = this;
this.init = function(){
// Get databse of shows
fetch("people/shows.json",{})
.then(response => { return response.json(); })
.then(json => {
this.data = json;
this.lookup = {};
var showkeys = new Array();
for(id in json){
this.lookup[json[id].i] = id;
showkeys.push(id);
}
showkeys.sort();
// Build the dropdown list
var html = '<option value="">Select show</option>';
for(var i = 0; i < showkeys.length; i++){
html += '<option value="'+showkeys[i]+'">'+this.data[showkeys[i]].title+'</option>';
}
el.innerHTML = html;
// Set the selected show
el.addEventListener('change',function(e){ _obj.set(e.target.value); });
}).catch(error => {
console.error('Unable to load shows');
});
return this;
};
// Set a particular show
// This will load the data and build the result
this.set = function(show){
if(!show || !show in this.data){
console.error('No show data for '+show);
document.getElementById('add').disabled = true;
this.setShow();
}else{
if(this.data[show].loaded){
this.setShow(show);
}else{
// Get databse of rankings
fetch("shows/data/"+show+".csv",{})
.then(response => { return response.text(); })
.then(text => {
var lines,l;
this.data[show].text = text;
this.data[show].episodes = new Array;
lines = text.split(/[\n\r]/);
for(l = 1; l < lines.length; l++){
if(lines[l]){
bits = lines[l].split(/,(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))/);
ep = {};
ep.id = bits[0];
ep.date = bits[1];
ep.people = (bits[2] ? bits[2].replace(/;$/,"").split(/;/) : "");
ep.ref = bits[3];
if(bits.length == 5) ep.more = bits[4];
for(g = 0; g < ep.people.length; g++){
guest = ep.people[g].split(/:/);
ep.people[g] = {}
ep.people[g].id = guest[0];
ep.people[g].string = guest[1]||"";
ep.people[g].string.replace(/^(.*?) \((.*)\)$/,function(m,p1,p2){
ep.people[g].name = p1;
if(p2){
attr = p2.split(/ - /);
if(attr.length >= 1) ep.people[g].gender = attr[0];
if(attr.length >= 2) ep.people[g].role = attr[1];
}
});
}
this.data[show].episodes.push(ep);
}
}
this.data[show].loaded = true;
this.setShow(show);
}).catch(error => {
console.error('Unable to load show data for '+show);
});
}
document.getElementById('add').disabled = false;
this.show = show;
}
return this;
};
this.setShow = function(show){
var lnk = document.getElementById('source');
var lnktxt = "";
if(!lnk){
lnk = document.createElement('span');
lnk.setAttribute('id','source');
lnk.classList.add('link');
lnk.innerHTML = "Link goes here";
document.getElementById('show-csv').after(lnk);
}
if(show){
document.getElementById('show-csv').value = _obj.buildCSV(show);
document.getElementById('show-csv').scrollTop = document.getElementById('show-csv').scrollTopMax;
if(_obj.data[show].episodes.length > 0){
var ep = _obj.data[show].episodes[_obj.data[show].episodes.length-1];
document.getElementById('prev-id').innerHTML = ep.id;
document.getElementById('prev-date').innerHTML = ep.date;
document.getElementById('prev-url').innerHTML = linkify(ep.ref);
// If no value is set we enter a guess
//if(document.getElementById('id').value==""){
bits = ep.id.split('x');
if(bits.length == 2){
n = parseInt(bits[1])+1;
n = ('00'+n).slice(-2);
document.getElementById('id').setAttribute('placeholder','e.g. '+ep.id);
document.getElementById('id').value = bits[0]+'x'+n;
}
//}
// If no value is set we enter a guess
//if(document.getElementById('date').value==""){
var d = new Date(ep.date);
d.setDate(d.getDate() + 7)
document.getElementById('date').value = d.toISOString().substr(0,10);
//}
lnktxt = '<a href="https://github.com/slowe/panelshows/edit/master/shows/data/'+show+'.csv" target="_github">Edit the file for '+shows.data[show].title+' on Github</a>';
}
}else{
document.getElementById('show-csv').value = "";
}
lnk.innerHTML = lnktxt;
return;
};
this.buildCSV = function(show){
var s,csv;
if(!show) show = this.show;
csv = '';
if(!show in this.data){
console.error('Show '+show+' does not exist in database');
}else{
s = this.data[show];
csv = 'Episode,Date,Guests (Himself/Herself - Role),References\n';
for(e = 0; e < s.episodes.length; e++){
csv += s.episodes[e].id;
csv += ','+s.episodes[e].date;
csv += ',';
if(s.episodes[e].people){
for(p = 0; p < s.episodes[e].people.length; p++){
csv += (p > 0 ? ';':'');
csv += s.episodes[e].people[p].id+':'+s.episodes[e].people[p].name;
csv += ' (';
csv += s.episodes[e].people[p].gender;
if(s.episodes[e].people[p].role){
csv += ' - '+s.episodes[e].people[p].role;
}
csv += ')';
}
}
csv += ','+s.episodes[e].ref;
csv += '\n';
}
}
csv = csv.replace(/\n$/,"");
return csv;
}
this.init();
return this;
}
var people = new PeopleDB();
var shows = new ShowDB(document.getElementById('shows'));
document.getElementById('episode').addEventListener('submit',function(e){
if (e.preventDefault) e.preventDefault();
e.stopPropagation();
updateList();
});
// Make the "copy to clipboard" button function
function CopyToClipboard(){
var copyText = document.getElementById("show-csv");
copyText.select();
copyText.setSelectionRange(0, 999999); // For mobile devices
// Copy the text inside the text field
navigator.clipboard.writeText(copyText.value);
copyText.setSelectionRange(999999,999999);
}
document.getElementById('copy').addEventListener('click',CopyToClipboard);
document.getElementById('search').addEventListener('keydown',function(e){
if(e.keyCode==13){
e.preventDefault();
e.stopPropagation();
return false;
}
});
document.getElementById('search').addEventListener('keyup',function(e){
e.preventDefault();
e.stopPropagation();
if(e.keyCode==40 || e.keyCode==38){
// Down=40
// Up=38
var li = document.querySelectorAll('.searchresults li');
var s = -1;
for(var i = 0; i < li.length; i++){
if(li[i].classList.contains('selected')) s = i;
}
if(e.keyCode==40) s++;
else s--;
if(s < 0) s = li.length-1;
if(s >= li.length) s = 0;
document.querySelector('.searchresults .selected').classList.remove('selected');
li[s].classList.add('selected');
}else if(e.keyCode==13){
selectName(document.querySelector('.searchresults .selected'));
}else{
var tmp = new Array();
var name = e.target.value;
var found = 0;
var html = "";
if(name.length < 1){
html = "";
}else{
var names = name.split(/ /);
var n = names.length;
var mx = 0;
for(var id in people.data){
if(people.data[id].n > mx) mx = people.data[id].n;
people.data[id].rank = 0;
}
for(var id in people.data){
rank = 0;
if(typeof people.data[id].wikipedia!=="string") people.data[id].wikipedia = "";
for(m = 0; m < n ; m++){
if(!people.data[id].Name) console.warn('Person with id '+id+' has no name');
else{
if(people.data[id].Name.indexOf(names[m]) >= 0) rank++;
else if(people.data[id].wikipedia.indexOf(names[m]) >= 0) rank++;
else rank--;
}
}
if(rank > 0){
datum = people.data[id];
datum.id = id;
datum.rank = rank*datum.n/mx;
if(show){
scalefactor = 0.0001;
if(datum.shows && shows.show && shows.show in shows.data){
i = shows.data[shows.show].i;
if(datum.shows[i]){
scalefactor = datum.shows[i]/shows.data[shows.show].episodes.length;
}
}
datum.rank *= scalefactor;
}
tmp.push(datum);
}
}
if(tmp.length > 0){
tmp = sortBy(tmp,'rank');
var n = Math.min(tmp.length,8);
var i,sid,sids,wiki,mtch;
for(i = 0; i < n; i++){
found++;
// Tidy wikipedia links
wiki = (tmp[i].wikipedia||"").replace(/\_/g," ").replace(tmp[i].Name,"").replace(/^\s*\((.*)\)\s*$/,function(m,p1){ return p1; });
html += '<li data-id="'+tmp[i].id+'" class="'+tmp[i].gender+''+(i==0 ? ' selected':'')+'"><div class="handle"></div><div class="name">'+tmp[i].Name+(tmp[i].dob ? ' ('+tmp[i].dob.substr(0,4)+')' : "")+""+(wiki ? " / <span class=\"wiki\">"+wiki+"</span>":"");
sids = new Array();
if(tmp[i].shows){
for(sid in tmp[i].shows){
sids.push({'id':sid,'n':tmp[i].shows[sid]});
}
sids = sortBy(sids,'n');
if(sids.length > 0){
html += ' [<em>';
html += trimTo(shows.data[shows.lookup[sids[0].id]].title,(sids.length > 1 ? 20 : 40));
html += '</em> × '+sids[0].n;
html += (sids.length > 1 ? ', <em>'+trimTo(shows.data[shows.lookup[sids[1].id]].title,20)+'</em> × '+sids[1].n : '');
html += ']';
}
}
html += "</div></li>";
}
}
}
if(found < 4 && name.length > 0){
html += '<li data-id="?" class=""><div class="handle"></div><div class="name">+ Add unknown person</div></li>';
}
if(html){
document.querySelector('.searchresults').innerHTML = "<ol>"+html+"</ol>";
var li = document.querySelectorAll('.searchresults li');
for(var i = 0 ; i < li.length ; i++) selectablePerson(li[i]);
}else{
document.querySelector('.searchresults').innerHTML = "";
}
}
// Sort the data
function sortBy(arr,i){
yaxis = i;
return arr.sort(function (a, b) {
return a[i] < b[i] ? 1 : -1;
});
}
return false;
});
function selectName(el){
// Get the ID from the DOM element's data-id attribute
// Use that to find the index that corresponds to in the "db" hash
var data = el.getAttribute('data-id');
var id,n;
if(data.length==0) return;
if(data=="?"){
// First create them an ID
newid = newID(document.getElementById('search').value);
id = newid.id;
// Check if this ID has been created
if(!people.data[id]){
people.data[id] = {};
people.data[id].Name = newid.name;
people.data[id].gender = "other";
people.data[id].pronoun = "";
people.data[id].rank = 0;
people.data[id].n = 1;
people.data[id].shows = new Array();
if(show in shows.data){
people.data[id].shows.push({'key':show,'n':1});
}
}
}else{
id = el.getAttribute('data-id');
// Update show counter
if(shows.show){
var i = shows.data[shows.show].i;
if(typeof people.data[id].shows[i]!=="number" || people.data[id].shows[i]==0) people.data[id].shows[i] = 0;
people.data[id].shows[i]++;
}
}
html = "";
person = document.createElement('span');
person.setAttribute('data-id',id);
person.classList.add('person');
if(people.data[id].gender) person.classList.add(people.data[id].gender);
html = '<span class="name">'+people.data[id].Name+'</span>';
html += '<input class="pronoun" type="text" value="'+people.data[id].pronoun+'" placeholder="Pronoun" />';
html += '<input class="role" type="text" placeholder="Role?" />';
html += '<button class="close" aria-label="Close">×</button>';
person.innerHTML = html;
document.getElementById('people').appendChild(person);
document.querySelector('.searchresults').innerHTML = '';
document.getElementById('search').value = '';
var p = document.querySelectorAll('.person');
for(var i = 0; i < p.length; i++){
el = p[i];
el.querySelector('.close').addEventListener('click',function(e){
e.target.parentNode.remove();
});
el.querySelector('.pronoun').addEventListener('change',function(e){
var parent = e.target.parentNode;
var id = parent.getAttribute('data-id');
var p = e.target.value;
var g = people.data[id].gender;
// Remove the existing gender
parent.classList.remove(people.data[id].gender);
// Use the user provided reflexive pronoun to get a new gender class name
if(p == "Himself") g = "male";
else if(p == "Herself") g = "female";
else g = "other";
if(g) parent.classList.add(g);
people.data[id].gender = g;
people.data[id].pronoun = p;
});
el.querySelector('.role').addEventListener('keyup',function(e){ adjustWidthOfInput(e.target); });
el.querySelector('.pronoun').addEventListener('keyup',function(e){ adjustWidthOfInput(e.target); });
}
}
// Select one of the people in the drop down list
function selectablePerson(el){
el.addEventListener('click',function(e){
selectName(el);
});
}
function trimTo(str,len){
if(str) return (str.length > len ? str.substr(0,len)+'…':str);
else return "";
}
// Function to update the textarea based on the people added to the DOM
function updateList(reset){
// Find all the "person" DOM elements
var p = document.querySelectorAll('.person');
var str = "";
if(shows.show){
if(!shows.data[shows.show].episodes) shows.data[shows.show].episodes = [];
// Build a new episode
var episode = {'people':[]};
var person;
episode.id = document.getElementById('id').value;
episode.date = document.getElementById('date').value;
episode.ref = document.getElementById('url').value;
// Loop over the DOM elements
for(var i = 0; i < p.length; i++){
// Get a stuQuery object for the current element
el = p[i];
// Find the ID stored in the "data-id" attribute
id = el.getAttribute('data-id');
person = { 'id':id };
person.name = people.data[id].Name;
person.gender = (people.data[id].gender == "male" ? "Himself" : (people.data[id].gender == "female" ? "Herself" : people.data[id].pronoun))
person.role = el.querySelector('.role').value;
episode.people.push(person);
}
shows.data[shows.show].episodes.push(episode);
//document.getElementById('show-csv').value = shows.buildCSV(shows.show);
shows.setShow(shows.show)
}
}
function linkify(txt){
return txt.replace(/(^|\,|\;|\s)(http[^\s]*)/g,function(m,p1,p2,p3){ return p1+'<a href="'+p2+'" target="source">'+p2+'</a>'; });
}
function getWidthOfInput(el) {
var w = 0;
if(el){
var tmp = document.createElement("span");
tmp.className = "episode-output";
tmp.innerHTML = el.value.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>');
tmp.style.padding = window.getComputedStyle(el)['padding'];
document.body.append(tmp);
w = tmp.getBoundingClientRect().width;
tmp.remove();
}
return w;
}
function adjustWidthOfInput(el){ el.style.width = (getWidthOfInput(el)+8) + "px"; }
// Code for creating a new ID
function newID(name){
var rtn = {'name':name};
if(!name){
console.error('No name given');
return rtn;
}
var key = generate_random_string(name);
var str = name;
var tries = 0;
while(key in people.data){
//str += 'a';
key = generate_random_string();
if(tries > 20){
console.error('Too many attempts');
return rtn;
}
tries++;
}
rtn.id = key;
return rtn;
}
// Create a seed for the random number generator based on the numbers in the input
function generate_random_string(seed,len){
length_of_randomstring = (len||8);
var n = 0;
var i,a2n,string;
rand = function(v){ return Math.floor(Math.random()*v); };
if(seed){
a2n = {};
string = seed.split("");
seed = 0;
n = string.length;
for(i = 0; i < string.length ; i++) seed += (string[i].charCodeAt()/256)**(n-i);
seed = (seed+"").replace(/[^0-9]/g,"").replace(/^0/g,"");
rand = srand(seed);
}
var chars = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','0','1','2','3','4','5','6','7','8','9'];
var random_string = "";
for(i = 1; i <= length_of_randomstring; i++) random_string += chars[Math.floor(rand.call(this,chars.length))];
return random_string;
}
/**
* srand from https://github.com/micro-js/srand MIT licence
*/
function srand(seed){
// If we're passed a string, condense it down into a number
if(typeof seed==='string'){
str = seed;
seed = 0xFF;
for(var i = 0; i < str.length; i++){
seed ^= str.charCodeAt(i);
}
}
return function (max, min){
max = max || 1;
min = min || 0;
seed = (seed * 9301 + 49297) % 233280;
return min + (seed / 233280) * (max - min);
}
}
</script>
</div>
</body>
</html>