-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathscript.js
806 lines (680 loc) · 29.4 KB
/
script.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
/**
* @summary Script for embedding live videos from various streaming providers into Tenth.org
*
* @author James Kurtz
* @copyright 2017
* @licence See https://github.com/TenthPres/livestreams for terms
*/
class Livestream {
// scriptBase = document.scripts[document.scripts.length-1].src.replace(/(\/\/.*?\/.*\/).*/g,"$1"); // TODO make static once FF supports
// singleton = null; // TODO make static once FF supports
/**
*
*
* @function
*/
constructor() {
// Declare properties
this.mode = null;
this.container = null;
this.mediaElt = null;
this.self = null;
this.vm = {
interval: null,
runs: {
live: [],
archive: [],
upcoming: []
},
orderContent: [],
hymnContent: [],
scriptureContent: [],
preferHymnLyrics: null
};
// Declare static properties
if (Livestream.singleton === undefined) {
Livestream.singleton = null;
}
// Constructor, proper
if (Livestream.singleton === null) {
Livestream.singleton = this;
this.self = this;
if (document.getElementsByClassName('livestream-container').length === 0) {
this.mode = "status"; // only relays status
this.loadLivestreamStatus();
if (this.vm.interval !== null)
clearInterval(this.vm.interval);
this.vm.interval = setInterval(this.loadLivestreamStatus, 30000);
} else {
this.mode = "player"; // uses a player
/** Create new HTML elements & define variables */
let knockoutLib = document.createElement('script');
this.mediaElt = document.createElement('p');
/** Load Knockout, if it isn't loaded */
if (!window.hasOwnProperty("ko")) {
knockoutLib.src = '//cdnjs.cloudflare.com/ajax/libs/knockout/3.5.0/knockout-min.js';
knockoutLib.type = 'text/javascript';
let that = this;
knockoutLib.addEventListener("load", function() {that.initalizeModels()}, true);
document.getElementsByTagName("head")[0].appendChild(knockoutLib);
} else {
this.initalizeModels();
}
this.container = document.getElementsByClassName('livestream-container')[0];
/** Insert "Loading..." into the video container. */
this.mediaElt.innerHTML = "loading...";
this.container.appendChild(this.mediaElt);
}
} else {
console.error("Not a livestream singleton.")
}
}
/**
* Initialize the observables in the view model with Knockout.
*
* @function
*/
initalizeModels() {
this.vm.runs.live = ko.observableArray([]);
this.vm.runs.archive = ko.observableArray([]);
this.vm.runs.upcoming = ko.observableArray([]);
this.vm.messages = ko.observableArray([]);
this.vm.currentRun = ko.observable({}); // the whole program
this.vm.currentSource = ko.observable("loading"); // the source id
this.vm.currentOrder = ko.observable({});
this.vm.currentAttachment = ko.observable(null);
this.vm.preferHymnLyrics = ko.observable(true);
ko.applyBindings(this.vm, document.body);
this.loadLivestreamStatus();
if (this.vm.interval !== null)
clearInterval(this.vm.interval);
let that = this;
this.vm.interval = setInterval(function() { that.loadLivestreamStatus(); }, 10000);
}
/**
* Create and send the Live XHR Request
*
* @function
*/
loadLivestreamStatus() {
let xhr = new XMLHttpRequest(),
runId = getUrlParameter("event"),
that = this;
xhr.Timeout = 4000;
xhr.withCredentials = true;
xhr.addEventListener('load', function() {that.loadLivestreamStatus_listener(this)}, true);
xhr.addEventListener('timeout', function() {that.loadLivestreamStatus_timeout()}, true);
if (this.mode === "status")
xhr.open("GET", Livestream.scriptBase + "live/json/" + (getUrlParameter('test') !== undefined ? "?test" : ""));
else // video mode
xhr.open("GET", Livestream.scriptBase + "live/json/?s=" + this.vm.currentSource() + (runId ? '&r=' + runId : '') + (getUrlParameter('test') !== undefined ? "&test" : ""));
xhr.send();
if (typeof ga === 'function' && this.vm.currentRun().hasOwnProperty('_id')) // assume Google Analytics is loaded.
ga('send', 'event', { 'eventCategory': 'Livestream', 'eventAction': 'Ping', 'eventLabel': 'Program ' + this.vm.currentRun()._id });
}
/**
* Listener for Live XHR Response
*
* @function
*/
loadLivestreamStatus_listener(xhr) {
// receive response.
let response = JSON.parse(xhr.responseText),
livestreamActiveBodyClassName = "livestreamActive";
// update status class
if (document.body.classList.contains(livestreamActiveBodyClassName) && response.live.length <= 0)
document.body.classList.remove(livestreamActiveBodyClassName);
if (!document.body.classList.contains(livestreamActiveBodyClassName) && response.live.length > 0)
document.body.classList.add(livestreamActiveBodyClassName);
// if we only care about status, then stop here.
if (this.mode === 'status')
return;
if (typeof this.vm.runs.live !== "function" || JSON.stringify(this.vm.runs.live()) !== JSON.stringify(response.live)) { // update vm streams if there's a change
this.vm.runs.live(response.live);
}
if (JSON.stringify(this.vm.runs.archive()) !== JSON.stringify(response.archive)) { // update vm archive if there's a change
this.vm.runs.archive(response.archive);
}
if (JSON.stringify(this.vm.runs.upcoming()) !== JSON.stringify(response.upcoming)) { // update vm upcoming if there's a change
this.vm.runs.upcoming(response.upcoming);
}
if (!this.sourceIsValid(this.vm.currentSource())) { // if the client is watching a source that's no longer valid.
this.clearMediaWindow();
this.vm.currentSource("loading");
this.vm.currentRun({});
}
if (this.vm.currentSource() === "loading") { // if the client is in "loading" mode
let ev = parseInt(getUrlParameter("event")),
evObj = undefined;
if (getUrlParameter("event") > 0) {
// find the program object in the available streams.
evObj = this.vm.runs.live().find(function(evO) {
return evO._id === ev;
});
if (evObj === undefined) {
evObj = this.vm.runs.archive().find(function(evO) {
return evO._id === ev;
});
}
if (evObj === undefined) {
evObj = this.vm.runs.upcoming().find(function(evO) {
return evO._id === ev;
});
}
// Play source for object
if (evObj !== undefined) {
if (evObj.sources.length > 0) {
this.playSource(evObj.sources[0], evObj);
}
} else {
this.mediaElt.innerHTML = "The livestream you're looking for isn't currently available.";
if (response.live.length > 0) {
this.mediaElt.innerHTML += "<br />However, others are live now."
}
}
} else {
if (response.live.length > 0) {
if (response.live[0].sources.length > 0) {
this.playSource(response.live[0].sources[0], response.live[0]);
} else {
this.mediaElt.innerHTML = "A livestream is currently available, but is not compatible with your browser.<br />Please consider using a different browser."
}
} else {
this.mediaElt.innerHTML = "There is no livestream currently available.<br />We will display the livestream here as soon as it begins."
}
}
}
/* Handle messages */
// TODO figure out a method for hashing messages so they don't all need to be sent every time.
// TODO apply that hashing mechanism to descriptions, too.
if (response.messages !== undefined && JSON.stringify(this.vm.messages()) !== JSON.stringify(response.messages)) { // updates only if there's a change. (Helps avoid needless UI refresh)
this.vm.messages(response.messages);
if (document.body.getElementsByClassName('video_messages').length > 0)
document.body.getElementsByClassName('video_messages')[0].innerHTML = this.vm.messages().join('<br /><br />');
}
}
/**
* Handler for when the XHR times out. TODO figure out a good way for reporting this back to some analytics mechanism.
*
* @function
*/
loadLivestreamStatus_timeout() {
window.console.info('XHR Timeout');
}
/**
* Clear the mediaElement and replace with a space for text.
*
* @function
*/
clearMediaWindow() {
this.container.removeChild(this.mediaElt);
this.mediaElt = document.createElement('p');
this.container.appendChild(this.mediaElt);
}
/**
* Clear the mediaElement and replace with an iFrame for inserting video into.
*
* @function
*/
createMediaFrame() {
this.container.removeChild(this.mediaElt);
this.mediaElt = document.createElement('iframe');
this.mediaElt.classList.add("video_mediaElt");
this.mediaElt.setAttribute('allowFullScreen','');
this.mediaElt.setAttribute('scrolling','no');
this.container.appendChild(this.mediaElt);
}
// noinspection JSUnusedGlobalSymbols
/**
* Starts playing a given source.
* When called, this should be bound to the object.
*
* @function
* @param source {object} A source object from within a LiveEvent object.
* @param run {object} The run object now to be played.
*/
playSource(source, run) {
this.createMediaFrame();
if (JSON.stringify(this.vm.currentRun()) !== JSON.stringify(run)) {
// New program is different from current one (attachments and such thus change).
this.vm.currentRun(run);
window.history.pushState(null, null, "?event=" + this.vm.currentRun()._id + (getUrlParameter('test') !== undefined ? "&test" : ""));
if (typeof ga === 'function') // assume Google Analytics is loaded.
ga('send', 'event', { 'eventCategory': 'Livestream', 'eventAction': 'Select Program', 'eventLabel': 'Program ' + this.vm.currentRun()._id });
this.loadOrderContent(this.vm.currentRun().order._id);
}
this.vm.currentSource(source._id);
switch (source.provider) {
case "yt":
this.playYouTube(source);
return;
case "fb":
this.playFacebook(source);
return;
case "vm":
this.playVimeo(source);
return;
case "sa":
this.playSA(source);
return;
}
console.error("Source unplayable because provider is unknown.")
}
/**
* Play a YouTube source.
*
* @function
* @param source {object} A source object from within a LiveEvent object.
*/
playYouTube(source) {
this.mediaElt.src = "//www.youtube.com/embed/" + source.providerId + "?autoplay=1&rel=0&showinfo=0&color=white";
// TODO invoke YT JS API to determine if user interacts while this video is presented.
}
/**
* Play a Vimeo source.
*
* @function
* @param source {object} A source object from within a LiveEvent object.
*/
playVimeo(source) {
this.mediaElt.src = "//player.vimeo.com/video/" + source.providerId + "?color=b61c24&api=1";
}
/**
* Play a Facebook source.
*
* @function
* @param source {object} A source object from within a LiveEvent object.
*/
playFacebook(source) {
this.mediaElt.src = "//www.facebook.com/plugins/video.php?href=https%3A%2F%2Fwww.facebook.com%2Ftenth%2Fvideos%2F" + source.providerId + "%2F&width=400";
}
/**
* Play a SermonAudio audio or video stream with no vendor-specific arrangements.
*
* @function
* @param source {object} A source object from within a LiveEvent object.
*/
playSA(source) {
this.mediaElt.src = "//embed.sermonaudio.com/player/l/tenth/?autoplay=true" + (source.providerId === "aud" ? "&quality=audio" : "");
}
// noinspection JSUnusedGlobalSymbols
/**
* Helps clarify provider for a given stream in the UI. This is called by knockout bindings.
*
* @function
* @param source {object} A source object from within a LiveEvent object. These are defined by the JSON from the
* server, and are stored in vm.livePrograms
* @returns {string} A string useful for distinguishing between streams.
*/
streamLabel(source) {
let s = "";
switch (source.provider) {
case "yt":
s += "YouTube Video";
break;
case "fb":
s += "Facebook Live";
break;
case "vm":
s += "Vimeo";
break;
case "sa":
s += "SermonAudio";
break;
}
if (this.vm.currentSource() === source._id)
s += "\nNow Playing";
return s;
}
loadOrderContent(orderId) {
if ((!this.vm.currentRun().order.hasHtml && !this.vm.currentRun().order.hasJson) || this.vm.orderContent[this.vm.currentRun().order._id] !== undefined) {
return;
}
let xhr = new XMLHttpRequest(),
that = this;
xhr.Timeout = 2000;
xhr.addEventListener('load', function() {that.loadOrderContent_listener(this)}, true);
xhr.open("GET", Livestream.scriptBase + "wo/content.php?o=" + orderId);
xhr.send();
}
loadOrderContent_listener(xhr) {
// receive response.
let response = JSON.parse(xhr.responseText);
// put response in vm where it can be referenced.
this.vm.orderContent[response._id] = response;
// update attachments
if (this.vm.currentRun().order._id === response._id)
this.vm.currentOrder(this.vm.orderContent[response._id]);
}
// noinspection JSUnusedGlobalSymbols
/**
* Provides the verb to use to describe the primary interaction with each stream.
*
* @function
* @param source {object} A source object from within a LiveEvent object.
* @returns {string} The pertinent verb
*/
static playVerb(source) {
switch (source.provider) {
case "yt":
case "fb":
case "vm":
return "Watch";
case "sa":
if (source.providerId === 'aud') {
return "Listen";
}
return "Watch";
}
return "Join" // seems to be the most generic term that would apply, even if watch/listen don't.
}
// noinspection JSUnusedGlobalSymbols
/**
* Comparison function for sorting sources by their verb. Puts "Watch" first.
*
* @function
* @param a {object} A source object
* @param b {object} A source object
* @returns {number}
*/
static compareSourceByVerb(a, b) {
if (Livestream.playVerb(a) === Livestream.playVerb(b))
return 0;
if (Livestream.playVerb(a) === 'Watch')
return -1;
if (Livestream.playVerb(b) === 'Watch')
return 1;
return 0;
}
/**
* @function Determines if a source with a given ID is currently valid for display. Most useful for after a live events ends.
* @param {object} source The source object.
* @returns {boolean} True of the source is valid for display.
*/
sourceIsValid(source) {
if (source === 'loading') // 'loading' is always a valid source because of the possibility that it could be paused.
return true;
if (source.provider === "yt") // youtube is always a valid source.
return true;
if (source.provider === "fb") // facebook is only a valid source when live or past.
return (source.status === "LIVE" || source.status === "COMPLETED");
if (source.provider === "vm") // vimeo is only a valid source when past (for now).
return (source.status === "COMPLETED");
// for everything else, if it's in the list of current sources, it's valid. If it's not, it's not.
return true // TODO make useful.
}
// noinspection JSUnusedGlobalSymbols
/**
* For UI iterations that allow attachments (scripture, order of worship, etc.) to be shown to the user.
*
* @param attachment {object} The attachment object, originating with the json response.
* @param event {event} Optional. The event (probably click) by which the attachment has been selected.
*/
selectAttachment(attachment, event) {
if (this.vm.currentAttachment() !== null) {
this.vm.currentAttachment().contentBox.classList.add("hidden");
}
// initialize attachment, if not initialized already.
if (!attachment.hasOwnProperty('contentBox')) {
if (attachment.hasOwnProperty('html')) { // Order of Worship. Also provides some future flexibility for other things that have their HTML pre-defined.
attachment.contentBox = document.createElement('div');
attachment.contentBox.classList.add('attachment');
document.getElementsByClassName('attachmentContentSection')[0].appendChild(attachment.contentBox);
attachment.contentBox.classList.add('orderOfWorship');
attachment.contentBox.innerHTML = attachment.html;
} else if (attachment.name.substr(0, 3) === "TH ") { // Hymnal
if (!this.vm.hymnContent.hasOwnProperty(attachment.name)) {
attachment.contentBox = this.loadAttachment_hymn(attachment.name.substr(3));
attachment.type = "hymn";
} else {
attachment.contentBox = this.vm.hymnContent[attachment.name].contentBox;
}
} else {
if (!this.vm.scriptureContent.hasOwnProperty(attachment.name)) {
attachment.contentBox = this.loadAttachment_scripture(attachment.name);
} else {
attachment.contentBox = this.vm.scriptureContent[attachment.name].contentBox;
}
}
}
this.vm.currentAttachment(attachment);
attachment.contentBox.classList.remove('hidden');
if (typeof ga === 'function') { // assume Google Analytics is loaded.
ga('send', 'event', { 'eventCategory': 'Livestream', 'eventAction': 'Attachment: ' + attachment.type, 'eventLabel': attachment.name });
}
}
loadAttachment_hymn(number) {
this.vm.hymnContent[number] = {
contentBox: document.createElement('div'),
lyricsBox: null,
musicBox: null
};
this.vm.hymnContent[number].contentBox.classList.add('attachment');
document.getElementsByClassName('attachmentContentSection')[0].appendChild(this.vm.hymnContent[number].contentBox);
let lyricsBox = document.createElement('div'),
musicBox = document.createElement('div');
lyricsBox.classList.add('subattachment');
musicBox.classList.add('subattachment');
lyricsBox.innerHTML = "Loading...";
musicBox.innerHTML = "Loading...";
lyricsBox.setAttribute('data-bind', 'visible: L.vm.preferHymnLyrics() === true');
musicBox.setAttribute('data-bind', 'visible: L.vm.preferHymnLyrics() === false');
this.vm.hymnContent[number].contentBox.appendChild(lyricsBox);
this.vm.hymnContent[number].contentBox.appendChild(musicBox);
this.vm.hymnContent[number].lyricsBox = lyricsBox;
this.vm.hymnContent[number].musicBox = musicBox;
ko.applyBindings(this.vm, this.vm.hymnContent[number].contentBox);
let xhr = new XMLHttpRequest(),
that = this;
xhr.Timeout = 2000;
xhr.addEventListener('load', function() {that.loadAttachment_hymn_listener(this)}, true);
xhr.open("GET", Livestream.scriptBase + "wo/hymn.php?h=" + number);
xhr.send();
return this.vm.hymnContent[number].contentBox;
}
loadAttachment_hymn_listener(xhr) {
let response = JSON.parse(xhr.responseText);
if (!response.hasOwnProperty('num')) {
console.error("Server did not provide hymn number is response.");
return;
}
if (response.hasOwnProperty('text') && response.text !== null) {
if (response.text === false) {
this.vm.hymnContent[response.num].lyricsBox.innerHTML = "<p>Due to copyright constraints, we cannot provide the lyrics for this hymn online.</p>";
} else {
this.vm.hymnContent[response.num].lyricsBox.innerHTML = response.text;
}
}
if (response.hasOwnProperty('images') && response.images !== null) {
if (response.images === false) {
this.vm.hymnContent[response.num].musicBox.innerHTML = "<p>Due to copyright constraints, we cannot provide the music for this hymn online.</p>";
} else {
this.vm.hymnContent[response.num].musicBox.innerHTML = "";
for (let im in response.images) {
if (!response.images.hasOwnProperty(im))
continue;
let io = document.createElement('img');
io.src = response.images[im];
this.vm.hymnContent[response.num].musicBox.appendChild(io);
}
}
}
}
loadAttachment_scripture(ref) {
this.vm.scriptureContent[ref] = {
contentBox: document.createElement('div')
};
this.vm.scriptureContent[ref].contentBox.classList.add('attachment');
document.getElementsByClassName('attachmentContentSection')[0].appendChild(this.vm.scriptureContent[ref].contentBox);
this.vm.scriptureContent[ref].contentBox.innerHtml = "Loading...";
let xhr = new XMLHttpRequest(),
that = this;
xhr.Timeout = 2000;
xhr.addEventListener('load', function() {that.loadAttachment_scripture_listener(this)}, true);
xhr.open("GET", Livestream.scriptBase + "wo/esv.php?q=" + ref);
xhr.send();
return this.vm.scriptureContent[ref].contentBox;
}
loadAttachment_scripture_listener(xhr) {
let response = JSON.parse(xhr.responseText);
this.vm.scriptureContent[response.ref].contentBox.innerHTML = response.passages[0];
}
/**
* Resets the tabs and marks the tab itself as 'active' for styling.
*
* @function
* @param caller
*/
switchTabs_reset(caller) {
/* Hide other content sections. */
if (this.vm.currentAttachment() !== null) {
this.vm.currentAttachment().contentBox.style.display = 'none';
}
var sidebars = document.getElementsByClassName('sidebar');
if (sidebars.length > 0)
sidebars[0].style.display = '';
/* Remove 'active' class from tab */
if (caller !== undefined) {
var tabs = caller.parentNode.parentNode.children;
for (var ti in tabs) {
if (!tabs.hasOwnProperty(ti))
continue;
tabs[ti].classList.remove('active');
}
/* Add 'active' class to caller tab */
caller.parentNode.classList.add('active');
}
}
}
// noinspection JSUnusedGlobalSymbols
// /**
// * For UI iterations that allow attachments (scripture, order of worship, etc.) to be shown to the user.
// *
// * @param attachment {object} The attachment object, originating with the json response.
// * @param event {event} Optional. The event (probably click) by which the attachment has been selected.
// */
// function selectAttachment(attachment, event) {
// if (event !== undefined)
// switchTabs_reset(event.target);
// else
// switchTabs_reset();
// if (!attachment.hasOwnProperty('contentBox')) {
// attachment.contentBox = document.createElement('div');
// attachment.contentBox.classList.add('attachment');
// document.getElementsByClassName('attachmentContentSection')[0].appendChild(attachment.contentBox);
// if (attachment.name.substr(0, 3) === "TH ") { // Hymnal
// attachment.type = "Hymn";
// populateAttachment_TH(attachment);
// } else if (attachment.hasOwnProperty("ifrUrl")) {
// attachment.type = "Document";
// populateAttachment_ifr(attachment);
// } else {
// attachment.type = "Scripture";
// populateAttachment_ESV(attachment);
// }
// }
// vm.currentAttachment(attachment);
// attachment.contentBox.style.display = "";
// if (typeof ga === 'function') { // assume Google Analytics is loaded.
// ga('send', 'event', { 'eventCategory': 'Livestream', 'eventAction': 'Attachment: ' + attachment.type, 'eventLabel': attachment.name });
// }
// }
// function populateAttachment_TH(attachment) {
// attachment.contentBox.innerHTML = "<p>loading...</p>";
// var hymnNumber = attachment.name.substr(3),
// xhr = new XMLHttpRequest();
// xhr.open('GET', scriptBase + 'attachments/TH/?h=' + hymnNumber);
// xhr.addEventListener('load', function() {
// if (this.responseText === '') {
// attachment.contentBox.innerHTML = "<p>Due to copyright constraints, we cannot provide the music for this hymn online.</p>"
// } else {
// attachment.contentBox.innerHTML = this.responseText;
// }
// });
// xhr.send();
// }
//
//
// function populateAttachment_ESV(attachment) {
// attachment.contentBox.innerHTML = "<p>loading...</p>";
// var passage = attachment.name.split(':',3),
// xhr = new XMLHttpRequest();
//
// if (passage.length > 2 && passage[1].indexOf("-") !== -1)
// passage = passage[0] + "-" + passage[1].split('-')[1];
// else
// passage = passage[0];
// xhr.open('GET', scriptBase + 'attachments/ESV/?q=' + passage);
// xhr.addEventListener('load', function() {
// if (this.responseText === '') {
// attachment.contentBox.innerHTML = "<p>Hmmm... couldn't load the passage. Sorry about that.</p>"
// } else {
// attachment.contentBox.innerHTML = this.responseText;
// }
// });
// xhr.send();
// }
//
//
// function populateAttachment_ifr(attachment) {
// if (attachment.hasOwnProperty('ifrUrl')) {
// var ifr = document.createElement('iframe');
// ifr.src = attachment.ifrUrl;
// attachment.contentBox.appendChild(ifr);
// } else {
// attachment.contentBox.innerHTML = "Can't load content, because it was not correctly specified. Sorry about that.";
// }
// }
/**
* When the window is narrow, the list of possible streams appears as one of the attachment tabs. The considerations
* for that particular tab are a little special 'cuz of that extra display line, so it gets its own function.
*
* @function
* @param caller
*/
function switchTabs_streamsList(caller) {
switchTabs_reset(caller);
document.getElementsByClassName('sidebar')[0].style.display = 'block';
vm.currentAttachment(null);
}
/**
* Extract a given URL Parameter from the request bar.
*
* @function
* @param name {string} The name of the parameter for which the value is sought.
* @returns {string|undefined|null} The value of the specified parameter.
* Undefined if parameter is absent,
* null if parameter is present but has no definition.
*
* @link https://stackoverflow.com/a/11582513/2339939
*/
function getUrlParameter(name) {
let uri = (new RegExp('[?&](' + name + ')(?:=([^&;]+))?').exec(location.search) || ['&', undefined, undefined]);
if (uri[1] === name) {
if (uri[2] === undefined)
return null;
return decodeURIComponent(uri[2].replace(/\+/g, '%20'));
}
return undefined;
}
/**
* Send some stuff to Google Analytics concerning hit sources.
*/
function startupAnalytics() {
if (getUrlParameter('mc_eid')) {
ga('set', 'dimension1', getUrlParameter('mc_eid'));
}
}
/** Initializations */
let L = null;
// Livestream.scriptBase = document.scripts[document.scripts.length - 1].src.replace(/(\/\/.*?\/.*\/).*/g, "$1");
Livestream.scriptBase = "//west.tenth.org/";
if (document.readyState === 'complete') {
L = new Livestream();
startupAnalytics();
} else {
window.addEventListener('load', function() {
L = new Livestream();
startupAnalytics();
});
}