-
Notifications
You must be signed in to change notification settings - Fork 0
/
codex_enter.html
521 lines (460 loc) · 13.6 KB
/
codex_enter.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
<html>
<head lang="it">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<script type="text/javascript" src="https://www.google.com/jsapi?key=ABQIAAAAUzJ_6UqPfuuygp9Xo0AGoxRYjYHH-N6Ytftz1YKT8IaSgMm3fBSIC090wMAgB4Mcecyj6FsiJdo98g"></script>
<script type="text/javascript">
google.load("jquery", "1.4.3");
</script>
<script type="text/javascript">
function dimmi_poem()
{
return "\
\
Dimmi: /com’era con l’altra, /più /semplice? \n\
Dimmi: /com’era con l’altra, /meno /fragile? \n\
Sembra /un vano … /tentativo /di gelosia \n\
Sembra /un vano … /frugare /in /memorie \n\
false, /fragili, /sporche. \n\
Parole /precise /attraversano \n\
fogli /bianchi /fermi /e /inutili. \n\
Taccio /solo /odio /fino al collo \n\
fino a qui, /fino a /rompere \n\
lo spessore /che /adesso /ci /divide.";
}
function taci_poem()
{
return "\
\
Taci: /non so se era, /più /seducente! \n\
Taci: /non so se era, /meno /formale! \n\
È /un ridicolo … /esempio /di tormento \n\
È /un ridicolo … /piegarsi /in /paure \n\
soffici, /lussuriose, /lente \n\
Frasi /fraintese /lacerano \n\
spazi /densi /rigidi /e /falsi \n\
Dimmi: /ancora /amore /fino al collo \n\
fino a qui, /fino a /cancellare \n\
la fluidità /che /ancora /ci /ferma";
}
/*jslint bitwise: true, browser: true, eqeqeq: true, immed: true, newcap: true, nomen: true, plusplus: true, regexp: true, undef: true, maxerr: 50, indent: 2, onevar: false */
// clicking (flips or locks the text? (switch?))
// master lock
var JOLLY = {}; // my namespace
var this_figure = {};
var that_figure = {};
// title
this_figure.title = "senza titolo";
// poem
this_figure.poem = dimmi_poem();
that_figure.title = '';
that_figure.poem = taci_poem();
function reverse(in_str)
{
var out_str = '',
i;
for (i = in_str.length - 1; i >= 0; i -= 1) {
out_str += in_str[i];
}
return out_str;
}
function initialize()
{
that_figure.title = this_figure.title;
this_figure.poem_array = this_figure.poem.split('\n');
/*
for (var j = 0; j < this_figure.poem_array.length; j += 1) {
var s = this_figure.poem_array[j];
that_figure.poem += (s + '\n');
}
*/
that_figure.poem_array = that_figure.poem.split('\n');
}
initialize();
function get_bounding(str)
{
hidden_span = document.createElement('span');
hidden_span.style.visibility="hidden";
// add an invisible div just before the last element of the document
var my_page = document.getElementById("page");
my_page.appendChild(hidden_span);
// place the text in it
hidden_span.innerHTML = str;
hidden_span.setAttribute('id',"nuke_me");
// now read the elements width and height
var w = hidden_span.offsetWidth;
var h = hidden_span.offsetTop; // ?? this is not the height
var nuke_me = document.getElementById("nuke_me");
my_page.removeChild(nuke_me);
// return it
return {
width: w,
height: h
};
}
// should be sent in larger, smaller
function pad_and_position(str, larger_width, smaller_width)
{
left_pad = right_pad = (larger_width-smaller_width)/2;
if ((larger_width-smaller_width)%2 == 1) right_pad += 1;
return '<span style=" padding-right:'+right_pad+'px; \
padding-left:'+left_pad+'px; \
width:'+larger_width+'px; \
">'+str+'</span>';
// text-align:center;
}
// element
// escaped segment (to prevent poetic literals messing up javascript)
function effectify(el, segment)
{
$(el).fadeOut('slow', function () {
var newHTML = unescape(segment);
el.innerHTML = newHTML;
$(el).fadeIn('slow');
});
}
entered = 0;
journey = null;
bad_trigger = null;
// jQuery this !! use binding and all that goodness
function textual_up_identical(unique, k, one)
{
s = ' \
<span id="divil_outer" \
> \
<!-- identical --><span style="cursor:default" id="divil_inner'+unique+':'+k+'" \
>'
+ one
+ '</span></span>';
return s;
}
function textual_up_same_length(unique, k, one, two)
{
s = ' \
<span id="divil_outer" \
> \
<!-- same length --><span style="cursor:default" id="divil_inner'+unique+':'+k+'" \
onmouseover=" \
if (journey[ '+unique+' ][ '+k+' ].evented == 0) { \
if (journey['+unique+']['+k+'].flip == false) { \
effectify(this,\''+escape(two)+'\'); \
journey['+unique+']['+k+'].flip = true; \
} else { \
effectify(this,\''+escape(one)+'\'); \
journey['+unique+']['+k+'].flip = false; \
} \
e = window.event; \
/* console.log(e); */ \
/* console.log(\'over: unique: \'+ '+unique+' +\' k: \'+ '+k+' ); */ \
journey['+unique+']['+k+'].evented += 1; \
e.cancelBubble = true; \
if (e.stopPropagation) e.stopPropagation(); \
return false; \
} \
" \
onmouseout=" \
journey['+unique+']['+k+'].evented -= 1; \
e = window.event; \
/* console.log(e.target.id); */ \
/* console.log(\'out: unique: \'+ '+unique+' +\' k: \'+ '+k+' ); */ \
e.cancelBubble = true; \
if (e.stopPropagation) e.stopPropagation(); \
return false; \
" \
>'
+ one
+ '</span></span>';
return s;
}
// if trans is set to true then the transition from two to one messes up,
// else if trans is set to false then the transition from one to two messes up
function textual_up_diff(unique, k, one, two, trans)
{
s = ' \
<span id="divil_outer" \
> \
<!-- diff --><span style="cursor:default" id="divil_inner'+unique+':'+k+'" \
onmouseover=" \
if (journey[ '+unique+' ][ '+k+' ].evented == 0) { \
if (journey['+unique+']['+k+'].flip == false) { \
/* one to two */ if ('+trans+' == false) bad_trigger=true; else bad_trigger=false; \
effectify(this,\''+escape(two)+'\'); \
journey['+unique+']['+k+'].flip = true; \
} else { \
/* two to one */ if ('+trans+' == true) bad_trigger=true; else bad_trigger=false; \
effectify(this,\''+escape(one)+'\'); \
journey['+unique+']['+k+'].flip = false; \
} \
e = window.event; \
/* console.log(e); */ \
/* console.log(\'over: unique: \'+ '+unique+' +\' k: \'+ '+k+' ); */ \
journey['+unique+']['+k+'].evented += 1; \
e.cancelBubble = true; \
if (e.stopPropagation) e.stopPropagation(); \
return false; \
} \
" \
onmouseout=" \
if (bad_trigger == false) { \
/* do nothing once */ \
bad_trigger = true; \
} else { \
journey['+unique+']['+k+'].evented -= 1; \
} \
e = window.event; \
/* console.log(e.target.id); */ \
/* console.log(\'out: unique: \'+ '+unique+' +\' k: \'+ '+k+' ); */ \
e.cancelBubble = true; \
if (e.stopPropagation) e.stopPropagation(); \
return false; \
" \
>'
+ one
+ '</span></span>';
return s;
}
// each line has a unique number
function double_up(unique, line_one, line_two)
{
// they all have the same id, prolly not what you want
var sequence_one = line_one.split('/');
// console.log(sequence_one);
var sequence_two = line_two.split('/');
// console.log(sequence_two);
var s = '';
journey[unique] = new Array(sequence_one.length);
for (var k = 0; k < sequence_one.length; k += 1) {
journey[unique][k] = {};
journey[unique][k].evented = 0;
journey[unique][k].flip = false;
var one = sequence_one[k];
var two = sequence_two[k];
if (one == two) {
s += textual_up_identical(unique, k, one);
} else {
var bounds_one = get_bounding(one);
console.log(one);
console.log(bounds_one);
var bounds_two = get_bounding(two);
console.log(two);
console.log(bounds_two);
if (bounds_one.width > bounds_two.width) {
two = pad_and_position(two, bounds_one.width, bounds_two.width);
s += textual_up_diff(unique, k, one, two, true);
} else if (bounds_two.width > bounds_one.width) {
one = pad_and_position(one, bounds_two.width, bounds_one.width);
s += textual_up_diff(unique, k, one, two, false);
} else {
one = pad_and_position(one, bounds_two.width, bounds_one.width);
s += textual_up_same_length(unique, k, one, two);
}
}
}
s += '<br>\n';
return s;
}
/*
// each line has a unique number
function save_double_up(unique, line_one, line_two)
{
// they all have the same id, prolly not what you want
var sequence_one = line_one.split('/');
var sequence_two = line_two.split('/');
var s = '';
journey[unique] = new Array(sequence_one.length);
for (var k = 0; k < sequence_one.length; k += 1) {
journey[unique][k] = 0;
var one = sequence_one[k];
var two = sequence_two[k];
var bounds_one = get_bounding(one);
var bounds_two = get_bounding(two);
if (bounds_one.width > bounds_two.width)
two = pad_and_position(two, bounds_one.width, bounds_two.width);
else if (bounds_two.width > bounds_one.width)
one = pad_and_position(one, bounds_two.width, bounds_one.width);
// else do nothing
s += ' \
<span id="divil_outer" \
> \
<span id="divil_inner" \
onmouseover=" \
if (journey[unique][k] == 0) { \
this.innerHTML=unique(\'' + escape(two) + '\'); \
journey[unique][k] = 1; \
return false; \
} \
" \
onmouseout=" \
this.innerHTML=unescape(\'' +escape(one)+ '\'); \
journey[ '+unique+' ][ '+k+' ] = 0; \
return false; \
" \
>'
+ one
+ '</span></span>';
}
s += '<br><br><br>\n';
return s;
}
*/
function toss()
{
return !! Math.floor(Math.random() * 2);
}
function poemify(title, poem, the_el)
{
var elem = document.getElementById(the_el);
//elem.innerHTML += '<u>'+double_up(one, two)+'</u>';
journey = new Array(poem.one.length + 1);
elem.innerHTML = double_up(0, title.one, title.two);
elem.innerHTML += '<br>\n';
for (var k = 0; k < poem.one.length; k += 1) {
var one = poem.one[k];
var two = poem.two[k];
//console.log(one);
//console.log(two);
elem.innerHTML += double_up(k+1, one, two); // line by line
}
}
function this_title()
{
return {
one: this_figure.title,
two: that_figure.title
};
}
function this_poem()
{
return {
one: this_figure.poem_array,
two: that_figure.poem_array
};
}
function click_this()
{
/*b = get_bounding('Does this really work?');
alert('width is '+b.width+' and height is '+b.height);
return;*/
var title = this_title();
var poem = this_poem();
var the_el = "dynamic_element";
poemify(title, poem, the_el);
}
function that_title()
{
return {
two: this_figure.title,
one: that_figure.title
};
}
function that_poem()
{
return {
two: this_figure.poem_array,
one: that_figure.poem_array
};
}
function click_that()
{
var title = that_title();
var poem = that_poem();
var the_el = "dynamic_element";
poemify(title, poem, the_el);
}
/*
function the_other_poem()
{
var len = this_figure.poem_array.length;
var alpha_poem = [];
var omega_poem = [];
var done_array = [];
for (var i = 0; i < len; i += 1) {
done_array[i] = false;
}
var done = 0;
while (done < len) {
var pos = Math.floor(Math.random() * len);
if (!done_array[pos]) {
if (toss()) {
alpha_poem[done] = this_figure.poem_array[pos];
omega_poem[done] = that_figure.poem_array[pos];
} else {
alpha_poem[done] = that_figure.poem_array[pos];
omega_poem[done] = this_figure.poem_array[pos];
}
done_array[pos] = true;
done += 1;
}
}
return {
one: alpha_poem,
two: omega_poem
};
}
*/
// just randomize poetic elements, not line ordering
function the_other_poem()
{
var len = this_figure.poem_array.length;
var alpha_poem = [];
var omega_poem = [];
var done_array = [];
for (var i = 0; i < len; i += 1) {
done_array[i] = false;
}
var done = 0;
while (done < len) {
if (toss()) {
alpha_poem[done] = this_figure.poem_array[done];
omega_poem[done] = that_figure.poem_array[done];
} else {
alpha_poem[done] = that_figure.poem_array[done];
omega_poem[done] = this_figure.poem_array[done];
}
done += 1;
}
return {
one: alpha_poem,
two: omega_poem
};
}
function click_the_other()
{
var title = (toss() ? this_title() : that_title());
var poem = the_other_poem();
var the_el = "dynamic_element";
poemify(title, poem, the_el);
}
</script>
</head>
<body>
<div id="page">
<div id="this_side">
<div id_"style_chooser">
<a href="#" onclick="click_this()">Α</a>
</div>
</div>
<br> <!-- crappy separator for now -->
<div id="that_side">
<div id_"style_chooser">
<a href="#" onclick="click_that()">Ω</a>
</div>
</div>
<br> <!-- crappy separator for now -->
<div id="the_other_side">
<div id_"style_chooser">
<a href="#" onclick="click_the_other()">~</a>
</div>
</div>
<br>
<div id="double_figure">
<script type="text/javascript">
var divil = '';
var the_el = "dynamic_element";
divil += '<div id="' + the_el + '"></div>\n';
document.write(divil);
click_this();
</script>
</div>
</div>
</body>
</html>