| author | ymh <ymh.work@gmail.com> |
| Tue, 22 Oct 2024 09:53:43 +0200 | |
| changeset 1079 | d4f0681c4ff1 |
| parent 1072 | ac1eacb3aa33 |
| permissions | -rw-r--r-- |
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
1 |
// Highlighter |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
2 |
|
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
3 |
import highlighterStyles from "./Highlighter.module.css"; |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
4 |
import _ from "lodash"; |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
5 |
|
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
6 |
const Highlighter = function (ns) { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
7 |
return class extends ns.Widgets.Widget { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
8 |
constructor(player, config) { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
9 |
super(player, config); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
10 |
var _this = this; |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
11 |
this.throttledRefresh = _.throttle(function () { |
| 1033 | 12 |
_this.update(); |
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
13 |
}, 800); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
14 |
} |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
15 |
|
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
16 |
/** |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
17 |
* Highlighter widget |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
18 |
* This widgets highlights the current annotations by setting the |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
19 |
* .activeAnnotation class on appropriate .Ldt-Highlighter-Annotation |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
20 |
* elements. These elements *must* have data-begin and data-end properties specifying their bounds (in ms) (and data-media specifying the media-id) |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
21 |
*/ |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
22 |
|
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
23 |
static defaults = {}; |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
24 |
|
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
25 |
update() { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
26 |
var _this = this; |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
27 |
var _currentTime = _this.media.getCurrentTime(); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
28 |
_this.$.find(".Ldt-Highlighter-Annotation", document).toggleClass( |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
29 |
"currentAnnotation", |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
30 |
function () { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
31 |
return ( |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
32 |
this.dataset.media === _this.media.id && |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
33 |
this.dataset.begin <= _currentTime && |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
34 |
_currentTime < this.dataset.end |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
35 |
); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
36 |
} |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
37 |
); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
38 |
return false; |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
39 |
} |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
40 |
|
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
41 |
draw() { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
42 |
var _this = this; |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
43 |
|
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
44 |
var _events = ["timeupdate", "seeked", "loadedmetadata"]; |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
45 |
for (var _i = 0; _i < _events.length; _i++) { |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
46 |
_this.onMediaEvent(_events[_i], _this.throttledRefresh); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
47 |
} |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
48 |
_this.throttledRefresh(); |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
49 |
} |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
50 |
}; |
| 1033 | 51 |
}; |
52 |
||
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
53 |
export { Highlighter, highlighterStyles }; |