-
Notifications
You must be signed in to change notification settings - Fork 60
/
xenith.js
5596 lines (4798 loc) · 213 KB
/
xenith.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
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Licensed to The Apereo Foundation under one or more contributor license
* agreements. See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
* The Apereo Foundation licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// all elements, variables and functions for interface are called "x_id" - do not make new id's prefixed with "x_" in page models
var XENITH = {};
var x_languageData = [],
x_params = new Object(), // all attributes of learningObject that aren't undefined
x_pages, // xml info about all pages in this LO
x_pageInfo = [], // holds info about pages (type, built, linkID, pageID, standalone, savedData) - use savedData if any input from page needs to be saved for use on other pages or on return to this page
x_normalPages = [], // indexes of pages in x_pages that are normal pages (i.e. not standalone)
x_urlParams = {},
x_startPage = {type : "index", ID : "0"},
x_currentPage = -1,
x_currentPageXML,
x_specialChars = [],
x_inputFocus = false,
x_dialogInfo = [], // (type, built)
x_browserInfo = {iOS:false, Android:false, touchScreen:false, mobile:false, orientation:"portrait"}, // holds info about browser/device
x_pageHistory = [], // keeps track of pages visited for historic navigation
x_firstLoad = true,
x_fillWindow = false,
x_volume = 1,
x_audioBarH = 30,
x_mediaText = [],
x_deepLink = "",
x_timer, // use as reference to any timers in page models - they are cancelled on page change
x_responsive = [], // list of any responsivetext.css files in use
x_cssFiles = [],
x_specialTheme = '',
x_pageLoadPause = false,
x_btnIcons = [
// default interface buttons icons can be overriden:
// x_params[custom] = should a custom btn icon be used (FA icon selected in editor)? true/false
// x_params[name+'Icon'] = the icon to use if custom is true
// defaultFA = old themes that use images for buttons can have all btns set to use these default FA icons using themeIcons checkbox
// defaultIconClass = if icon isn't customised via icon selectors in editor or themeIcons checkbox, fallback to use this css style (this will mean btn icons/images set in theme will be used)
{name: 'max', defaultIconClass:'x_maximise', custom: 'fullScreenIcons', defaultFA: 'fas fa-expand-arrows-alt'}, // full screen on
{name: 'min', defaultIconClass:'x_minimise', custom: 'fullScreenIcons', defaultFA: 'fas fa-compress-arrows-alt'}, // full screen off
{name: 'prev', defaultIconClass:'x_prev', custom: 'navIcons', defaultFA: 'fas fa-chevron-circle-left'}, // previous page
{name: 'next', defaultIconClass:'x_next', custom: 'navIcons', defaultFA: 'fas fa-chevron-circle-right'}, // next page
{name: 'toc', defaultIconClass:'x_info', custom: 'navIcons', defaultFA: 'fas fa-bars'}, // table of contents
{name: 'home', defaultIconClass:'x_home', custom: 'navIcons', defaultFA: 'fas fa-home'}, // home page
{name: 'hideTools', defaultIconClass:'fa fa-angle-double-left fa-lg', custom: 'footerToolIcons', defaultFA: 'fas fa-angle-double-left'}, // footer tools hide
{name: 'showTools', defaultIconClass:'fa fa-angle-double-right fa-lg', custom: 'footerToolIcons', defaultFA: 'fas fa-angle-double-right'}, // footer tools show
{name: 'accessibility', defaultIconClass:'x_colourChanger', custom: 'accessibilityIc', defaultFA: 'fas fa-eye-slash'}, // accessibility options
{name: 'help', defaultIconClass:'x_help', custom: 'helpIc', defaultFA: 'fas fa-question'}, // project help file
{name: 'saveSession', defaultIconClass:'x_saveSession', custom: 'saveSessionIc', defaultFA: 'fas fa-save'}, // save session
{name: 'glossary', defaultIconClass:'x_glossary', custom: 'glossaryIc', defaultFA: 'fas fa-book'}, // glossary
{name: 'intro', defaultIconClass:'x_projectIntro', custom: 'introIc', defaultFA: 'fas fa-info'}, // project introduction
{name: 'pageIntro', defaultIconClass:'fas fa-info', custom: 'pageIntroIc', defaultFA: 'fas fa-info'}, // page introduction
{name: 'sideBarHideLeft', defaultIconClass:'fa fa-angle-double-left', custom: 'sideBarBtnIcons', defaultFA: 'fas fa-angle-double-left'}, // side bar hide (bar on left)
{name: 'sideBarHideRight', defaultIconClass:'fa fa-angle-double-right', custom: 'sideBarBtnIcons', defaultFA: 'fas fa-angle-double-right'}, // side bar hide (bar on right)
{name: 'sideBarShowLeft', defaultIconClass:'fa fa-angle-double-right', custom: 'sideBarBtnIcons', defaultFA: 'fas fa-angle-double-right'}, // side bar show (bar on left)
{name: 'sideBarShowRight', defaultIconClass:'fa fa-angle-double-left', custom: 'sideBarBtnIcons', defaultFA: 'fas fa-angle-double-left'} // side bar show (bar on right)
],
x_sideBarBtns = [];
// Determine whether offline mode or not
var xot_offline = !(typeof modelfilestrs === 'undefined');
var modelfilestrs = modelfilestrs || [];
var $x_window, $x_body, $x_head, $x_mainHolder, $x_mobileScroll, $x_headerBlock, $x_pageHolder, $x_helperText, $x_pageDiv, $x_footerBlock, $x_footerL,
$x_introBtn, $x_helpBtn, $x_pageIntroBtn, $x_glossaryBtn, $x_menuBtn, $x_colourChangerBtn, $x_saveSessionBtn, $x_prevBtn, $x_pageNo, $x_nextBtn, $x_cssBtn, $x_background;
$(document).keydown(function(e) {
// if lightbox open then don't allow page up/down buttons to change the page open in the background
// Place lightbox check in a try block, because an exception will be triggereed if LO is embedded in an iframe
let shownInFeatherlight = false;
try
{
shownInFeatherlight = parent.window.$.featherlight.current();
}
catch (e)
{
// Ignore
}
if (!shownInFeatherlight) {
switch(e.which) {
case 33: // PgUp
var pageIndex = $.inArray(x_currentPage, x_normalPages);
if (pageIndex > -1 && $x_prevBtn.is(":enabled") && $x_nextBtn.is(":visible")) {
if (x_params.navigation != "Historic" && x_params.navigation != "LinearWithHistoric") {
// linear back
if (pageIndex > 0) {
x_changePage(x_normalPages[pageIndex -1]);
}
} else {
var prevPage = x_pageHistory[x_pageHistory.length-2];
x_pageHistory.splice(x_pageHistory.length - 2, 2);
// check if history is empty and if so allow normal back navigation and change to normal back button
if (prevPage == undefined && x_currentPage > 0) {
x_changePage(x_normalPages[pageIndex -1]);
} else {
x_changePage(prevPage);
}
}
} else if (pageIndex == -1) {
// historic back (standalone page)
if (history.length > 1 && ((x_params.forcePage1 != undefined && x_params.forcePage1 != 'true') || shownInFeatherlight)) {
history.go(-1);
} else {
x_changePage(x_normalPages[0]);
}
}
break;
case 34: // PgDn
// if it's a standalone page then nothing will happen
var pageIndex = $.inArray(x_currentPage, x_normalPages);
if (pageIndex != -1 && $x_nextBtn.is(":enabled") && $x_nextBtn.is(":visible")) {
x_changePage(x_normalPages[pageIndex + 1]);
}
break;
default: return; // exit this handler for other keys
}
} else {
return;
}
});
$(document).ready(function() {
// Load the loadjs dependency loader
if (!xot_offline) {
// TODO - we should move this to play/preview and let it kickstart the loading of all files
$.getScript(x_templateLocation + "common_html5/js/loadjs.min.js");
}
$x_mainHolder = $("#x_mainHolder");
if (navigator.userAgent.match(/iPhone/i) != null || navigator.userAgent.match(/iPod/i) != null || navigator.userAgent.match(/iPad/i) != null) {
x_browserInfo.iOS = true;
if (navigator.userAgent.match(/iPad/i) != null) {
x_browserInfo.Device = "iPad";
}
else
{
x_browserInfo.Device = "iPhone";
}
}
if (navigator.userAgent.match(/Android/i) != null)
{
x_browserInfo.Android = true;
}
// detect touchscreen function (https://patrickhlauke.github.io/touch/touchscreen-detection/)
function detectTouchscreen() {
var result = false;
if (window.PointerEvent && ('maxTouchPoints' in navigator)) {
// if Pointer Events are supported, just check maxTouchPoints
if (navigator.maxTouchPoints > 0) {
result = true;
}
} else {
// no Pointer Events...
if (window.matchMedia && window.matchMedia("(any-pointer:coarse)").matches) {
// check for any-pointer:coarse which mostly means touchscreen
result = true;
} else if (window.TouchEvent || ('ontouchstart' in window)) {
// last resort - check for exposed touch events API / event handler
result = true;
}
}
return result;
}
x_browserInfo.touchScreen = detectTouchscreen();
if (x_browserInfo.touchScreen == true) {
$x_mainHolder.addClass("x_touchScreen");
}
x_browserInfo.mobile = x_isMobileBrowser();
// get xml data and sort it
if (typeof dataxmlstr != 'undefined')
{
var newString = x_makeAbsolute(x_fixLineBreaks(dataxmlstr)),
xmlData = $($.parseXML(newString)).find("learningObject");
x_projectDataLoaded(xmlData);
}
else {
var now = new Date().getTime();
let url = "website_code/php/templates/get_template_xml.php?file=" + x_projectXML + "&time=" + now;
if (typeof use_url !== "undefined" && use_url)
{
url = x_projectXML + "?time=" + now;
}
$.ajax({
type: "GET",
url: url,
dataType: "text",
success: function (text) {
var newString = x_makeAbsolute(x_fixLineBreaks(text)),
xmlData = $($.parseXML(newString)).find("learningObject");
x_projectDataLoaded(xmlData);
},
error: function () {
// can't have translation for this as if it fails to load we don't know what language file to use
$("body").append("<p>The project data has not loaded.</p>");
}
});
}
});
x_pagesViewed = function()
{
var viewed = [];
x_pageInfo.forEach(function(item, index){
if (item.viewed) {
viewed.push(index);
}
});
return viewed;
}
x_restorePagesViewed = function(viewed)
{
viewed.forEach(function(item){
x_pageInfo[item].viewed = true;
});
}
// To be able to check on orientation, and also detect the difference between a mobile and tablet
// See https://stackoverflow.com/questions/11381673/detecting-a-mobile-browser
x_isMobileBrowser = function() {
var check = false;
(function(a){if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0,4))) check = true;})(navigator.userAgent||navigator.vendor||window.opera);
return check;
};
x_projectDataLoaded = function(xmlData) {
var i, len;
var markedPages = new Array();
for (i = 0, len = xmlData[0].attributes.length; i < len; i++) {
x_params[xmlData[0].attributes[i].name] = xmlData[0].attributes[i].value;
}
// author support should only work when previewed (not play link)
if (x_params.authorSupport == "true") {
if (window.location.pathname.substring(window.location.pathname.lastIndexOf("/") + 1, window.location.pathname.length).indexOf("preview") == -1) {
x_params.authorSupport = "false";
}
}
// sort any parameters in url - these will override those in xml
var tempUrlParams = window.location.href.slice(window.location.href.indexOf('?') + 1).split(/[#&]/),
hash;
for (var i=0; i<tempUrlParams.length; i++) {
var split = tempUrlParams[i].split("=");
if (split.length == 2) {
x_urlParams[split[0]] = split[1];
} else {
hash = tempUrlParams[i];
}
}
x_pages = xmlData.children();
var pageToHide = [],
currActPage = 0;
x_pages.each(function (i) {
// work out whether the page is hidden or not - can be simply hidden or hidden between specific dates/times
var hidePage = $(this)[0].getAttribute("hidePage") == "true" ? true : false;
if (hidePage == true) {
// get current date/time according to browser
var nowTemp = new Date();
var now = {day:nowTemp.getDate(), month:nowTemp.getMonth()+1, year:nowTemp.getFullYear(), time:Number(String(nowTemp.getHours()) + (String(nowTemp.getMinutes()) < 10 ? '0' : '') + String(nowTemp.getMinutes()))};
// functions to get hide on/until date/times from xml
var hideOn, hideUntil,
hideOnString = '', hideUntilString = '';
var getDateInfo = function(dmy, hm) {
// some basic checks of whether values are valid & then splits the data into time/day/month/year
var tempDmy = dmy.split('/'), // original date format
formatType = 0,
format = [[0,1,2], [2,1,0]]; // d, m, y
if (tempDmy.length == 3) {
dmy = tempDmy;
} else if (tempDmy.length == 1) {
tempDmy = dmy.split('-'); // try the newer date format
if (tempDmy.length == 3) {
tempDmy.splice(2, 1, tempDmy[2].split('T')[0]);
dmy = tempDmy;
formatType = 1;
} else {
dmy = false;
}
} else {
dmy = false;
}
if (dmy == false) {
return [false];
} else {
var day = Math.max(1, Math.min(Number(dmy[format[formatType][0]]), 31)),
month = Math.max(1, Math.min(Number(dmy[format[formatType][1]]), 12)),
year = Math.max(Number(dmy[format[formatType][2]]), 2017),
time = 0; // use midnight if no time is given
if (hm != undefined && hm.trim() != '') {
var hm = hm.split(':');
if (hm.length == 2) {
var hour = Math.min(Number(hm[0]), 23),
minute = Math.min(Number(hm[1]), 59);
time = Number(String(hour) + (minute < 10 ? '0' : '') + String(minute));
}
}
return [{day:day, month:month, year:year, time:time}, (formatType == 0 ? day + '/' + month + '/' + year : year + '-' + month + '-' + day)];
}
}
var getFullDate = function(info) {
var timeZero = '';
for (var i=0; i<4-String(info.time).length; i++) {
timeZero += '0';
}
return Number(String(info.year) + (info.month < 10 ? '0' : '') + String(info.month) + (info.day < 10 ? '0' : '') + String(info.day) + timeZero + String(info.time));
}
var skipHideDateCheck = false,
hideOnInfo,
hideUntilInfo;
if ($(this)[0].getAttribute("hideOnDate") != undefined && $(this)[0].getAttribute("hideOnDate") != '') {
hideOnInfo = getDateInfo($(this)[0].getAttribute("hideOnDate"), $(this)[0].getAttribute("hideOnTime"));
hideOn = hideOnInfo[0];
}
if ($(this)[0].getAttribute("hideUntilDate") != undefined && $(this)[0].getAttribute("hideUntilDate") != '') {
hideUntilInfo = getDateInfo($(this)[0].getAttribute("hideUntilDate"), $(this)[0].getAttribute("hideUntilTime"));
hideUntil = hideUntilInfo[0];
}
// if hide from & to date/times are identical then hide (to prevent issue with a previous release where these were never blank but pages should have been hidden)
if ($(this)[0].getAttribute("hideOnDate") != undefined && $(this)[0].getAttribute("hideOnDate") != '' && $(this)[0].getAttribute("hideUntilDate") != undefined && $(this)[0].getAttribute("hideUntilDate") != '') {
if (hideOn.day == hideUntil.day && hideOn.month == hideUntil.month && hideOn.year == hideUntil.year) {
if ($(this)[0].getAttribute("hideOnTime") == $(this)[0].getAttribute("hideUntilTime") || $(this)[0].getAttribute("hideOnTime") == '' || $(this)[0].getAttribute("hideUntilTime") == '') {
skipHideDateCheck = true;
}
}
}
if (skipHideDateCheck != true) {
// is it hidden from a certain date? if so, have we passed that date/time?
if ($(this)[0].getAttribute("hideOnDate") != undefined && $(this)[0].getAttribute("hideOnDate") != '') {
if (hideOn != false) {
if (hideOn.year > now.year || (hideOn.year == now.year && hideOn.month > now.month) || (hideOn.year == now.year && hideOn.month == now.month && hideOn.day > now.day) || (hideOn.year == now.year && hideOn.month == now.month && hideOn.day == now.day && hideOn.time > now.time)) {
hidePage = false;
}
hideOnString = '{from}: ' + hideOnInfo[1] + ' ' + $(this)[0].getAttribute("hideOnTime");
}
}
// is it hidden until a certain date? if so, have we passed that date/time?
if ($(this)[0].getAttribute("hideUntilDate") != undefined && $(this)[0].getAttribute("hideUntilDate") != '') {
if (hideUntil != false) {
// if hideUntil date is before hideOn date then the page is hidden/shown/hidden rather than shown/hidden/shown & it might need to be treated differently:
var skip = false;
if (hideOn != undefined && getFullDate(hideOn) > getFullDate(hideUntil)) {
if (hidePage == false) {
hidePage = true;
} else {
skip = true;
}
}
if (skip != true && hidePage == true) {
if (hideUntil.year < now.year || (hideUntil.year == now.year && hideUntil.month < now.month) || (hideUntil.year == now.year && hideUntil.month == now.month && hideUntil.day < now.day) || (hideUntil.year == now.year && hideUntil.month == now.month && hideUntil.day == now.day && hideUntil.time <= now.time)) {
hidePage = false;
}
}
hideUntilString = '{until}: ' + hideUntilInfo[1] + ' ' + $(this)[0].getAttribute("hideUntilTime");
}
}
}
// language data hasn't been sorted yet so temporarily just store the attribute name of where we can later get the language we need
var infoString = '';
if (hideOnString != '') {
infoString += '(' + hideOnString;
}
if (hideUntilString != '') {
if (infoString == '') { infoString += '('; } else { infoString += ' & '; }
infoString += hideUntilString;
}
if (infoString != '') { infoString += ')'; }
if (hidePage == true) {
infoString = '{hidden} ' + infoString;
} else {
infoString = '{shown} ' + infoString;
}
$(this)[0].setAttribute("hidePageInfo", infoString);
}
if (hidePage == false || x_params.authorSupport == "true") {
var linkID = $(this)[0].getAttribute("linkID"),
pageID = $.trim($(this)[0].getAttribute("pageID")),
page = {type: $(this)[0].nodeName, built: false, viewed: false};
if (linkID != undefined) {
page.linkID = linkID;
}
// pageID optional property was deprecated previously but has been brought back
// it's now blank when added to editor but need to ignore default text that used to be in field prior to it being deprecated
if (pageID != undefined && pageID != "" && pageID != "Unique ID for this page") {
// if pages have custom ID then make sure they don't include spaces
page.pageID = pageID.split(" ").join("_");
}
// Get child linkIDs for deeplinking
page.childIDs = [];
var tempArrays = [];
var allChildIDs = function($this, array) {
$this.children().each(function () {
var $child = $(this)
if ($child.children().length > 0) {
array.push($child[0].getAttribute("linkID"));
tempArrays.push([]);
var tempArray = tempArrays[tempArrays.length-1];
allChildIDs($child, tempArray);
array.push(tempArray);
} else {
array.push($child[0].getAttribute("linkID"));
}
});
}
allChildIDs($(this), page.childIDs);
// is this a standalone page?
if ($(this)[0].getAttribute("linkPage") == 'true') {
page.standalone = true;
}
x_pageInfo.push(page);
if (($(this)[0].getAttribute("unmarkForCompletion") === "false" || $(this)[0].getAttribute("unmarkForCompletion") == undefined) && this.nodeName !== "results" )
{
markedPages.push(currActPage);
currActPage++;
}
else {
currActPage++;
}
}
else {
pageToHide.push(i);
}
});
// removes hidden pages from x_pages array
var numPages = x_pages.length,
offset = 0;
for (var i=0; i<numPages; i++) {
if (pageToHide.indexOf(i) != -1) {
x_pages.splice(i-offset, 1);
offset++;
}
}
// make array containing indexes of normal pages (not standalone)
for (var i=0; i<x_pageInfo.length; i++) {
if (x_pageInfo[i].standalone != true) {
x_normalPages.push(i);
}
}
if (x_normalPages.length < 2) {
// don't show navigation options if there's only one page
$("#x_footerBlock .x_floatRight").remove();
} else {
if (x_params.navigation == undefined) {
x_params.navigation = "Linear";
}
if (x_params.navigation != "Linear" && x_params.navigation != "LinearWithHistoric" && x_params.navigation != "Historic" && x_params.navigation != undefined) { // 1st page is menu
x_pages.splice(0, 0, "menu");
x_pageInfo.splice(0, 0, {type: 'menu', built: false, viewed:false});
// adjust normal page indexes to take into account menu page
for (var i=0; i<x_normalPages.length; i++) {
x_normalPages.splice(i, 1, x_normalPages[i]+1);
}
x_normalPages.splice(0, 0, 0);
}
}
if (x_params.fixDisplay != undefined) {
if ($.isNumeric(x_params.fixDisplay.split(",")[0]) == true && $.isNumeric(x_params.fixDisplay.split(",")[1]) == true) {
x_params.displayMode = x_params.fixDisplay.split(",");
x_fillWindow = false; // overrides fill window for touchscreen devices
}
}
// there are several URL params that can determine the 1st page viewed - check if they are valid pages before setting start page
var customStartPage = false;
if (x_urlParams.linkID) { // ID auto-generated in xwd e.g. URL/play_123&linkID=PG1593081880325
var temp = getDeepLink(x_urlParams.linkID);
if (temp.length > 1) {
x_deepLink = temp[1];
}
var validPage = x_lookupPage("linkID", temp[0]);
if (validPage !== false) {
x_startPage = { type : "index", ID : validPage };
customStartPage = true;
}
delete x_urlParams.linkID;
}
if (x_urlParams.pageID) { // ID created by author OR auto-generated in xwd e.g. URL/play_123&pageID=customID OR URL/play_123&pageID=PG1593081880325
var temp = getDeepLink(x_urlParams.pageID);
if (temp.length > 1) {
x_deepLink = temp[1];
}
var validPage = x_lookupPage("pageID", temp[0]);
if (validPage !== false) {
x_startPage = { type : "index", ID : validPage };
customStartPage = true;
}
delete x_urlParams.pageID;
}
if (x_urlParams.page) { // ID created by author OR numeric page number e.g. URL/play_123&page=customID OR URL/play_123&page=5
var temp = getDeepLink(x_urlParams.page);
if (temp.length > 1) {
x_deepLink = temp[1];
}
var validPage = x_lookupPage("pageID", temp[0]);
if (validPage !== false) {
x_startPage = {type : "index", ID : validPage};
customStartPage = true;
} else {
if ($.isNumeric(temp[0]) && temp[0] <= x_normalPages.length) {
var tempIndex = x_normalPages[Number(temp[0])-1];
x_startPage = { type : "index", ID : tempIndex };
customStartPage = true;
}
}
delete x_urlParams.page;
}
if (x_urlParams.resume) { // Numeric page number e.g. URL/play_123#resume=5 - deprecated but needs to work for existing links
var temp = getDeepLink(x_urlParams.resume);
if (temp.length > 1) {
x_deepLink = temp[1];
}
if ($.isNumeric(temp[0]) && temp[0] <= x_normalPages.length) {
var tempIndex = x_normalPages[Number(temp[0])-1];
x_startPage = { type : "index", ID : tempIndex };
customStartPage = true;
}
delete x_urlParams.resume;
}
if (hash != undefined) { // ID created by author OR numeric page number e.g. URL/play_123#customID OR URL/play_123#page5 OR URL/play_123#5
var temp = getDeepLink(hash);
if (temp.length > 1) {
x_deepLink = temp[1];
}
var info = getHashInfo(temp[0]);
if (info !== false) {
x_startPage = {type : "index", ID : info};
customStartPage = true;
}
}
// any params in URL which can change the start page can be disabled from working by adding optional property
// also, if 1st page is project is standalone page then it should default to 1st non-standalone page instead
if (x_pageInfo[x_startPage.ID] != undefined) {
if ((x_pageInfo[x_startPage.ID].standalone == true && customStartPage == false) ||
(x_params.forcePage1 == 'true' && customStartPage == true && (x_pageInfo[x_startPage.ID].standalone == undefined || x_pageInfo[x_startPage.ID].standalone == false))) {
var tempIndex;
for (var i=0; i<x_pageInfo.length; i++) {
if (x_pageInfo[i].standalone != true) {
tempIndex = i;
break;
}
}
if (tempIndex) {
x_startPage = {type : "index", ID : String(tempIndex)};
} else {
x_startPage = {type : "index", ID : "0"};
}
}
}
// tidy up the URL to remove all of the params about start page - hash at end of URL will change according to currently viewed page
var shortParams = "";
Object.keys(x_urlParams).forEach(function(key, index) {
shortParams += index==0 ? '?' : '&';
shortParams += key + '=' + x_urlParams[key];
});
// change URL params without reloading the page
window.history.pushState('window.location.href', "", shortParams);
// url embed parameter uses ideal setup for embedding in iframes - can be overridden with other parameters below
if (x_urlParams.embed == 'true') {
x_params.embed = true;
x_params.displayMode = 'full screen';
x_params.responsive = 'false';
// css button also won't appear
}
// url display parameter will set size of LO (display=fixed|full|fill - or a specified size e.g. display=200,200)
if (x_urlParams.display != undefined) {
if ($.isNumeric(x_urlParams.display.split(",")[0]) == true && $.isNumeric(x_urlParams.display.split(",")[1]) == true) {
x_params.displayMode = x_urlParams.display.split(",");
x_fillWindow = false; // overrides fill window for touchscreen devices
} else if (x_urlParams.display == "fixed" || x_urlParams.display == "default" || x_urlParams.display == "full" || x_urlParams.display == "fill") {
if (x_browserInfo.mobile == true) {
x_fillWindow = true;
}
if (x_urlParams.display == "fixed" || x_urlParams.display == "default") { // default fixed size using values in css (800,600)
x_params.displayMode = "default";
} else if (x_urlParams.display == "full" || x_urlParams.display == "fill") {
x_params.displayMode = "full screen"
}
}
}
if (window.location.href.indexOf("/peer.php") != -1 || window.location.href.indexOf("/peerreview_") != -1) {
x_params.displayMode = "default";
x_fillWindow = false;
}
// this is being shown in iframe so force to fill available space
if (self !== top) {
x_fillWindow = true;
}
// url hide parameter will remove x_headerBlock &/or x_footerBlock divs
if (x_urlParams.hide != undefined) {
if (x_urlParams.hide == "none") {
x_params.hideHeader = "false";
x_params.hideFooter = "false";
} else if (x_urlParams.hide == "both") {
x_params.hideHeader = "true";
x_params.hideFooter = "true";
} else if (x_urlParams.hide == "bottom") {
x_params.hideHeader = "false";
x_params.hideFooter = "true";
} else if (x_urlParams.hide == "top") {
x_params.hideHeader = "true";
x_params.hideFooter = "false";
}
}
// url parameter to turn responsive on / off
if (x_urlParams.responsive != undefined && (x_urlParams.responsive == "true" || x_urlParams.responsive == "false")) {
x_params.responsive = x_urlParams.responsive;
}
if (x_urlParams.theme != undefined && (x_params.themeurl == undefined || x_params.themeurl != 'true'))
{
x_params.theme = x_urlParams.theme;
}
// Setup nr of pages for tracking
XTSetOption('nrpages', x_pageInfo.length);
XTSetOption('toComplete', markedPages);
XTSetOption('templateId', x_TemplateId);
XTSetOption('templateName', x_params.name);
if (x_params.trackingMode != undefined) {
XTSetOption('tracking-mode', x_params.trackingMode);
}
if (x_params.trackingPassed != undefined)
{
// Get value, and try to convert to decimal between 0 and 1
var passed = x_params.trackingPassed;
var factor = 1;
var percpos = passed.indexOf('%')
if (percpos > 0)
{
factor = 0.01;
passed = passed.substr(0, passed.indexOf('%'));
}
// Change decimal ',' to '.'
passed = passed.replace(',', '.');
var passednumber = Number(passed) * factor;
XTSetOption('objective_passed', passednumber);
}
if (x_params.trackingPageTimeout != undefined)
{
XTSetOption('page_timeout', x_params.trackingPageTimeout);
}
if (x_params.forceTrackingMode != undefined)
{
XTSetOption('force_tracking_mode', x_params.forceTrackingMode);
}
if (typeof x_embed == "undefined")
{
x_embed = false;
x_embed_activated = false;
}
if (x_embed && !x_embed_activated)
{
// Activate overlay
$("#x_embed_overlay")
.switchClass("embed-overlay-inactive", "embed-overlay")
.click(function(){
window.location = x_embed_activation_url;
})
.append("<span><i class='far fa-play-circle fa-2x'></i></span>");
}
x_getThemeInfo(x_params.theme);
}
function x_getThemeInfo(thisTheme, themeChg) {
// what icons / images will be used on interface buttons?
// some older themes use images for interface buttons (not FontAwesome icons) - it's only these themes that can fall back to use the defaultFA (all others should have FA icons set in theme)
// these themes should have imgbtns: true in the theme info file
if (thisTheme == undefined || thisTheme == "default") {
x_params.theme = "default";
x_setUpThemeBtns({imgbtns: 'true'}, themeChg);
} else if (xot_offline) {
const temp = themeinfo.split('\n'),
themeInfo = {};
for (let i=0; i<temp.length; i++) {
if (temp[i].split(':').length > 1) {
themeInfo[temp[i].split(':')[0]] = temp[i].split(':')[1].trim();
}
}
x_setUpThemeBtns(themeInfo, themeChg);
} else {
$.ajax({
type: "GET",
url: x_themePath + thisTheme + '/' + thisTheme + '.info',
dataType: "text",
success: function (text) {
const temp = text.split('\n'),
themeInfo = {};
for (let i=0; i<temp.length; i++) {
if (temp[i].split(':').length > 1) {
themeInfo[temp[i].split(':')[0]] = temp[i].split(':')[1].trim();
}
}
x_setUpThemeBtns(themeInfo, themeChg);
},
error: function(err) {
if (err.status == 404)
{
// Fall back to default
x_params.theme = "default";
x_setUpThemeBtns({ imgbtns: 'true' }, themeChg);
}
else
{
x_setUpThemeBtns({}, themeChg);
}
}
});
}
}
function x_setUpThemeBtns(themeInfo, themeChg) {
let themeIcons = x_params.themeIcons;
if (themeIcons != 'true' || themeInfo.imgbtns != 'true') {
themeIcons = false;
}
// buttons on side bar will always use icons & not images
if (themeChg !== true) {
x_sideBarBtnInfo();
}
for (let i=0; i<x_btnIcons.length; i++) {
x_btnIcons[i].customised = false;
x_btnIcons[i].btnImgs = false;
x_btnIcons[i].iconClass = x_btnIcons[i].defaultIconClass;
const tempName = x_btnIcons[i].name == 'home' ? 'toc' : x_btnIcons[i].name;
if (x_params[x_btnIcons[i].custom] == 'true') {
// a custom icon has individually been selected in editor for this button
x_btnIcons[i].iconClass = x_params[x_btnIcons[i].name + 'Icon'];
x_btnIcons[i].customised = true;
} else if (themeIcons == 'true' || (themeInfo.imgbtns == 'true' && $.inArray(tempName, x_sideBarBtns) != -1)) {
// it's an old theme where all button images are to be overridden with the default FontAwesome icons
// either because update theme icons is checked or button is on side bar
x_btnIcons[i].iconClass = x_btnIcons[i].defaultFA;
x_btnIcons[i].customised = true;
} else if (themeInfo.imgbtns == 'true') {
x_btnIcons[i].btnImgs = true;
}
}
if (themeChg !== true) {
x_getLangData(x_params.language); // x_setUp() function called in here after language file loaded
} else {
// theme has been changed sometime after the project has already loaded
// change classes on interface buttons as new theme may use a different type of btn (FontAwesome / image)
var btns = [ { btn: $x_helpBtn, name: 'help' }, { btn: $x_introBtn, name: 'intro' }, { btn: $x_colourChangerBtn, name: 'accessibility' }, { btn: $x_nextBtn, name: 'next' }, { btn: $x_saveSessionBtn, name: 'saveSession' }, { btn: $x_glossaryBtn, name: 'glossary' } ];
for (let i=0; i<btns.length; i++) {
if (btns[i].btn != undefined) {
const btnIcon = x_btnIcons.filter(function(icon){return icon.name === btns[i].name;})[0];
btns[i].btn.button({ icons: { primary: btnIcon.iconClass } });
if (btnIcon.customised == true) { btns[i].btn.addClass("customIconBtn"); } else { btns[i].btn.removeClass("customIconBtn"); };
if (btnIcon.btnImgs == true) { btns[i].btn.addClass("imgIconBtn"); } else { btns[i].btn.removeClass("imgIconBtn"); };
}
}
// now do btns where icon works slightly differently
if ($x_cssBtn != undefined) {
let btnIcon;
if (x_fillWindow == false) {
btnIcon = x_btnIcons.filter(function(icon){return icon.name === 'max';})[0];
} else {
btnIcon = x_btnIcons.filter(function(icon){return icon.name === 'min';})[0];
}
$x_cssBtn.button({ icons: { primary: btnIcon.iconClass } });
if (btnIcon.customised == true) { $x_cssBtn.addClass("customIconBtn"); } else { $x_cssBtn.removeClass("customIconBtn"); };
if (btnIcon.btnImgs == true) { $x_cssBtn.addClass("imgIconBtn"); } else { $x_cssBtn.removeClass("imgIconBtn"); };
}
if ($x_prevBtn != undefined) {
const btnIcon = x_btnIcons.filter(function(icon){return icon.name === 'prev';})[0];
if ((x_params.navigation == "Historic" || x_params.navigation == "LinearWithHistoric") && btnIcon.customised === false) {
btnIcon.iconClass = "x_prev_hist";
}
$x_prevBtn.button({ icons: { primary: btnIcon.iconClass } });
if (btnIcon.customised == true) { $x_prevBtn.addClass("customIconBtn"); } else { $x_prevBtn.removeClass("customIconBtn"); };
if (btnIcon.btnImgs == true) { $x_prevBtn.addClass("imgIconBtn"); } else { $x_prevBtn.removeClass("imgIconBtn"); };
}
if ($x_menuBtn != undefined) {
let btnIcon = x_btnIcons.filter(function(icon){return icon.name === 'toc';})[0];
if (x_params.navigation == "Historic") {
btnIcon = x_btnIcons.filter(function(icon){return icon.name === 'home';})[0];
}
$x_menuBtn.button({ icons: { primary: btnIcon.iconClass } });
if (btnIcon.customised == true) { $x_menuBtn.addClass("customIconBtn"); } else { $x_menuBtn.removeClass("customIconBtn"); };
if (btnIcon.btnImgs == true) { $x_menuBtn.addClass("imgIconBtn"); } else { $x_menuBtn.removeClass("imgIconBtn"); };
}
}
}
// browser back / fwd button will trigger this - manually make page change to match #pageX
window.onhashchange = function() {
if (x_params.forcePage1 == undefined || x_params.forcePage1 != 'true') {
var temp = getDeepLink(window.location.hash);
if (temp.length > 1) {
x_deepLink = temp[1];
}
var pageInfo = getHashInfo(temp[0]);
if (pageInfo !== false) {
x_navigateToPage(false, { type: "index", "ID": pageInfo }, false );
}
}
// force lightbox to close
// catch error - in case we're in an iframe, i.e. bootstrap or LMS LTI link
try {
if (parent.window.$.featherlight.current()) {
parent.window.$.featherlight.current().close();
}
}
catch(e) {}
}
// Get the page info from the URL (called on project load & when page changed via browser fwd/back btns)
function getHashInfo(urlHash) {
if (urlHash.length > 0) {
var pageLink = urlHash[0] == '#' ? urlHash.substring(1) : urlHash,
thisPage;
if (pageLink.substring(0,4) == "page") { // numeric page number e.g. URL/play_123#page5
var tempNum = Number(pageLink.substring(4));
if (tempNum < 1 || tempNum > x_normalPages.length) {
thisPage = false;
} else {
thisPage = x_normalPages[tempNum-1];
}
} else { // ID created by author OR numeric page number e.g. URL/play_123#customID OR URL/play_123#page5 OR URL/play_123#5
var validPage = x_lookupPage("pageID", pageLink);
if (validPage !== false) {
thisPage = validPage;
} else if ($.isNumeric(pageLink)) {
var tempNum = Number(pageLink);
if (tempNum < 1 || tempNum > x_normalPages.length) {
thisPage = false;
} else {
thisPage = x_normalPages[tempNum-1];
}
} else {
thisPage = false;
}
}
return thisPage;
} else {
return false;
}
}
// Make absolute urls from urls with FileLocation + ' in their strings
x_makeAbsolute = function(html){
//var tempDecoded = decodeURIComponent(html);
// var tempDecoded = $('<textarea/>').html(tempURIDecoded).text();
var temp = html.replace(/FileLocation \+ \'([^\']*)\'/g, FileLocation + '$1');
return temp;
}
// replace all line breaks in attributes with ascii code - otherwise these are replaced with spaces when parsed to xml
function x_fixLineBreaks(text) {
var split_up = text.split(/<\!\[CDATA\[|\]\]>/),
temp, i, j, len, len2;
for (i=0, len=split_up.length; i<len; i+=2) {
temp = split_up[i].split('"');
for (j=1, len2=temp.length; j<len2; j+=2) {
temp[j] = temp[j].replace(/(\n|\r|\r\n)/g, " ");
}
split_up[i] = temp.join('"');
}
// Put the CDATA blocks back...
temp = [];
for (i=0, len=split_up.length-1; i<len; i+=2) {
temp.push(split_up[i] + "<![CDATA[" + split_up[i+1]);
}
temp.push(split_up[i]);
return temp.join("]]>");
}
// function gets data from language file
function x_getLangData(lang) {
if (typeof langxmlstr != 'undefined')
{
// We have a off-line object with the language definition in a string
// Convert to an XML object and continue like before
langxmlstr = langxmlstr.substr(langxmlstr.indexOf("<"), langxmlstr.lastIndexOf(">") + 1);
x_languageData = $($.parseXML(langxmlstr)).find("language");
x_setUp();
}
else {
if (lang == undefined || lang == "undefined" || lang == "") {
lang = "en-GB";
}