-
-
Notifications
You must be signed in to change notification settings - Fork 38
/
ui.js
877 lines (746 loc) · 23.8 KB
/
ui.js
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
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
/***********************************************************************************************************************
ui.js
Copyright © 2013–2024 Thomas Michael Edwards <thomasmedwards@gmail.com>. All rights reserved.
Use of this source code is governed by a BSD 2-clause "Simplified" License, which may be found in the LICENSE file.
***********************************************************************************************************************/
/*
global Alert, Config, Dialog, Engine, Has, L10n, Save, Setting, State, Story, Wikifier,
createSlug, errorPrologRegExp, triggerEvent
*/
var UI = (() => { // eslint-disable-line no-unused-vars, no-var
/*******************************************************************************
Utility Functions.
*******************************************************************************/
function assembleLinkList(passage, listEl) {
let list = listEl;
// Cache the value of `Config.debug`, then disable it during this method's run.
const debugState = Config.debug;
Config.debug = false;
try {
if (list == null) { // lazy equality for null
list = document.createElement('ul');
}
// Wikify the content of the given source passage into a fragment.
const frag = document.createDocumentFragment();
new Wikifier(frag, Story.get(passage).processText().trim(), { cleanup : false });
// Gather the text of any error elements within the fragment…
const errors = Array.from(frag.querySelectorAll('.error'))
.map(errEl => errEl.textContent.replace(errorPrologRegExp, ''));
// …and throw an exception, if there were any errors.
if (errors.length > 0) {
throw new Error(errors.join('; '));
}
while (frag.hasChildNodes()) {
const node = frag.firstChild;
// Create list items for <a>-element nodes.
if (node.nodeType === Node.ELEMENT_NODE && node.nodeName.toUpperCase() === 'A') {
const li = document.createElement('li');
list.appendChild(li);
li.appendChild(node);
}
// Discard non-<a>-element nodes.
else {
frag.removeChild(node);
}
}
}
finally {
// Restore `Config.debug` to its original value.
Config.debug = debugState;
}
return list;
}
function buildRestart() {
if (BUILD_DEBUG) { console.log('[UI/buildRestart()]'); }
Dialog
.create(L10n.get('restartTitle'), 'restart')
.append(
/* eslint-disable max-len */
`<p>${L10n.get('restartMesgPrompt')}</p><ul class="buttons">`
+ `<li><button id="restart-ok">${L10n.get(['restartTextOk', 'textOk'])}</button></li>`
+ `<li><button id="restart-cancel" class="ui-close">${L10n.get(['restartTextCancel', 'textCancel'])}</button></li>`
+ '</ul>'
/* eslint-enable max-len */
);
// NOTE: Instead of adding '.ui-close' to the '#restart-ok' button (to receive
// the use of the default delegated dialog close handler), we set up a special
// case close handler here. We do this to ensure that the invocation of
// `Engine.restart()` happens after the dialog has fully closed. If we did not,
// then a race condition could occur, causing display shenanigans.
jQuery(Dialog.body())
.find('#restart-ok')
.ariaClick({ one : true }, () => {
jQuery(document).one(':dialogclosed', () => Engine.restart());
Dialog.close();
});
return true;
}
function buildSaves() {
function createFileInput(id, callback) {
const input = document.createElement('input');
jQuery(input)
.attr({
id,
type : 'file',
tabindex : -1,
'aria-hidden' : true
})
.css({
display : 'block',
visibility : 'hidden',
position : 'fixed',
left : '-16128px', // 8K UHD horizontal ×2.1
top : '-16128px', // 8K UHD horizontal ×2.1
width : '1px',
height : '1px'
})
.on('change', callback);
return input;
}
function createActionItem(id, classNames, text, label, callback) {
const $btn = jQuery(document.createElement('button'))
.attr('id', `saves-${id}`)
.text(text);
if (classNames) {
$btn.addClass(classNames);
}
if (callback) {
$btn.ariaClick({ label }, callback);
}
else {
$btn.ariaDisabled(true);
}
return jQuery(document.createElement('li'))
.append($btn);
}
function createSaveList() {
function createButton(id, classNames, kind, index, callback) {
let text;
switch (id) {
case 'delete': text = L10n.get('textDelete'); break;
case 'load': text = L10n.get('textLoad'); break;
case 'save': text = L10n.get('textSave'); break;
default: throw new Error(`buildSaves unknown ID "${id}"`);
}
const $btn = jQuery(document.createElement('button'))
.attr('id', `saves-${id}-${index}`)
.addClass(id);
if (classNames) {
$btn.addClass(classNames);
}
if (callback) {
$btn.ariaClick({
label : `${text} ${kind} ${index + 1}`
}, () => {
try {
callback(index);
}
catch (ex) {
openAlert(`${ex.message}.</p><p>${L10n.get('textAborting')}.`);
}
});
}
else {
$btn.ariaDisabled(true);
}
return $btn;
}
const $tbody = jQuery(document.createElement('tbody'));
// Create auto save UI entries.
Save.browser.auto.entries().forEach(({ index, info }) => {
/* legacy */
const $tdSlot = jQuery(document.createElement('td'));
/* /legacy */
const $tdLoad = jQuery(document.createElement('td'));
const $tdDesc = jQuery(document.createElement('td'));
const $tdDele = jQuery(document.createElement('td'));
// // Add the slot ID.
// $tdSlot
// .attr({
// title : `${L10n.get('savesTextBrowserAuto')} ${index + 1}`,
// 'aria-label' : `${L10n.get('savesTextBrowserAuto')} ${index + 1}`
// })
// .text(`A${index + 1}`);
// Add the description and details.
jQuery(document.createElement('div'))
.text(info.desc)
.appendTo($tdDesc);
jQuery(document.createElement('div'))
.addClass('details')
/* legacy */
.addClass('datestamp')
/* /legacy */
.text(`${L10n.get('savesTextBrowserAuto')}\u00a0${index + 1}\u00a0\u00a0\u2022\u00a0\u00a0`)
.append(
info.date
? `${new Date(info.date).toLocaleString()}`
: `<em>${L10n.get('savesTextNoDate')}</em>`
)
.appendTo($tdDesc);
// Add the load button.
$tdLoad.append(createButton(
'load',
'ui-close',
L10n.get('savesTextBrowserAuto'),
index,
index => {
jQuery(document).one(':dialogclosed', () => {
Save.browser.auto.load(index)
.then(
Engine.show,
ex => openAlert(`${ex.message.toUpperFirst()}.</p><p>${L10n.get('textAborting')}.`)
);
});
}
));
// Add the delete button.
$tdDele.append(createButton(
'delete',
null,
L10n.get('savesTextBrowserAuto'),
index,
index => {
Save.browser.auto.delete(index);
buildSaves();
}
));
jQuery(document.createElement('tr'))
/* legacy */
.append($tdSlot)
/* /legacy */
.append($tdLoad)
.append($tdDesc)
.append($tdDele)
.appendTo($tbody);
});
const slotAllowed = typeof Config.saves.isAllowed !== 'function' || Config.saves.isAllowed(Save.Type.Slot);
// Create slot save UI entries.
//
// NOTE: The array may be sparse.
Save.browser.slot.entries().reduce(
// Add slot entries.
(slots, entry) => {
slots[entry.index] = entry; // eslint-disable-line no-param-reassign
return slots;
},
// Fill configured slots with empty entries.
Array.from({ length : Config.saves.maxSlotSaves }, (_, i) => ({ index : i }))
).forEach(({ index, info }) => {
/* legacy */
const $tdSlot = jQuery(document.createElement('td'));
/* /legacy */
const $tdLoad = jQuery(document.createElement('td'));
const $tdDesc = jQuery(document.createElement('td'));
const $tdDele = jQuery(document.createElement('td'));
// // Add the slot ID.
// $tdSlot
// .attr({
// title : `${L10n.get('savesTextBrowserSlot')} ${index + 1}`,
// 'aria-label' : `${L10n.get('savesTextBrowserSlot')} ${index + 1}`
// })
// .text(index + 1);
if (info) {
// Add the description and details.
jQuery(document.createElement('div'))
.text(info.desc)
.appendTo($tdDesc);
jQuery(document.createElement('div'))
.addClass('details')
/* legacy */
.addClass('datestamp')
/* /legacy */
.text(`${L10n.get('savesTextBrowserSlot')}\u00a0${index + 1}\u00a0\u00a0\u2022\u00a0\u00a0`)
.append(
info.date
? `${new Date(info.date).toLocaleString()}`
: `<em>${L10n.get('savesTextNoDate')}</em>`
)
.appendTo($tdDesc);
// Add the load button.
$tdLoad.append(createButton(
'load',
'ui-close',
L10n.get('savesTextBrowserSlot'),
index,
index => {
jQuery(document).one(':dialogclosed', () => {
Save.browser.slot.load(index)
.then(
Engine.show,
ex => openAlert(`${ex.message.toUpperFirst()}.</p><p>${L10n.get('textAborting')}.`)
);
});
}
));
// Add the delete button.
$tdDele.append(createButton(
'delete',
null,
L10n.get('savesTextBrowserSlot'),
index,
index => {
Save.browser.slot.delete(index);
buildSaves();
}
));
}
else {
// Add the, mostly empty, description and details.
//
// QUESTION: Should `$tdDesc` also get `aria-hidden="true"`? The
// `empty` class has `speak: none`, but that may be insufficient.
$tdDesc.addClass('empty');
jQuery(document.createElement('div'))
.text('\u00a0')
.appendTo($tdDesc);
jQuery(document.createElement('div'))
.addClass('details')
/* legacy */
.addClass('datestamp')
/* /legacy */
.text(`${L10n.get('savesTextBrowserSlot')}\u00a0${index + 1}`)
.appendTo($tdDesc);
// Add the save button, possibly disabled.
$tdLoad.append(createButton(
'save',
null,
L10n.get('savesTextBrowserSlot'),
index,
index < Config.saves.maxSlotSaves && slotAllowed
? index => {
Save.browser.slot.save(index);
buildSaves();
}
: null
));
// Add the disabled delete button.
$tdDele.append(createButton(
'delete',
null,
L10n.get('savesTextBrowserSlot'),
index
));
}
jQuery(document.createElement('tr'))
/* legacy */
.append($tdSlot)
/* /legacy */
.append($tdLoad)
.append($tdDesc)
.append($tdDele)
.appendTo($tbody);
});
return jQuery(document.createElement('table'))
.attr('id', 'saves-list')
.append($tbody);
}
if (BUILD_DEBUG) { console.log('[UI/buildSaves()]'); }
const browserEnabled = Save.browser.isEnabled();
// Bail out if both saves and the file API are disabled/missing.
if (!browserEnabled && !Has.fileAPI) {
openAlert(L10n.get('warningNoSaves'));
return false;
}
Dialog.create(L10n.get('savesTitle'), 'saves');
const $dialogBody = jQuery(Dialog.body());
// Add slots header, list, and button list.
if (browserEnabled) {
jQuery(document.createElement('h2'))
.text(L10n.get('savesHeaderBrowser'))
.appendTo($dialogBody);
$dialogBody.append(createSaveList());
const $slotButtons = jQuery(document.createElement('ul'))
.addClass('buttons slots')
.appendTo($dialogBody);
if (Has.fileAPI) {
// Add the disk export/import buttons and the hidden `input[type=file]`
// element that will be triggered by the `#saves-import` button.
const slotImportInput = createFileInput('saves-import-handler', ev => {
Save.disk.import(ev)
.then(
buildSaves,
ex => openAlert(`${ex.message.toUpperFirst()}.</p><p>${L10n.get('textAborting')}.`)
);
});
$slotButtons
.append(createActionItem(
'export',
null,
`${L10n.get('textExport')}\u2026`,
L10n.get('savesLabelBrowserExport'),
() => Save.disk.export(`saves-export-${Story.name}`)
))
.append(createActionItem(
'import',
null,
`${L10n.get('textImport')}\u2026`,
L10n.get('savesLabelBrowserImport'),
() => slotImportInput.click()
));
jQuery(slotImportInput).appendTo($dialogBody);
}
// Add the slots clear button.
$slotButtons.append(createActionItem(
'clear',
null,
L10n.get('textClear'),
L10n.get('savesLabelBrowserClear'),
Save.browser.size > 0
? () => {
Save.browser.clear();
buildSaves();
}
: null
));
}
// Add the disk load and save buttons.
if (Has.fileAPI) {
jQuery(document.createElement('h2'))
.text(L10n.get('savesHeaderDisk'))
.appendTo($dialogBody);
const $diskButtons = jQuery(document.createElement('ul'))
.addClass('buttons')
.appendTo($dialogBody);
// Add the disk save/load buttons and the hidden `input[type=file]`
// element that will be triggered by the `#saves-disk-load` button.
const diskLoadInput = createFileInput('saves-disk-load-handler', ev => {
jQuery(document).one(':dialogclosed', () => {
Save.disk.load(ev)
.then(
Engine.show,
ex => openAlert(`${ex.message.toUpperFirst()}.</p><p>${L10n.get('textAborting')}.`)
);
});
Dialog.close();
});
$diskButtons
.append(createActionItem(
'disk-save',
null,
`${L10n.get('textSave')}\u2026`,
L10n.get('savesLabelDiskSave'),
typeof Config.saves.isAllowed !== 'function' || Config.saves.isAllowed(Save.Type.Disk)
? () => Save.disk.save(Story.name)
: null
))
.append(createActionItem(
'disk-load',
null,
`${L10n.get('textLoad')}\u2026`,
L10n.get('savesLabelDiskLoad'),
() => diskLoadInput.click()
));
jQuery(diskLoadInput).appendTo($dialogBody);
}
return true;
}
function buildSettings() {
if (BUILD_DEBUG) { console.log('[UI/buildSettings()]'); }
Dialog.create(L10n.get('settingsTitle'), 'settings');
const $dialogBody = jQuery(Dialog.body());
Setting.forEach(control => {
switch (control.type) {
case Setting.Types.Header: {
const name = control.name;
const id = createSlug(name);
const $header = jQuery(document.createElement('div'));
const $heading = jQuery(document.createElement('h2'));
$header
.attr('id', `header-body-${id}`)
.append($heading)
.appendTo($dialogBody);
$heading
.attr('id', `header-heading-${id}`)
.wikiWithOptions({ cleanup : false }, name);
// Set up the description, if any.
if (control.desc) {
jQuery(document.createElement('p'))
.attr('id', `header-desc-${id}`)
.wikiWithOptions({ cleanup : false }, control.desc)
.appendTo($header);
}
return;
}
case Setting.Types.Value: {
// no-op
return;
}
}
const name = control.name;
const id = createSlug(name);
const $setting = jQuery(document.createElement('div'));
const $label = jQuery(document.createElement('label'));
const $controlBox = jQuery(document.createElement('div'));
let $control;
// Set up the label+control wrapper.
jQuery(document.createElement('div'))
.append($label)
.append($controlBox)
.appendTo($setting);
// Set up the description, if any.
if (control.desc) {
jQuery(document.createElement('p'))
.attr('id', `setting-desc-${id}`)
.wikiWithOptions({ cleanup : false }, control.desc)
.appendTo($setting);
}
// Set up the label.
$label
.attr({
id : `setting-label-${id}`,
for : `setting-control-${id}` // must be in sync with $control's ID (see below)
})
.wikiWithOptions({ cleanup : false }, control.label);
// Set up the control.
if (Setting.getValue(name) == null) { // lazy equality for null
Setting.setValue(name, control.default);
}
switch (control.type) {
case Setting.Types.List: {
$control = jQuery(document.createElement('select'));
for (let i = 0, iend = control.list.length; i < iend; ++i) {
jQuery(document.createElement('option'))
.val(i)
.text(control.list[i])
.appendTo($control);
}
$control
.val(control.list.indexOf(Setting.getValue(name)))
.attr('tabindex', 0)
.on('change', function () {
Setting.setValue(name, control.list[Number(this.value)]);
});
break;
}
case Setting.Types.Range: {
$control = jQuery(document.createElement('input'));
// NOTE: Setting the value with `<jQuery>.val()` can cause odd behavior
// in Edge if it's called before the type is set, so we use the `value`
// content attribute here to dodge the entire issue.
$control
.attr({
type : 'range',
min : control.min,
max : control.max,
step : control.step,
value : Setting.getValue(name),
tabindex : 0
})
.on('change input', function () {
Setting.setValue(name, Number(this.value));
})
.on('keypress', ev => {
if (ev.which === 13) {
ev.preventDefault();
triggerEvent('change', $control);
}
});
break;
}
case Setting.Types.Toggle: {
$control = jQuery(document.createElement('button'));
if (Setting.getValue(name)) {
$control
.addClass('enabled')
.text(L10n.get('textOn'));
}
else {
$control
.text(L10n.get('textOff'));
}
$control.ariaClick(function () {
const status = Setting.getValue(name);
if (status) {
jQuery(this)
.removeClass('enabled')
.text(L10n.get('textOff'));
}
else {
jQuery(this)
.addClass('enabled')
.text(L10n.get('textOn'));
}
Setting.setValue(name, !status);
});
break;
}
}
$control
.attr('id', `setting-control-${id}`)
.appendTo($controlBox);
$setting
.attr('id', `setting-body-${id}`)
.appendTo($dialogBody);
});
// Add the button bar.
$dialogBody
.append(
'<ul class="buttons">'
+ `<li><button id="settings-ok" class="ui-close">${L10n.get(['settingsTextOk', 'textOk'])}</button></li>`
+ `<li><button id="settings-reset">${L10n.get('settingsTextReset')}</button></li>`
+ '</ul>'
)
.find('#settings-reset')
/*
Instead of adding '.ui-close' to '#settings-reset' (to receive the use of the default
delegated dialog close handler), we set up a special case close handler here. We
do this to ensure that the invocation of `window.location.reload()` happens after the
dialog has fully closed. If we did not, then a race condition could occur, causing
display shenanigans.
*/
.ariaClick({ one : true }, () => {
jQuery(document).one(':dialogclosed', () => {
Setting.reset();
window.location.reload();
});
Dialog.close();
});
return true;
}
function update() {
triggerEvent(':uiupdate');
}
/*******************************************************************************
Built-in Dialog Functions.
*******************************************************************************/
function openAlert(message, /* options, closeFn */ ...args) {
Dialog
.create(L10n.get('alertTitle'), 'alert')
.append(
`<p>${message}</p><ul class="buttons">`
+ `<li><button id="alert-ok" class="ui-close">${L10n.get(['alertTextOk', 'textOk'])}</button></li>`
+ '</ul>'
)
.open(...args);
}
function openRestart(/* options, closeFn */ ...args) {
buildRestart();
Dialog.open(...args);
}
function openSaves(/* options, closeFn */ ...args) {
buildSaves();
Dialog.open(...args);
}
function openSettings(/* options, closeFn */ ...args) {
buildSettings();
Dialog.open(...args);
}
/*******************************************************************************
Deprecated Functions.
*******************************************************************************/
// [DEPRECATED]
function buildAutoload() {
if (BUILD_DEBUG) { console.log('[UI/buildAutoload()]'); }
console.warn('[DEPRECATED] UI.buildAutoload() is deprecated.');
Dialog
.create(L10n.get('autoloadTitle'), 'autoload')
.append(
/* eslint-disable max-len */
`<p>${L10n.get('autoloadMesgPrompt')}</p><ul class="buttons">`
+ `<li><button id="autoload-ok" class="ui-close">${L10n.get(['autoloadTextOk', 'textOk'])}</button></li>`
+ `<li><button id="autoload-cancel" class="ui-close">${L10n.get(['autoloadTextCancel', 'textCancel'])}</button></li>`
+ '</ul>'
/* eslint-enable max-len */
);
// Add an additional delegated click handler for the `.ui-close` elements to handle autoloading.
jQuery(document).one('click.autoload', '.ui-close', ev => {
const isAutoloadOk = ev.target.id === 'autoload-ok';
jQuery(document).one(':dialogclosed', () => {
new Promise((resolve, reject) => {
if (isAutoloadOk) {
resolve();
}
reject(); // eslint-disable-line prefer-promise-reject-errors
})
.then(() => {
if (BUILD_DEBUG) { console.log('\tattempting autoload of browser continue'); }
return Save.browser.continue();
})
.catch(() => {
if (BUILD_DEBUG) { console.log(`\tstarting passage: "${Config.passages.start}"`); }
Engine.play(Config.passages.start);
});
});
});
return true;
}
// [DEPRECATED]
function buildJumpto() {
if (BUILD_DEBUG) { console.log('[UI/buildJumpto()]'); }
console.warn('[DEPRECATED] UI.buildJumpto() is deprecated.');
const list = document.createElement('ul');
Dialog
.create(L10n.get('jumptoTitle'), 'jumpto list')
.append(list);
const expired = State.expired.length;
for (let i = State.size - 1; i >= 0; --i) {
if (i === State.activeIndex) {
continue;
}
const passage = Story.get(State.history[i].title);
if (passage && passage.tags.includes('bookmark')) {
jQuery(document.createElement('li'))
.append(
jQuery(document.createElement('a'))
.ariaClick({ one : true }, (function (index) {
return () => jQuery(document).one(':dialogclosed', () => Engine.goTo(index));
})(i))
.addClass('ui-close')
.text(`${L10n.get('textTurn')} ${expired + i + 1}`)
)
.appendTo(list);
}
}
if (!list.hasChildNodes()) {
jQuery(list).append(`<li><a><em>${L10n.get('jumptoMesgUnavailable')}</em></a></li>`);
}
}
// [DEPRECATED]
function buildShare() {
if (BUILD_DEBUG) { console.log('[UI/buildShare()]'); }
console.warn('[DEPRECATED] UI.buildShare() is deprecated.');
try {
Dialog
.create(L10n.get('shareTitle'), 'share list')
.append(assembleLinkList('StoryShare'));
}
catch (ex) {
console.error(ex);
Alert.error('StoryShare', ex.message);
return false;
}
return true;
}
// [DEPRECATED]
function openJumpto(/* options, closeFn */ ...args) {
buildJumpto();
Dialog.open(...args);
}
// [DEPRECATED]
function openShare(/* options, closeFn */ ...args) {
buildShare();
Dialog.open(...args);
}
/*******************************************************************************
Object Exports.
*******************************************************************************/
return Object.preventExtensions(Object.create(null, {
// Utility Functions.
assembleLinkList : { value : assembleLinkList },
buildRestart : { value : buildRestart },
buildSaves : { value : buildSaves },
buildSettings : { value : buildSettings },
update : { value : update },
// Built-in Dialog Functions.
alert : { value : openAlert },
restart : { value : openRestart },
saves : { value : openSaves },
settings : { value : openSettings },
// Deprecated Functions.
buildAutoload : { value : buildAutoload },
buildJumpto : { value : buildJumpto },
buildShare : { value : buildShare },
jumpto : { value : openJumpto },
share : { value : openShare }
}));
})();