| author | ymh <ymh.work@gmail.com> |
| Tue, 22 Oct 2024 07:03:54 +0200 | |
| changeset 1076 | 510fd2a482f4 |
| parent 1072 | ac1eacb3aa33 |
| permissions | -rw-r--r-- |
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
1 |
import _ from "lodash"; |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
2 |
import jQuery from "jquery"; |
| 982 | 3 |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
4 |
const MultiSegments = function (ns) { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
5 |
return class extends ns.Widgets.Widget { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
6 |
constructor(player, config) { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
7 |
super(player, config); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
8 |
} |
| 982 | 9 |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
10 |
static defaults = { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
11 |
annotation_show_arrow: true, |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
12 |
annotation_start_minimized: false, |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
13 |
annotation_show_annotation_type: true, |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
14 |
show_all: false, |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
15 |
}; |
| 982 | 16 |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
17 |
draw() { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
18 |
var _this = this, |
| 982 | 19 |
lines = [], |
20 |
currentLine = null, |
|
21 |
segmentsopts = {}, |
|
22 |
annotationopts = {}; |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
23 |
_(this).each(function (_v, _k) { |
| 982 | 24 |
if (/^segments_/.test(_k)) { |
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
25 |
segmentsopts[_k.replace(/^segments_/, "")] = _v; |
| 982 | 26 |
} |
27 |
if (/^annotation_/.test(_k)) { |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
28 |
annotationopts[_k.replace(/^annotation_/, "")] = _v; |
| 982 | 29 |
} |
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
30 |
}); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
31 |
this.source.getAnnotationTypes().forEach(function (_anntype) { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
32 |
var segments = _anntype.getAnnotations().filter(function (_ann) { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
33 |
return _ann.getDuration() > 0 && _ann.getMedia().id == _this.media.id; |
| 982 | 34 |
}); |
35 |
if (segments.length) { |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
36 |
var visible = false; |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
37 |
|
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
38 |
var line = { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
39 |
segmentWidget: jQuery("<div>"), |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
40 |
annotationWidget: jQuery("<div>"), |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
41 |
hasSegmentsNow: function () { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
42 |
var _time = _this.media.getCurrentTime(); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
43 |
return !!segments.filter(function (_annotation) { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
44 |
return _annotation.begin <= _time && _annotation.end > _time; |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
45 |
}).length; |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
46 |
}, |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
47 |
hide: function () { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
48 |
if (visible) { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
49 |
visible = false; |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
50 |
this.annotationWidget.slideUp(); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
51 |
} |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
52 |
}, |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
53 |
show: function () { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
54 |
if (!visible) { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
55 |
visible = true; |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
56 |
this.annotationWidget.slideDown(); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
57 |
} |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
58 |
}, |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
59 |
}; |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
60 |
|
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
61 |
line.segmentWidget |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
62 |
.addClass("Ldt-MultiSegments-Segment") |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
63 |
.appendTo(_this.$); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
64 |
|
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
65 |
if (!_this.show_all) { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
66 |
line.segmentWidget.on("mouseenter", function () { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
67 |
if (line.hasSegmentsNow()) { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
68 |
currentLine = line; |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
69 |
checkVisibilities(); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
70 |
} |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
71 |
}); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
72 |
} |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
73 |
|
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
74 |
line.annotationWidget |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
75 |
.addClass("Ldt-MultiSegments-Annotation") |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
76 |
.appendTo(_this.$) |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
77 |
.hide(); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
78 |
|
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
79 |
_this.insertSubwidget( |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
80 |
line.segmentWidget, |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
81 |
_({ |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
82 |
type: "Segments", |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
83 |
annotation_type: _anntype, |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
84 |
width: "100%", |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
85 |
}).extend(segmentsopts).value() |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
86 |
); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
87 |
|
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
88 |
_this.insertSubwidget( |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
89 |
line.annotationWidget, |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
90 |
_({ |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
91 |
type: "Annotation", |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
92 |
annotation_type: _anntype, |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
93 |
width: "100%", |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
94 |
}).extend(annotationopts).value() |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
95 |
); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
96 |
|
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
97 |
lines.push(line); |
| 982 | 98 |
} |
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
99 |
}); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
100 |
|
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
101 |
// open line on segment click |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
102 |
jQuery(document).on("click", ".Ldt-Segments-Segment", function (e) { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
103 |
if (!_this.show_all && currentLine && !currentLine.hasSegmentsNow()) { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
104 |
currentLine = undefined; |
|
1021
7253d4d06f0d
update widgets after enhance in annotation platform.
cavaliet
parents:
1013
diff
changeset
|
105 |
} |
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
106 |
_(lines).each(function (line) { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
107 |
if ( |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
108 |
jQuery(e.target).parent().parent()[0] == line.segmentWidget[0] |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
109 |
) { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
110 |
currentLine = line; |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
111 |
line.show(); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
112 |
} else { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
113 |
line.hide(); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
114 |
} |
|
1021
7253d4d06f0d
update widgets after enhance in annotation platform.
cavaliet
parents:
1013
diff
changeset
|
115 |
}); |
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
116 |
}); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
117 |
|
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
118 |
//var _annotationWidgets = _this.$.find(".Ldt-MultiSegments-Annotation"); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
119 |
|
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
120 |
function checkVisibilities(_time) { |
|
1021
7253d4d06f0d
update widgets after enhance in annotation platform.
cavaliet
parents:
1013
diff
changeset
|
121 |
/*if (!_this.show_all && currentLine && !currentLine.hasSegmentsNow()) { |
| 982 | 122 |
currentLine = undefined; |
123 |
} |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
124 |
_(lines).each(function(line) { |
| 982 | 125 |
if (line.hasSegmentsNow()) { |
126 |
if (!_this.show_all && !currentLine) { |
|
127 |
currentLine = line; |
|
128 |
} |
|
129 |
if (_this.show_all || line === currentLine) { |
|
130 |
line.show(); |
|
131 |
} else { |
|
132 |
line.hide(); |
|
133 |
} |
|
134 |
} else { |
|
135 |
line.hide(); |
|
136 |
} |
|
|
1021
7253d4d06f0d
update widgets after enhance in annotation platform.
cavaliet
parents:
1013
diff
changeset
|
137 |
});*/ |
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
138 |
} |
| 982 | 139 |
} |
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
140 |
}; |
| 1033 | 141 |
}; |
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
142 |
|
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1069
diff
changeset
|
143 |
export { MultiSegments }; |