-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui.js
1808 lines (1581 loc) · 53.6 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
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
/**
* OVAL (Online Video Annotation for Learning) is a video annotation tool
* that allows users to make annotations on videos uploaded to the platform.
*
* Copyright (C) 2014 Shane Dawson, University of South Australia, Australia
* Copyright (C) 2014 An Zhao, University of South Australia, Australia
* Copyright (C) 2014 Dragan Gasevic, University of Edinburgh, United Kingdom
* Copyright (C) 2014 Neging Mirriahi, University of New South Wales, Australia
* Copyright (C) 2014 Abelardo Pardo, University of Sydney, Australia
* Copyright (C) 2014 Alan Kingstone, University of British Columbia, Canada
* Copyright (C) 2014 Thomas Dang, , University of British Columbia, Canada
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
var annotationTimeModified = false;
var annotationDialogOpen = false;
var viewAllAnnotations = true; // should default to true because students should see instructor's and TA's comment and vice versa.
var playheadMouseup = false;
// true if viewing/adding 'annotations' false if viewing/adding 'comments'
var annotationMode = true;
// true if in 'psycMode' and 'Add Annotation' button is being pressed
var psycModeAnnotating = false;
var videoAnnotationEntryID = null;
var annotations = [];
var comments = [];
// array index of currently open annotation dialog
var openAnnotationIndex = null;
// the time the user clicks "Add Annotation"
var createAnnotationStartTime;
// time of the currently active dialog (applies to pre-existing annotations only)
var dialogAnnotationStartTime;
var dialogAnnotationEndTime;
// seek time of the currently active dialog (applies to pre-existing annotations only)
var startTimeSeekPosition = 0;
var intervalID;
/*** CONSTANTS ***/
// seconds to seek at a time
var seekSpeed = 1;
var CONFIRMED = 1;
// set to dimension of video player
var sliderWidth = 550;
// current annotation-item
var currentPreviewItem = null;
function confirmDelete() {
if (annotationMode) {
type = "annotation";
list = annotations;
} else {
type = "comment";
list = comments;
}
debug("vid_anno_id " + list[openAnnotationIndex].videoAnnotationID);
if (confirm("Are you sure you want to delete this " + type + "?")) {
deleteAnnotation(
list[openAnnotationIndex].id,
list[openAnnotationIndex].videoAnnotationID
);
}
}
function isVideoAnnotation(videoAnnotationID) {
if (newAnnotation()) {
return "video" == $("#annotation-type").val();
} else {
// assert: pre-existing annotation
if (
null == videoAnnotationID ||
undefined == videoAnnotationID ||
"null" == videoAnnotationID
) {
return false;
} else {
return true;
}
}
}
function playerSee() {
var val = $("#annotation-start-time").text();
var a = val.split(":");
var seconds = +a[0] * 60 * 60 + +a[1] * 60 + +a[2];
player1.seekTo(seconds);
}
function setAnnotationWindow(
startTime,
endTime,
tags,
description,
isPrivate,
ID,
userID,
userName,
videoAnnotationID
) {
description = $.trim(description);
var saveButton =
'<a href="#" id="save_annotation" class="dialog-buttons" target="_self" onClick="saveAnnotation();">Save</a>';
var cancelButton =
'<a href="#" id="cancel_annotation" class="dialog-buttons" target="_self" onClick="closeAnnotationDialog();">Close</a>';
var editButton =
'<a href="#" id="edit_annotation" class="dialog-buttons" target="_self" onClick="updateAnnotation(' +
ID +
');" >Update</a>';
var deleteButton =
'<a class="dialog-buttons" href="javascript:confirmDelete()" >Delete</a>';
var playButton =
'<a href="#" id="play_annotation" class="dialog-buttons" target="_self" onClick="playerSee();"; >Play</a>';
setAnnotationFormValues(tags, description, isPrivate);
showAnnotationForm();
$("#webcam").css("display", "none"); // WEBCAM ANNOTATION:
$("#annotation-form select").removeAttr("disabled");
$("#annotation-form select").val("annotation").attr("selected", true);
annotationMode ? (list = annotations) : (list = comments);
var html;
if (annotationMode) {
$(".annotation-label > #annotation-type")
.parent()
.css("display", "inline-block");
if (newAnnotation()) {
html = "<br /><br />" + saveButton + cancelButton;
$("#annotation-title").html("Add Annotation");
var startTime = getCurrentYouTime();
openAnnotationIndex = null;
setFormWritable();
editStartTime(false);
videoAnnotationEntryID = null;
} else {
// pre-existing annotation
if (isVideoAnnotation(videoAnnotationID)) {
$("#annotation-form select").val("video").attr("selected", true);
videoAnnotationEntryID = videoAnnotationID;
showPlayer(videoAnnotationID);
} else {
$("#annotation-form select").val("annotation").attr("selected", true);
}
// annotation mode readonly for editing
$("#annotation-form select").attr("disabled", "disabled");
if ("true" == list[openAnnotationIndex].myAnnotation) {
// annotation authored by user
html =
"<br /><br />" +
playButton +
editButton +
deleteButton +
cancelButton;
if (annotationMode) $(".controls img").css("display", "inline-block");
setFormWritable();
editStartTime(true);
$("#annotation-title").html("Edit Annotation (" + userName + ")");
} else {
// annotation NOT authored by user
html = "<br /><br />" + playButton + cancelButton;
setFormReadonly();
editStartTime(false);
$("#annotation-title").html("View Annotation (" + userName + ")");
}
startTimeSeekPosition = 0;
}
} else {
// this is a comment
$(".annotation-label > #annotation-type").parent().css("display", "none");
$("#start-time-rwd, #start-time-fwd, #annotation-start-time").css(
"display",
"none"
);
if (newAnnotation()) {
$("#annotation-title").html("Add Comment");
setFormWritable();
// new comment
html = "<br /><br />" + saveButton + cancelButton;
// feedback form with points will display after submit the general comments form.
} else {
// pre-existing comment
debug("openAnnotationIndex: " + openAnnotationIndex);
if ("true" == list[openAnnotationIndex].myAnnotation) {
// comment authored by user
$("#annotation-title").html("Edit Comment");
setFormWritable(false);
html = "<br /><br />" + editButton + deleteButton + cancelButton;
// feedback form with points will display after the user update the general comments form.
} else {
// authored by others
$("#annotation-title").html("View Comment");
setFormReadonly();
html = "<br /><br />" + cancelButton;
}
}
}
setDialogStartTime(startTime);
annotationDialogOpen = true;
$("#form-buttons").html(html);
}
function setFeedbackWindow(
startTime,
endTime,
tags,
description,
isPrivate,
ID,
userID,
userName,
videoAnnotationID
) {
description = $.trim(description);
var saveButton =
'<a href="#" id="save_annotation" class="dialog-buttons" target="_self" onClick="saveAnnotation();">Save</a>';
var cancelButton =
'<a href="#" id="cancel_annotation" class="dialog-buttons" target="_self" onClick="closeAnnotationDialog();">Close</a>';
var editButton =
'<a href="#" id="edit_annotation" class="dialog-buttons" target="_self" onClick="updateAnnotation(' +
ID +
');" >Update</a>';
var deleteButton =
'<a class="dialog-buttons" href="javascript:confirmDelete()" >Delete</a>';
var playButton =
'<a href="#" id="play_annotation" class="dialog-buttons" target="_self" onClick="playerSeek();"; >Play</a>';
setFeedbackFormValues(tags, description, isPrivate);
showFeedbackForm();
$("#webcam").css("display", "none"); // WEBCAM ANNOTATION:
$("#annotation-form1 select").removeAttr("disabled");
$("#annotation-form1 select").val("annotation").attr("selected", true);
$("#annotation-tags").css("display", "none");
$("#annotation-description").css("display", "none");
var html;
// this is a comment
$(".annotation-label > #annotation-type").parent().css("display", "none");
$("#start-time-rwd, #start-time-fwd, #annotation-start-time").css(
"display",
"none"
);
$(".annotation-label").css("display", "none");
// if (newAnnotation()) {
$("#annotation-title").html("Feedback");
$(".annotation-label").html("Is this video talked about unisa");
//setFormWritable();
// new comment
html = "<br /><br />" + saveButton + cancelButton;
// }
// else {
// pre-existing comment
// debug("openAnnotationIndex: " + openAnnotationIndex);
// if ("true" == list[openAnnotationIndex].myAnnotation) {
// comment authored by user
// $('#annotation-title').html("Edit Comment");
// setFormWritable(false);
// html = "<br /><br />" + editButton + deleteButton + cancelButton;
// } else {
// authored by others
// $('#annotation-title').html("View Comment");
// setFormReadonly();
// html = "<br /><br />" + cancelButton;
// }
// }
setDialogStartTime(startTime);
annotationDialogOpen = true;
$("#form-buttons").html(html);
}
function editStartTime(display) {
var rule;
display ? (rule = "inline-block") : (rule = "none");
$("#annotation-start-time").css("display", "inline-block");
$("#start-time-rwd, #start-time-fwd").css("display", rule);
}
function setFormWritable() {
$("#annotation-description").removeAttr("readonly");
$("#annotation-tags").removeAttr("readonly");
$("#annotation-privacy").removeAttr("readonly");
$("#annotation-privacy").css("display", "inline-block");
$("#annotation-privacy").parent().css("display", "inline-block");
}
function setFormReadonly() {
$("#start-time-rwd, #start-time-fwd, #annotation-start-time").css(
"display",
"none"
);
$("#annotation-description").attr("readonly", "readonly");
$("#annotation-tags").attr("readonly", "readonly");
$("#annotation-privacy").attr("readonly", "readonly");
$("#annotation-privacy").css("display", "none");
$("#annotation-privacy").parent().css("display", "none");
}
function setDialogStartTime(startTime) {
var startTimeDisplay = formatISO(startTime);
$("#annotation-start-time").html(startTimeDisplay);
}
function formatISO(seconds) {
var hours = parseInt(seconds / (60 * 60));
var rest = parseInt(seconds % (60 * 60));
var minutes = parseInt(rest / 60);
rest = parseInt(rest % 60);
var seconds = parseInt(rest);
var millis = parseInt(rest);
return (
doubleDigits(hours) +
":" +
doubleDigits(minutes) +
":" +
doubleDigits(seconds)
);
}
function doubleDigits(value) {
if (value > 9) {
return value;
} else {
return "0" + value;
}
}
function fadeOutComments(fade) {
fade ? (opacity = "0.4") : (opacity = "1.0");
$("#comments").css("opacity", opacity);
}
function fadeOutFeedbacks(fade) {
fade ? (opacity = "0.4") : (opacity = "1.0");
$("#feedbacks").css("opacity", opacity);
}
function showAnnotationWindow() {
fadeOutComments(true);
ATTENTIONAL_DELAY = 3;
if (annotationChanged()) {
// exit
alertAnnotationChanged();
return;
} else {
createAnnotationStartTime = Math.floor(getCurrentYouTime());
createAnnotationStartTimeWDelay =
createAnnotationStartTime > ATTENTIONAL_DELAY
? createAnnotationStartTime - ATTENTIONAL_DELAY
: createAnnotationStartTime;
if (annotationMode) {
// iterate through to check if annotation already exists for given time
for (i = 0; i < annotations.length; i++) {
var myAnnotation = annotations[i].myAnnotation;
var startTime = annotations[i].startTime;
if (
"true" == myAnnotation &&
startTime == createAnnotationStartTimeWDelay &&
annotationMode
) {
alert(
"You already have an annotation at " +
createAnnotationStartTimeWDelay +
" seconds.\n" +
"You can update or delete the current annotation."
);
fadeOutComments(false);
return;
}
}
}
openAnnotationIndex = null;
setAnnotationWindow(null, null, null, null, null, null, null, null);
annotationDialogOpen = true;
if (annotationMode) {
// TODO: look at UI configurations before auto-closing annotation
// saveAnnotation();
}
}
}
function showFeedbackWindow() {
if (!annotationMode) {
fadeOutComments(true);
showFeedbackForm();
//setFeedbackWindow(null, null, null, null, null, null, null, null);
}
}
function setAnnotationFormValues(tags, description, isPrivate) {
var description = $.trim(description);
$("#annotation-tags").val(tags);
$("#annotation-description").val(description);
if (parseInt(isPrivate)) {
$("#annotation-privacy").attr("checked", "checked");
} else {
$("#annotation-privacy").removeAttr("checked");
}
}
function setFeedbackFormValues(tags, description, isPrivate) {
tags = "Is this video talked about UniSA?";
description = null;
}
function showAnnotation(ID, annotationView) {
if (annotationChanged()) {
alertAnnotationChanged();
return;
}
var found = false;
var list;
annotationView ? (list = annotations) : (list = comments);
for (i = 0; i < list.length; i++) {
if (ID == list[i].id) {
var startTime = list[i].startTime;
var endTime = list[i].endTime;
var tags = list[i].tags;
var description = list[i].description;
var userID = list[i].userID;
var userName = list[i].userName;
var isPrivate = list[i].isPrivate;
dialogAnnotationStartTime = list[i].startTime;
dialogAnnotationEndTime = list[i].endTime;
openAnnotationIndex = i;
setAnnotationWindow(
startTime,
endTime,
tags,
description,
isPrivate,
list[i].id,
userID,
userName,
list[i].videoAnnotationID
);
found = true;
}
}
if (!found) alert("error - ID:" + ID + " not found");
}
function alertAnnotationChanged() {
if (newAnnotation()) {
var cancelButton =
'<a href="#" id="cancel_annotation" class="dialog-buttons" target="_self" onClick="closeAnnotationDialog(' +
CONFIRMED +
');">close</a>';
var editButton =
'<a href="#" id="edit_annotation" style="padding:0px" class="dialog-buttons" target="_self" onClick="saveAnnotation();" >save</a>';
} else {
// pre-existing annotation
ID = annotations[openAnnotationIndex].id;
var editButton =
'<a href="#" id="edit_annotation" class="dialog-buttons" target="_self" onClick="updateAnnotation(' +
ID +
');" >save</a>';
}
annotationMode ? (type = "annotation") : (type = "comment");
var cancelButton =
'<a href="#" id="cancel_annotation" style="padding:0px" class="dialog-buttons" target="_self" onClick="closeAnnotationDialog(' +
CONFIRMED +
');">discard</a>';
if (isVideoAnnotation()) {
if (webcamRecordingSaved()) {
msg =
"To keep your recording please " +
editButton +
" this annotation. Or you may " +
cancelButton +
" this annotation.";
} else {
msg =
"Please record and save your webcam video. Or " +
cancelButton +
" this annotation.";
}
} else {
msg =
"You have modified the " +
type +
". Please " +
editButton +
" or " +
cancelButton +
" changes.";
}
$("#message-dialog").html(msg);
$("#message-dialog").dialog();
$("#message-dialog").dialog({ resizable: false });
}
function alertFeedbackChanged() {
msg = "points ...";
$("#message-dialog").html(msg);
$("#message-dialog").dialog();
$("#message-dialog").dialog({ resizable: false });
}
function newAnnotation() {
// new annotations do not have an array index (whereas pre-existing annotations do)
return null == openAnnotationIndex;
}
function annotationDialogClosed() {
return !annotationDialogOpen;
}
function webcamRecordingSaved() {
var currentStatus = $("#webcam iframe")
.contents()
.find("#currentStatus")
.text();
// recording started and/or stoped but not saved
if (-1 != currentStatus.indexOf("recording")) {
return true;
}
return "video saved." == currentStatus;
}
function annotationChanged() {
// no annotation is open
if (annotationDialogClosed()) return false;
if (newAnnotation()) {
if (isVideoAnnotation()) {
if (webcamRecordingSaved()) {
debug("webcam recording saved");
return true;
} else {
debug("webcam recording NOT saved");
//TODO: WEBCAM: prompt user that they have not made a recording
return true;
}
}
if (
"" != $.trim($("#annotation-tags").val()) ||
"" != $.trim($("#annotation-description").val())
) {
return true;
}
} else {
annotationMode ? (list = annotations) : (list = comments);
if (undefined != openAnnotationIndex) {
debug("index: " + openAnnotationIndex);
if (
$("#annotation-tags").val() != list[openAnnotationIndex].tags ||
$("#annotation-description").val() !=
list[openAnnotationIndex].description ||
annotationTimeModified
) {
return true;
}
}
}
return false;
}
function closeAnnotationDialog(msg) {
debug("in closeAnnotationDialog()");
fadeOutComments(false);
// if user has not already interacted with message dialog
if (CONFIRMED != msg) {
debug("closeAnnotationDialog() - not confirmed " + msg);
// you don't have confirmation to close dialog
if (annotationChanged()) {
alertAnnotationChanged();
return;
}
} else {
debug("closeAnnotationDialog() - confirmed " + msg);
}
$("#recording-annotation").css("display", "none");
$("#annotation-form").css("display", "none");
annotationDialogOpen = false;
closeMessageDialog();
annotationMode ? (list = annotations) : (list = comments);
if (!newAnnotation()) {
// set back annotation start and end time
list[openAnnotationIndex].startTime = dialogAnnotationStartTime;
list[openAnnotationIndex].endTime = dialogAnnotationEndTime;
// this will only be triggered if annotation is not being saved therefore
// annotation needs to be set back to it's original position
if (annotationTimeModified)
setAnnotationPosition(dialogAnnotationStartTime);
}
// at this point user has chosen to save or cancel update
annotationTimeModified = false;
videoAnnotationEntryID = null;
openAnnotationIndex = null;
}
function closeAnnotationDialog1(msg) {
debug("in closeAnnotationDialog1()");
fadeOutComments(false);
// if user has not already interacted with message dialog
if (CONFIRMED != msg) {
debug("closeAnnotationDialog1() - not confirmed " + msg);
// you don't have confirmation to close dialog
if (annotationChanged()) {
alertAnnotationChanged();
return;
}
} else {
debug("closeAnnotationDialog1() - confirmed " + msg);
}
$("#recording-annotation").css("display", "none");
$("#annotation-form1").css("display", "none");
annotationDialogOpen = false;
closeMessageDialog();
annotationMode ? (list = annotations) : (list = comments);
if (!newAnnotation()) {
// set back annotation start and end time
list[openAnnotationIndex].startTime = dialogAnnotationStartTime;
list[openAnnotationIndex].endTime = dialogAnnotationEndTime;
// this will only be triggered if annotation is not being saved therefore
// annotation needs to be set back to it's original position
if (annotationTimeModified)
setAnnotationPosition(dialogAnnotationStartTime);
}
// at this point user has chosen to save or cancel update
annotationTimeModified = false;
videoAnnotationEntryID = null;
openAnnotationIndex = null;
}
function closeMessageDialog() {
if ($("#message-dialog").dialog("isOpen"))
$("#message-dialog").dialog("close");
// rewrite cancel button
if (isVideoAnnotation()) {
$("#cancel_annotation").attr("onClick", "closeAnnotationDialog()");
} else {
$("#cancel_annotation").attr(
"onClick",
"closeAnnotationDialog(" + CONFIRMED + ")"
);
}
}
function generateTrendline() {
var trendline = [];
annotationsCopy = getAnnotationsCopy();
// initialize array
for (i = 0; i < sliderWidth; i++) trendline[i] = 0;
var largest = 0;
for (i = 0; i < annotationsCopy.length; i++) {
startingPosition = Math.floor(
(annotationsCopy[i].startTime / mediaDuration) * sliderWidth
);
// should this be same width as flag?
endPosition = startingPosition + 3;
for (j = startingPosition; j < endPosition; j++) {
trendline[j] = trendline[j] + 1;
if (trendline[j] > largest) {
largest = trendline[j];
}
}
}
//get largest value and scale trendline accordingly
var trendlineCSS = new String();
for (i = 0; i < sliderWidth; i++) {
var scaleFactor = Math.floor(255 / largest);
// calculate red intensity of RGB
var red = (trendline[i] * scaleFactor).toString(16);
if (1 == red.length) red = "0" + red;
var color = "#" + red + "0000";
// TODO: group contiguous numbers into one div
// quick and dirty method until then
trendlineCSS =
trendlineCSS +
'<div style="margin:0;padding:0;float:left;width:1px;height:25px;background-color:' +
color +
';"></div>';
}
return trendlineCSS;
}
/*
* this function is used to encapsulate the annotation object
*/
function Annotation(
ID,
startTime,
endTime,
tags,
description,
description_with_html,
myAnnotation,
userID,
userName,
isPrivate,
videoAnnotationID,
viewMode,
creationDate
) {
this.id = ID;
this.startTime = Math.floor(startTime);
this.endTime = Math.floor(endTime);
this.tags = tags;
this.description = description;
this.description_with_html = description_with_html;
this.myAnnotation = myAnnotation;
this.userID = userID;
this.userName = userName;
this.isPrivate = isPrivate;
this.videoAnnotationID = videoAnnotationID;
this.viewMode = viewMode;
this.creationDate = creationDate;
}
function getAnnotationList(viewMode) {
//debug('in getAnnotationlist()');
var list = "";
var tmpList = [];
$.ajax({
type: "GET",
url: "ajax/get_annotations.php",
data: {
video_id: videoID,
annotation_mode: annotationMode,
view_mode: viewMode,
},
dataType: "json",
beforeSend: function (jqXHR, settings) {},
success: function (data) {
$.each(data, function (i, item) {
if (null == item.start_time) {
// General comments have a null start_time (as they are not time specific)
comments.push(
new Annotation(
item.annotation_id,
item.start_time,
item.end_time,
item.tags,
item.description,
item.description_with_html,
item.my_annotation,
item.user_id,
item.user_name,
item.is_private,
item.video_annotation_id,
viewMode,
item.creation_date
)
);
} else {
// all other annotations have a specific start time
annotations.push(
new Annotation(
item.annotation_id,
item.start_time,
item.end_time,
item.tags,
item.description,
item.description_with_html,
item.my_annotation,
item.user_id,
item.user_name,
item.is_private,
item.video_annotation_id,
viewMode
)
);
// clone annotations
//debug(item.annotation_id + " " + item.start_time + " " + item.end_time);
tmpList.push(
new Annotation(
item.annotation_id,
item.start_time,
item.end_time,
item.tags,
item.description,
item.description_with_html,
item.my_annotation,
item.user_id,
item.user_name,
item.is_private,
item.video_annotation_id,
viewMode
)
);
}
});
list = compactList(tmpList, viewMode);
},
error: function (request, status, error) {
debug(
"request.status: " +
request.status +
" error " +
error +
"<error>" +
request.responseText +
"</error>"
);
},
async: false,
});
if (null != list) {
list = list.toString();
} else {
list = "";
}
debug("list " + list);
return list;
}
function getFeedback() {}
var LIST_ITEM_BORDER_LEFT_BIG = 11;
var LIST_ITEM_BORDER_LEFT_MEDIUM = 7;
var LIST_ITEM_BORDER_LEFT_SMALL = 5;
function formatListItem(ID, startTime, myAnnotation, viewMode, hasData) {
var startingPosition = getStartPosition(startTime);
var width = 10; // used to be 7
var height = 1; // used to be default, let's make these arrows bigger to test how they look, then change to another color.
var style =
"margin:0;padding:0;z-index:1;position:absolute;width:" +
width +
"px;height:" +
height +
"px;left:" +
startingPosition +
"px;border-bottom:6px solid transparent;border-top:6px solid transparent;";
style +=
"border-left:" +
LIST_ITEM_BORDER_LEFT_MEDIUM +
"px solid " +
getAnnotationColor(viewMode) +
";";
return (
'<div id="' +
ID +
'" class="annotation-list-item" style="' +
style +
'"></div>'
);
}
function getAnnotationColor(viewMode) {
var color;
if (MINE == viewMode) {
color = "#58a0dc"; // BLUE
} else if (INSTRUCTORS_AND_TAS == viewMode) {
color = "#000000"; // BLACK // "#58b947"; // color blindness: green conflicts with orange/red for protanopia and deuteranopia and conflicts with blue for tritanopia.
} else {
color = "#ff6b00"; // ORANGE
}
return color;
}
function getStartPosition(startTime) {
// alert("The value of mediaDuration is: " + mediaDuration);
return Math.floor((startTime / mediaDuration) * sliderWidth);
}
function newWindowPrint(someText) {
var newWin = window.open("", "", "width=640,height=480");
newWin.document.writeln(someText);
}
function compactList(listCopy, viewMode) {
// if no annotations there's nothing to do
if (0 == listCopy.length) return null;
// for display purposes give flags an end time that will work out to 7px (the width of the flag icon)
var flagWidth = 10; // used to be 7
var duration = (flagWidth / sliderWidth) * mediaDuration;
// debug("duration: " + duration + "\nflagWidth: " + flagWidth + "\nsliderWidth: " + sliderWidth + "\ngetDuration(): " + duration);
for (i = 0; i < listCopy.length; i++) {
listCopy[i].endTime = listCopy[i].startTime + duration;
}
var itemsToDelete = [];
hasData = annotationHasData(listCopy[0].tags, listCopy[0].description);
var list =
"<li>" +
formatListItem(
listCopy[0].id,
listCopy[0].startTime,
listCopy[0].myAnnotation,
viewMode,
hasData
) +
"";
var currentEnd = Math.floor(listCopy[0].endTime);
listCopy.splice(0, 1);
while (listCopy.length > 0) {
for (i = 0; i < listCopy.length; i++) {
if (currentEnd <= Math.floor(listCopy[i].startTime)) {
// these annotations do not overlap so they can go on the same line
hasData = annotationHasData(listCopy[i].tags, listCopy[i].description);
list =
list +
formatListItem(
listCopy[i].id,
listCopy[i].startTime,
listCopy[i].myAnnotation,
viewMode,
hasData
) +
"";
currentEnd = Math.floor(listCopy[i].endTime);
// we're done with [i] so splice it out
itemsToDelete.push(i);
}
}
while (itemsToDelete.length > 0) {
listCopy.splice(itemsToDelete.pop(), 1);
}
list = list + "</li>";
if (listCopy.length > 0) {
currentEnd = 0;
list = list + "<li>";