This repository was archived by the owner on Feb 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimeline.js
3226 lines (2729 loc) · 146 KB
/
timeline.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
/* Tag */
//Use this global variable to keep track of event label whenever showMap() is called
var savedNewContent;
var sameTag = undefined;
CSAVTimelineTag = function(params) {
var requiredFieldNames = ["timeline", "name"];
for (var idx = 0; idx < requiredFieldNames.length; idx++) {
if (params[requiredFieldNames[idx]] !== undefined)
this[requiredFieldNames[idx]] = params[requiredFieldNames[idx]];
else
throw "CSAVTimelineTag: Parameter \"" + requiredFieldNames[idx] + "\" is required."
}
var optionalFieldNames = ["id", "color", "level"];
for (var idx = 0; idx < optionalFieldNames.length; idx++) {
this[optionalFieldNames[idx]] = params[optionalFieldNames[idx]];
}
}
CSAVTimelineTag.prototype.getId = function() {
return this.id;
}
CSAVTimelineTag.prototype.getTimeline = function() {
return this.timeline;
}
CSAVTimelineTag.prototype.getName = function() {
return this.name;
}
CSAVTimelineTag.prototype.getColor = function() {
return this.color;
}
CSAVTimelineTag.prototype.getLevel = function () {
return this.level;
}
CSAVTimelineTag.prototype.setId = function(id) {
this.id = id;
}
CSAVTimelineTag.prototype.setName = function(name) {
this.name = name;
}
CSAVTimelineTag.prototype.setColor = function(color) {
this.color = color;
}
CSAVTimelineTag.prototype.setLevel = function(level) {
this.level = level;
}
/* Event */
CSAVTimelineEvent = function(params) {
var requiredFieldNames = ["tag", "startTime", "endTime"];
for (var idx = 0; idx < requiredFieldNames.length; idx++) {
if (params[requiredFieldNames[idx]] !== undefined)
this[requiredFieldNames[idx]] = params[requiredFieldNames[idx]];
else
throw "CSAVTimelineEvent: Parameter \"" + requiredFieldNames[idx] + "\" is required."
}
var optionalFieldNames = ["id", "comment", "latitude", "longitude", "scope","level"];
for (var idx = 0; idx < optionalFieldNames.length; idx++) {
this[optionalFieldNames[idx]] = params[optionalFieldNames[idx]];
}
}
CSAVTimelineEvent.prototype.deepCopy = function() {
var event = this;
return new CSAVTimelineEvent({
id: event.id,
tag: event.tag,
startTime: event.startTime,
endTime: event.endTime,
comment: event.comment,
latitude: event.latitude,
longitude: event.longitude,
scope: event.scope,
level: event.level
});
}
CSAVTimelineEvent.prototype.setId = function(id) {
this.id = id;
}
CSAVTimelineEvent.prototype.getId = function() {
return this.id;
}
CSAVTimelineEvent.prototype.getTag = function() {
return this.tag;
}
CSAVTimelineEvent.prototype.setTag = function(tag) {
this.tag = tag;
}
CSAVTimelineEvent.prototype.setStartTime = function(startTime) {
this.startTime = startTime
}
CSAVTimelineEvent.prototype.getStartTime = function() {
return this.startTime;
}
CSAVTimelineEvent.prototype.setEndTime = function(endTime) {
this.endTime = endTime;
}
CSAVTimelineEvent.prototype.getEndTime = function() {
return this.endTime;
}
CSAVTimelineEvent.prototype.setComment = function(comment) {
this.comment = comment;
}
CSAVTimelineEvent.prototype.getComment = function() {
return this.comment;
}
CSAVTimelineEvent.prototype.setLat = function(latitude) {
this.latitude = latitude;
}
CSAVTimelineEvent.prototype.getLat = function() {
return this.latitude;
}
CSAVTimelineEvent.prototype.setLng = function(longitude) {
this.longitude = longitude;
}
CSAVTimelineEvent.prototype.getScope = function() {
return this.scope;
}
CSAVTimelineEvent.prototype.setScope = function(scope) {
this.scope = scope;
}
CSAVTimelineEvent.prototype.getLng = function() {
return this.longitude;
}
CSAVTimelineEvent.prototype.getLevel = function () {
return this.level;
}
CSAVTimelineEvent.prototype.setLevel = function (level) {
this.level = level;
}
CSAVTimeline = function(params) {
var requiredFieldNames = ["id",
"minorMarkerInterval", "majorMarkerInterval", "minTime", "maxTime", "selector", "zoomFactor", "clipId", "readOnly", "streamUpdate", "readOnlyGroup"];
for (var idx = 0; idx < requiredFieldNames.length; idx++) {
if (params[requiredFieldNames[idx]] !== undefined)
this[requiredFieldNames[idx]] = params[requiredFieldNames[idx]];
else
throw "CSAVTimeline: Parameter \"" + requiredFieldNames[idx] + "\" is required."
}
var optionalFieldNames = ["userId", "groupId"];
for (var idx = 0; idx < optionalFieldNames.length; idx++) {
this[optionalFieldNames[idx]] = params[optionalFieldNames[idx]];
}
// Some of the parameters need to be of the Number type
var numberFieldNames = ["minorMarkerInterval", "majorMarkerInterval", "minTime", "maxTime", "zoomFactor", "clipId"];
for (var idx = 0; idx < numberFieldNames.length; idx++) {
var num = Number(params[numberFieldNames[idx]]);
if (!isNaN(num))
this[numberFieldNames[idx]] = num;
else
throw "CSAVTimeline: Parameter \"" + requiredFieldNames[idx] + "\" must be a number."
}
// Initialize
this.listeners = {};
this.recordingEvents = {};
this.tagDialogOpen = {};
this.eventDialogOpen = {};
var timeline = this;
// Add back tags and events
this.tags = [];
this.events = [];
this.fetchDataXHR = undefined;
this.fetchDataTimestamp = 0;
this.redraw();
this.fetchData();
if (typeof this.streamUpdate != "undefined" && this.streamUpdate > 0) {
this.fetchDataInterval = setInterval(function() {
if (typeof timeline.fetchDataXHR == "undefined")
timeline.fetchData();
}, this.streamUpdate);
}
// SSC-1176
// Adding an array to keep track of the last tag or event adds or deletions.
this.lastChanges = [];
// SSC-1191: Detect if the clip has changed
this.clipModified = undefined;
// SSC-1157
// Apparently the width of the event bands changes during initialization (don't know why though)
// so we should redraw with the updated width in mind
delete timeline.noRedraw.marker;
this.redraw();
}
CSAVTimeline.prototype.fetchData = function() {
var timeline = this;
//SSC-1191: Detect changes to the clip
var clipData = {
"c1_command": "getclipdata",
"c1_clipid": this.clipId,
"c1_timeout": 0
}
this.fetchDataXHR = false;
this.fetchDataXHR = jQuery.ajax({
type: "POST",
url: "database.php",
data: clipData,
dataType: "json",
async: true,
success: function(jsonData, textStatus) {
if (!jsonData instanceof Array)
throw "CSAVTimelineTag.prototype.save: Remote host returned an error message: " + jsonData["message"];
if (typeof jsonData == "undefined" || jsonData == null)
throw "CSAVTimelineTag.prototype.save: jsonData not defined";
if (typeof jsonData[0] == "undefined")
throw "CSAVTimelineTag.prototype.save: jsonData[0] not defined";
if (jsonData[0]["success"] !== true)
throw "CSAVTimelineTag.prototype.save: Remote host returned an error message: " + jsonData[0]["message"];
var timemodified = jsonData[0]["data"][0].timemodified;
if (timeline.clipModified == undefined) {
timeline.clipModified = timemodified;
return;
}
if (timeline.clipModified !== timemodified) {
timeline.sendMessage(timeline, "clipChanged", timemodified);
timeline.clipModified = timemodified;
}
},
complete: function(jqXHR, textStatus) {
timeline.fetchDataXHR = undefined;
}
});
var data = {
"c1_command": "gettagsevents",
"c1_clipid": this.clipId,
"c1_timestamp": this.fetchDataTimestamp,
"c1_timeout": 0
}
if (this.userId) data["c1_userid"] = this.userId;
if (this.groupId) data["c1_groupid"] = this.groupId;
var tagids = '';
for (var idx in this.tags) {
if (tagids != '')
tagids += ',';
tagids += this.tags[idx].getId();
}
data["c1_tags"] = tagids;
var eventids = '';
for (var idx in this.events) {
if (eventids != '')
eventids += ',';
eventids += this.events[idx].getId();
}
data["c1_events"] = eventids;
this.fetchDataXHR = false;
this.fetchDataXHR = jQuery.ajax({
type: "POST",
url: "database.php",
data: data,
dataType: "json",
async: true,
success: function(jsonData, textStatus) {
if (!jsonData instanceof Array)
throw "CSAVTimelineTag.prototype.save: Remote host returned an error message: " + jsonData["message"];
if (typeof jsonData == "undefined" || jsonData == null)
throw "CSAVTimelineTag.prototype.save: jsonData not defined";
if (typeof jsonData[0] == "undefined")
throw "CSAVTimelineTag.prototype.save: jsonData[0] not defined";
if (jsonData[0]["success"] !== true)
throw "CSAVTimelineTag.prototype.save: Remote host returned an error message: " + jsonData[0]["message"];
timeline.fetchDataTimestamp = jsonData[0]["timestamp"];
var changed = false;
for (var idx in jsonData[0]["tags"]) {
var tagData = jsonData[0]["tags"][idx];
var tagObj = timeline.findTag(Number(tagData.id));
if (tagObj)
timeline.editTag(Number(tagData["id"]), undefined, undefined, tagData["name"], tagData["color"], false, Number(tagData["level"]));
else
timeline.addTag(Number(tagData["id"]), tagData["name"], tagData["color"], false, Number(tagData["level"]));
changed = true;
}
for (var idx in jsonData[0]["events"]) {
var eventData = jsonData[0]["events"][idx];
var eventObj = timeline.findEvent(Number(eventData.id));
if (eventObj)
{
if (eventData["latitude"] && eventData["longitude"])
{
timeline.editEvent(Number(eventData["id"]), undefined, undefined, undefined, Number(eventData["starttime"]), Number(eventData["endtime"]), eventData["content"], false, Number(eventData["latitude"]), Number(eventData["longitude"]), eventData["scope"], Number(eventData["level"]));
}
else
{
timeline.editEvent(Number(eventData["id"]), undefined, undefined, undefined, Number(eventData["starttime"]), Number(eventData["endtime"]), eventData["content"], false, undefined, undefined, undefined, Number(eventData["level"]));
}
}
else
{
if (eventData["latitude"] && eventData["longitude"])
{
timeline.addEvent(Number(eventData["id"]), Number(eventData["tagid"]), Number(eventData["starttime"]), Number(eventData["endtime"]), eventData["content"], false, Number(eventData["latitude"]), Number(eventData["longitude"]), eventData["scope"], Number(eventData["level"]));
}
else
{
timeline.addEvent(Number(eventData["id"]), Number(eventData["tagid"]), Number(eventData["starttime"]), Number(eventData["endtime"]), eventData["content"], false, undefined, undefined, undefined, Number(eventData["level"]));
}
}
changed = true;
}
for (var idx in jsonData[0]["deletedevents"]) {
var eventId = jsonData[0]["deletedevents"][idx];
var tagId = timeline.findEvent(Number(eventId)).getTag().getId();
timeline.removeEvent(eventId, false);
if (!(typeof timeline.editEventDialogOpen === "undefined"))
delete timeline.editEventDialogOpen[tagId];
jQuery('#EventBar_Event' + eventId + '_Timeline' + timeline.id).remove();
changed = true;
}
for (var idx in jsonData[0]["deletedtags"]) {
var tagId = jsonData[0]["deletedtags"][idx];
timeline.removeTag(tagId, false);
if (!(typeof timeline.editTagDialogOpen === "undefined"))
delete timeline.editTagDialogOpen[tagId];
jQuery('#TagEventBand_Tag' + tagId + '_Timeline' + timeline.id).remove();
changed = true;
}
if (changed)
timeline.redraw(true);
if (typeof jsonData[0]["onlineusers"] != "undefined")
timeline.sendMessage(timeline, "onlineUsersUpdated", jsonData[0]["onlineusers"]);
},
complete: function(jqXHR, textStatus) {
timeline.fetchDataXHR = undefined;
}
});
}
CSAVTimeline.prototype.handleError = function(err) {
if (typeof err.errortype != "undefined") {
switch (err.errortype) {
case "writeconflict":
alert("FinishGroupModeASAPErrorMessage: " + err.message);
break;
default:
alert("error: " + err.message);
}
} else {
alert("error: " + err.message);
}
}
CSAVTimeline.prototype.inArray = function(needle, haystack, comparator) {
for (var key in haystack) {
if (comparator(needle, haystack[key]))
return key;
}
return undefined;
}
CSAVTimeline.prototype.redraw = function(forceRedraw) {
var timeline = this;
// Create the timeline base if it doesn't exist
if (typeof this.noRedraw === 'undefined' || !this.noRedraw) {
jQuery('#TimelineBase_Timeline' + this.id).remove();
var str = '';
str += '<div id="TimelineBase_Timeline' + this.id + '" class="TimelineBase">';
str += " <div id='LeftMarker_Timeline" + this.id + "' class='LeftMarker'></div>";
str += " <div id='RightMarker_Timeline" + this.id + "' class='RightMarker'></div>";
str += " <div id='CurrentTimeBar_Timeline" + this.id + "' class='CurrentTimeBar'></div>";
str += ' <div id="TimeMarkerDigitPanel_Timeline' + this.id + '" class="TimeMarkerDigitPanel">';
str += ' <table border=0 width="100%">';
str += ' <tr valign="top">';
str += ' <td id="TimeMarkerDigitPanel1_Timeline' + this.id + '" class="TimeMarkerDigitPanel1">';
str += ' <button id="AddTagButton_Timeline' + this.id + '" class="AddTagButton" type="submit" title="Click to add a tag">Add Tag</button>';
str += ' <button id="BulkModeOnButton_Timeline' + this.id + '" class="BulkModeOnButton" title="Enable selecting multiple tags">Bulk Mode On</button>';
str += ' <button id="BulkModeOffButton_Timeline' + this.id + '" class="BulkModeOffButton" title="Disable selecting multiple tags">Bulk Mode Off</button>';
str += '<br>';
str += ' <a href="#" id="SelectAllButton_Timeline' + this.id + '" class="SelectAllButton" title="Select all tags">all</a>';
str += ' <a href="#" id="SelectNoneButton_Timeline' + this.id + '" class="SelectNoneButton" title="Unselect all tags">none</a>';
str += ' <a href="#" id="BulkStartButton_Timeline' + this.id + '" class="BulkStartButton" title="Start recording for the selected tags">start</a>';
str += ' <a href="#" id="BulkStopButton_Timeline' + this.id + '" class="BulkStopButton" title="Stop recording for the selected tags">stop</a>';
str += ' </td>';
str += ' <td id="TimeMarkerDigitPanel2_Timeline' + this.id + '" class="TimeMarkerDigitPanel2">';
str += ' </td>';
str += ' </tr>';
str += ' </table>';
str += ' </div>';
str += ' <div id="AddTagBand_Timeline' + this.id + '" class="AddTagBand">';
str += ' <input id="ZoomInButton_Timeline' + this.id + '" class="ZoomInButton" type="image" border=0 src="images/zoomin.png" title="Zoom in"/>';
str += ' <input id="ZoomOutButton_Timeline' + this.id + '" class="ZoomOutButton" type="image" border=0 src="images/zoomout.png" title="Zoom out"/>';
str += ' </div>';
str += " <div id='CurrentTimeBarHandle_Timeline" + this.id + "' class='CurrentTimeBarHandle'></div>";
str += ' <div id="TimeMarkerPanel_Timeline' + this.id + '" class="TimeMarkerPanel"></div>';
str += '</div>';
jQuery(this.selector).append(str);
jQuery('#TimelineBase_Timeline' + this.id).append('<div id="test"></div>');
// Bulk Mode On button turns bulk mode on
jQuery('#BulkModeOnButton_Timeline' + this.id).click(function(event) {
event.preventDefault();
event.stopPropagation();
timeline.bulkMode = true;
timeline.redraw();
return false;
});
// Bulk Mode Off button turns bulk mode off
jQuery('#BulkModeOffButton_Timeline' + this.id).click(function(event) {
event.preventDefault();
event.stopPropagation();
timeline.bulkMode = false;
timeline.redraw();
return false;
});
// Select All button checks all checkboxes
jQuery('#SelectAllButton_Timeline' + this.id).click(function(event) {
event.preventDefault();
event.stopPropagation();
timeline.selectTags(timeline.tags);
timeline.redraw();
return false;
});
// Select None button unchecks all checkboxes
jQuery('#SelectNoneButton_Timeline' + this.id).click(function(event) {
event.preventDefault();
event.stopPropagation();
timeline.selectTags([]);
timeline.redraw();
return false;
});
// Bulk Start button starts recording for all tags
jQuery('#BulkStartButton_Timeline' + this.id).click(function(event) {
event.preventDefault();
event.stopPropagation();
if (timeline.readOnly) {
if(timeline.readOnlyGroup) {
alert("You cannot edit another group's annotation.");
} else {
alert("The annotation can not be changed after it has been submitted.");
}
return false;
}
try {
timeline.startRecording(timeline.selectedTags);
timeline.redraw();
} catch (err) {
timeline.handleError(err);
}
return false;
});
// Bulk Stop button stops recording for all tags
jQuery('#BulkStopButton_Timeline' + this.id).click(function(event) {
event.preventDefault();
event.stopPropagation();
if (timeline.readOnly) {
if(timeline.readOnlyGroup) {
alert("You cannot edit another group's annotation.");
} else {
alert("The annotation can not be changed after it has been submitted.");
}
return false;
}
try {
timeline.stopRecording(timeline.selectedTags);
timeline.redraw();
} catch (err) {
timeline.handleError(err);
}
return false;
});
// We use TimeMarkerDigitPanel2's width (which should be set to every event band's width)
// as the initial value of eventBandWidth
// If TimeMarkerDigitPanel2 is ever resized, update the value
jQuery('#TimeMarkerDigitPanel2_Timeline' + this.id).resize(function() {
delete timeline.noRedraw.marker;
this.redraw();
});
// TimeMarkerDigitPanel2 (the area with the time numbers), when clicked, skips the video to another time
jQuery('#TimeMarkerDigitPanel2_Timeline' + this.id).click(function(clickEvent) {
clickEvent.preventDefault();
clickEvent.stopPropagation();
var pixel = clickEvent.pageX - jQuery('#TimeMarkerPanel_Timeline' + timeline.id).offset().left;
var time = timeline.pixelToSecond(pixel);
// SSC-978: Ignore clicks that result in attempted seeks outside the playable range
// We need this check because the event band is longer than the "clickable" range
if (time < timeline.minTime || time > timeline.maxTime)
return;
timeline.setCurrentTime(time, true);
delete timeline.noRedraw.currentTime;
timeline.redraw();
});
// Add Tag button brings up the Add Tag dialog
jQuery('#AddTagButton_Timeline' + this.id).click(function(event) {
event.preventDefault();
event.stopPropagation();
if (timeline.readOnly) {
if(timeline.readOnlyGroup) {
alert("You cannot edit another group's annotation.");
} else {
alert("The annotation can not be changed after it has been submitted.");
}
return false;
}
timeline.addTagDialogOpen = true;
timeline.redraw();
});
// Zoom In button increases the zoom factor by 2; the maximum zoom factor is 256
jQuery('#ZoomInButton_Timeline' + this.id).click(function(event) {
event.preventDefault();
event.stopPropagation();
if (timeline.zoomFactor * 2 <= 256)
timeline.zoomFactor *= 2;
delete timeline.noRedraw.marker;
timeline.redraw();
return;
});
// Zoom Out button decreases the zoom factor by 1/2; the minimum zoom factor is 1
jQuery('#ZoomOutButton_Timeline' + this.id).click(function(event) {
event.preventDefault();
event.stopPropagation();
if (timeline.zoomFactor / 2 >= 1)
timeline.zoomFactor /= 2;
delete timeline.noRedraw.marker;
timeline.redraw();
return;
});
// Dragging the current time bar handle moves the current time
jQuery('#CurrentTimeBarHandle_Timeline' + this.id).draggable({
axis: 'x',
cursor: 'w-resize',
containment: [
jQuery('#TimeMarkerPanel_Timeline' + this.id).offset().left,
0,
jQuery('#TimeMarkerPanel_Timeline' + this.id).offset().left + jQuery('#TimeMarkerPanel_Timeline' + this.id).width() - jQuery('#CurrentTimeBarHandle_Timeline' + this.id).width(),
0
],
start: function() {
timeline.sendMessage(timeline, 'currentTimeDragStart', timeline.getCurrentTime());
},
drag: function(event, ui) {
var newTime = timeline.pixelToSecond(ui.position.left - jQuery('#TimeMarkerPanel_Timeline' + timeline.id).position().left);
timeline.setCurrentTime(newTime, true);
delete timeline.noRedraw.currentTime;
timeline.redraw();
},
stop: function() {
timeline.sendMessage(timeline, 'currentTimeDragStop', timeline.getCurrentTime());
}
});
// Make bands sortable
jQuery('#TimelineBase_Timeline' + this.id).sortable({
disabled: false,
axis: 'y',
forcePlaceholderSize: true,
items: '.TagEventBand',
update: function(updateEvent, ui) {
if (timeline.readOnly)
return;
var elementIds = jQuery(this).sortable("toArray");
var tagIds = [];
for (var idx in elementIds) {
a = elementIds[idx];
var tagId = jQuery('#' + elementIds[idx]).data('tagId');
if (tagId !== undefined)
tagIds.push(tagId);
}
// Update the database via AJAX
var error = undefined;
jQuery.ajax({
type: "POST",
url: "database.php",
data: {
"c1_command": "reordertags",
"c1_clipid": timeline.clipId,
"c1_groupid": timeline.groupId,
"c1_orders": tagIds.join(",")
},
dataType: "json",
async: false,
success: function(jsonData, textStatus) {
if (!jsonData instanceof Array) {
error = new Error();
error.message = "error when receiving data from server";
return;
}
if (jsonData[0]["success"] !== true) {
error = new Error();
if (typeof jsonData[0]["errortype"] != "undefined")
error.errortype = jsonData[0]["errortype"];
if (typeof jsonData[0]["message"] != "undefined")
error.message = jsonData[0]["message"];
return;
}
}
});
if (typeof error != "undefined")
throw error;
// Reorder our tags array
var newTags = [];
for (var idx in tagIds) {
newTags.push(timeline.findTag(tagIds[idx]));
}
timeline.tags = newTags;
}
});
this.noRedraw = {};
}
// Create the time markers if it doesn't exist
if (typeof this.noRedraw.marker === 'undefined' || !this.noRedraw.marker) {
jQuery('#TimeMarkerPanel_Timeline' + this.id).children().remove();
var eventBandWidth = jQuery('#TimeMarkerDigitPanel2_Timeline' + this.id).width();
var minTime;
var maxTime;
// Find the smallest value in {1s, 10s, 100s, 1000s, ...} for majorMarkerInterval
// so that the space between two major markers is at least 20 pixels
for (var majorMarkerInterval = 1; majorMarkerInterval < this.maxTime - this.minTime; majorMarkerInterval *= 10) {
// Find max(time value of the left edge of the event band, min playable time)
// Find min(time value of the right edge of the event band, max playable time)
// Round both the the nearest (majorMarkerInterval)
minTime = Math.floor(Math.max(this.pixelToSecond(0), this.minTime) / majorMarkerInterval) * majorMarkerInterval;
maxTime = Math.ceil(Math.min(this.pixelToSecond(eventBandWidth), this.maxTime) / majorMarkerInterval) * majorMarkerInterval;
// If the space is at least 20 pixel, use this majorMarkerInterval value
if (this.secondToPixel(majorMarkerInterval, true) >= 20)
break;
}
var str = '';
for (var tInSec = minTime; tInSec <= maxTime; tInSec += majorMarkerInterval) {
str += "<div class='TimeAxisMajorMarker' style='left: " + this.secondToPixel(tInSec) + "px;'></div>";
str += "<div class='TimeAxisMajorMarkerText' style='left: " + this.secondToPixel(tInSec) + "px;'>" + tInSec + "</div>";
}
jQuery('#TimeMarkerPanel_Timeline' + this.id).append(str);
this.noRedraw.marker = true;
}
// If the current time is set, show CurrentTimeBarHandle and CurrentTimeBar at that left position
// Otherwise, hiden them
if (typeof this.noRedraw.currentTime === 'undefined' || !this.noRedraw.currentTime) {
timeline.setTimelineMarker();
}
//
if (typeof this.bulkMode !== "undefined" && this.bulkMode) {
jQuery('#BulkModeOnButton_Timeline' + this.id).hide();
jQuery('#BulkModeOffButton_Timeline' + this.id).show();
jQuery('#SelectAllButton_Timeline' + this.id).show();
jQuery('#SelectNoneButton_Timeline' + this.id).show();
jQuery('#BulkStartButton_Timeline' + this.id).show();
jQuery('#BulkStopButton_Timeline' + this.id).show();
} else {
jQuery('#BulkModeOnButton_Timeline' + this.id).show();
jQuery('#BulkModeOffButton_Timeline' + this.id).hide();
jQuery('#SelectAllButton_Timeline' + this.id).hide();
jQuery('#SelectNoneButton_Timeline' + this.id).hide();
jQuery('#BulkStartButton_Timeline' + this.id).hide();
jQuery('#BulkStopButton_Timeline' + this.id).hide();
}
// Process each tag
for (var idx in this.tags) {
var tagId = this.tags[idx].getId();
// Create the tag band and event band if they're not there
if (jQuery('#TagEventBand_Tag' + tagId + '_Timeline' + this.id).length == 0) {
var str = '';
str += '<div id="TagEventBand_Tag' + tagId + '_Timeline' + this.id + '" class="TagEventBand" style="">';
str += ' <div id="TagBand_Tag' + tagId + '_Timeline' + this.id + '" class="TagBand" title="Double-click to edit this tag; drag to reorder this tag">';
str += ' </div>';
str += ' <div id="EventBand_Tag' + tagId + '_Timeline' + this.id + '" class="EventBand" title="Double-click to add an event">';
str += ' </div>';
str += '</div>';
// Add the new tag event band to after the last existing tag event band
// Or, if no tag event band exists, add after the time marker digit panel
var lastTagEventBand = jQuery('#TimelineBase_Timeline' + timeline.id).find('.TagEventBand').last();
if (lastTagEventBand.length > 0) {
lastTagEventBand.after(str);
} else {
jQuery('#TimeMarkerDigitPanel_Timeline' + this.id).after(str);
}
// Set the tag ID so that sortable can use it to update the order
jQuery('#TagEventBand_Tag' + tagId + '_Timeline' + this.id).data('tagId', tagId).data('oldlevel', this.findTag(tagId).getLevel());
jQuery('#EventBand_Tag' + tagId + '_Timeline' + this.id).data('tagId', tagId);
// Set the initial height of the EventBand_Tag and TagEventBand_Tag.
console.log("setting initial height");
var EventBandTag = jQuery('#EventBand_Tag' + tagId + '_Timeline' + this.id);
var level = this.findTag(tagId).getLevel();
var baseHeight = 22;
EventBandTag.css('height', level * baseHeight);
EventBandTag.parent().css('height', level * baseHeight);
// If the event band is clicked, go to the time corresponding to the position clicked
jQuery('#EventBand_Tag' + tagId + '_Timeline' + this.id).click(function(clickEvent) {
clickEvent.preventDefault();
//clickEvent.stopPropagation();
var pixel = clickEvent.pageX - jQuery('#TimeMarkerPanel_Timeline' + timeline.id).offset().left;
var time = timeline.pixelToSecond(pixel);
// SSC-978: Ignore clicks that result in attempted seeks outside the playable range
// We need this check because the event band is longer than the "clickable" range
if (time < timeline.minTime || time > timeline.maxTime)
return;
timeline.setCurrentTime(time, true);
delete timeline.noRedraw.currentTime;
timeline.setTimelineMarker();
});
// If the event band is double-clicked, bring up the Add Event dialog
jQuery('#EventBand_Tag' + tagId + '_Timeline' + this.id).click(function(clickEvent) {
if(event.shiftKey) {
clickEvent.preventDefault();
clickEvent.stopPropagation();
if (timeline.readOnly) {
if(timeline.readOnlyGroup) {
alert("You cannot edit another group's annotation.");
} else {
alert("The annotation can not be changed after it has been submitted.");
}
return;
}
if (jwplayer().getState() == "PLAYING")
jwplayer().pause();
// SSC-978: Ignore clicks that result in attempted seeks outside the playable range
// We need this check because the event band is longer than the "clickable" range
var pixel = clickEvent.pageX - jQuery('#TimeMarkerPanel_Timeline' + timeline.id).offset().left;
var time = timeline.pixelToSecond(pixel);
if (time < timeline.minTime || time > timeline.maxTime)
return;
var tagId = jQuery(this).data('tagId');
if (typeof timeline.editEventDialogOpen === "undefined")
timeline.editEventDialogOpen = {};
timeline.editEventDialogOpen[tagId] = 0;
timeline.setTimelineMarker();
timeline.redraw();
}
});
}
// If Edit Tag dialog requested, create it if it doesn't exist
if (typeof this.editTagDialogOpen !== "undefined"
&& typeof this.editTagDialogOpen[tagId] !== "undefined"
&& this.editTagDialogOpen[tagId]
&& !this.readOnly) {
if (jQuery('#EditTagDialog_Tag' + tagId + '_Timeline' + this.id).length == 0) {
var str = '';
str += '<table id="EditTagDialog_Tag' + tagId + '_Timeline' + this.id + '" class="EditTagDialog">';
str += ' <tr>';
str += ' <th colspan=2 id="EditTagDialogTitle_Tag' + tagId + '_Timeline' + this.id + '" class="EditTagDialogTitle">Edit Tag</th>';
str += ' </tr>';
str += ' <tr>';
str += ' <td>Name:</td>';
str += ' <td><textarea id="EditTagDialogName_Tag' + tagId + '_Timeline' + this.id + '" class="EditTagDialogName" name="name" cols="14"></textarea></td>';
str += ' </tr>';
str += ' <tr>';
str += ' <td>Color:</td>';
str += ' <td>';
str += ' <input type="hidden" id="EditTagDialogColor_Tag' + tagId + '_Timeline' + this.id + '" class="EditTagDialogColor" name="color" value="" />';
str += ' <input id="ColorPicker' + tagId + '_Edit" class="ColorPicker" value=' + timeline.findTag(tagId).getColor() + '></input>';
str += ' <div style="clear: both;"></div>';
str += ' </td>';
str += ' </tr>';
str += ' <tr>';
str += ' <td colspan=2>';
str += ' <div id="EditTagDialogError_Tag' + tagId + '_Timeline' + this.id + '" class="EditTagDialogError"></div>';
str += ' </td>';
str += ' </tr>';
str += ' <tr>';
str += ' <td colspan=2>';
str += ' <input id="EditTagDialogSaveButton_Tag' + tagId + '_Timeline' + this.id + '" class="EditTagDialogSaveButton" type="submit" value="Save" />';
str += ' <input id="EditTagDialogCancelButton_Tag' + tagId + '_Timeline' + this.id + '" class="EditTagDialogCancelButton" type="submit" value="Cancel" />';
str += ' <input id="EditTagDialogDeleteButton_Tag' + tagId + '_Timeline' + this.id + '" class="EditTagDialogDeleteButton" type="submit" value="Delete This Tag" />';
str += ' <input id="EditTagDialogOldName_Tag' + tagId + '_Timeline' + this.id + '" type="hidden" />';
str += ' <input id="EditTagDialogOldColor_Tag' + tagId + '_Timeline' + this.id + '" type="hidden" />';
str += ' </td>';
str += ' </tr>';
str += '</table>';
jQuery('#TagBand_Tag' + tagId + '_Timeline' + this.id).append(str);
// SSC-978:
// Prevent clicks on the dialog from being passed through
jQuery('#EditTagDialog_Tag' + tagId + '_Timeline' + this.id).click(function(event) {
event.stopPropagation();
});
/********* Color Picker Code ********************/
//bind the new color dialogs
jscolor.init();
//set the initial color and tag information
var color = '#' + document.getElementById('ColorPicker' + tagId + '_Edit').color.toString();
jQuery('#EditTagDialogColor_Tag' + tagId + '_Timeline' + timeline.id).val(color);
jQuery('#ColorPicker' + tagId + '_Edit').data('tagId', tagId);
//change the tag color when a new color is selected
jQuery('#ColorPicker' + tagId + '_Edit').change( function() {
tagId = jQuery(this).data('tagId');
var color = '#' + this.color.toString();
jQuery('#EditTagDialogColor_Tag' + tagId + '_Timeline' + timeline.id).val(color);
});
/******** End Color Picker Code *****************/
// Record existing name and color
jQuery('#EditTagDialogOldName_Tag' + tagId + '_Timeline' + this.id).val(timeline.findTag(tagId).getName());
jQuery('#EditTagDialogOldColor_Tag' + tagId + '_Timeline' + this.id).val(timeline.findTag(tagId).getColor());
// Show existing name
jQuery('#EditTagDialogName_Tag' + tagId + '_Timeline' + this.id).val(timeline.findTag(tagId).getName());
jQuery('#EditTagDialogSaveButton_Tag' + tagId + '_Timeline' + this.id).data('tagId', tagId).data('timeline', timeline);
jQuery('#EditTagDialogCancelButton_Tag' + tagId + '_Timeline' + this.id).data('tagId', tagId);
jQuery('#EditTagDialogDeleteButton_Tag' + tagId + '_Timeline' + this.id).data('tagId', tagId);
// If Save button clicked,
// update the tag and hide tag dialog and show tag controls
jQuery('#EditTagDialogSaveButton_Tag' + tagId + '_Timeline' + this.id).click(function(event) {
event.preventDefault();
event.stopPropagation();
var tagId = jQuery(event.target).data('tagId');
var oldName = jQuery('#EditTagDialogOldName_Tag' + tagId + '_Timeline' + timeline.id).val();
var oldColor = jQuery('#EditTagDialogOldColor_Tag' + tagId + '_Timeline' + timeline.id).val();
var newName = jQuery('#EditTagDialogName_Tag' + tagId + '_Timeline' + timeline.id).val();
if (typeof newName != 'string' || newName.trim() == '') {
jQuery('#EditTagDialogError_Tag' + tagId + '_Timeline' + timeline.id).text('Name cannot be empty.');
timeline.redraw();
return;
}
if (typeof timeline.findTag(newName) != 'undefined' && timeline.findTag(newName).getId() != tagId) {
jQuery('#EditTagDialogError_Tag' + tagId + '_Timeline' + timeline.id).text('A tag with the same name already exists.');
timeline.redraw();
return;
}
var newColor = jQuery('#EditTagDialogColor_Tag' + tagId + '_Timeline' + timeline.id).val();
try {
timeline.editTag(tagId, oldName, oldColor, newName, newColor, true, timeline.findTag(tagId).getLevel());
delete timeline.editTagDialogOpen[tagId];
savedNewContent = undefined;
timeline.redraw();
} catch (err) {
timeline.handleError(err);
}
});
// If Cancel button clicked,
// hide tag dialog and show tag controls
jQuery('#EditTagDialogCancelButton_Tag' + tagId + '_Timeline' + this.id).click(function(event) {
event.preventDefault();
event.stopPropagation();