| author | ymh <ymh.work@gmail.com> |
| Tue, 22 Oct 2024 07:03:54 +0200 | |
| changeset 1076 | 510fd2a482f4 |
| parent 1072 | ac1eacb3aa33 |
| permissions | -rw-r--r-- |
| 880 | 1 |
/* |
2 |
The Slider Widget shows time position and allows seek |
|
3 |
*/ |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
4 |
import sliceStyles from "./Slice.module.css"; |
| 880 | 5 |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
6 |
const Slice = 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); |
| 924 | 10 |
this.sliding = false; |
| 880 | 11 |
}; |
12 |
||
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
13 |
static defaults = { |
| 965 | 14 |
show_arrow: false |
| 880 | 15 |
}; |
16 |
||
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
17 |
static template = |
| 965 | 18 |
'<div class="Ldt-Slice"></div>' |
| 1013 | 19 |
+ '{{#show_arrow}}<div class="Ldt-Slice-Arrow"></div>{{/show_arrow}}'; |
| 965 | 20 |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
21 |
draw() { |
| 880 | 22 |
|
| 965 | 23 |
this.renderTemplate(); |
24 |
|
|
25 |
this.$slider = this.$.find(".Ldt-Slice"); |
|
| 880 | 26 |
|
| 965 | 27 |
if (this.show_arrow) { |
28 |
this.insertSubwidget(this.$.find(".Ldt-Slice-Arrow"), { type: "Arrow" },"arrow"); |
|
29 |
} |
|
| 880 | 30 |
|
31 |
this.min = 0; |
|
| 965 | 32 |
this.max = this.media.duration.valueOf(); |
| 880 | 33 |
|
| 924 | 34 |
var _this = this, |
35 |
_currentTime; |
|
| 880 | 36 |
|
37 |
this.$slider.slider({ |
|
38 |
range: true, |
|
| 965 | 39 |
values: [0, this.max], |
| 880 | 40 |
min: 0, |
41 |
max: this.max, |
|
42 |
change: function(event, ui) { |
|
| 965 | 43 |
if (_this.arrow) { |
| 1013 | 44 |
_this.arrow.moveToTime((ui.values[0]+ui.values[1])/2); |
| 965 | 45 |
} |
46 |
if (_this.onBoundsChanged) { |
|
47 |
_this.onBoundsChanged(ui.values[0],ui.values[1]); |
|
48 |
} |
|
| 923 | 49 |
}, |
50 |
start: function() { |
|
| 924 | 51 |
_this.sliding = true; |
| 975 | 52 |
if (!_this.media.getPaused()) { |
| 957 | 53 |
_this.media.pause(); |
| 923 | 54 |
} |
| 957 | 55 |
_currentTime = _this.media.getCurrentTime(); |
| 924 | 56 |
}, |
57 |
slide: function(event, ui) { |
|
| 957 | 58 |
_this.media.setCurrentTime(ui.value); |
| 924 | 59 |
}, |
60 |
stop: function() { |
|
61 |
_this.sliding = false; |
|
| 957 | 62 |
_this.media.setCurrentTime(_currentTime); |
| 880 | 63 |
} |
64 |
}); |
|
| 965 | 65 |
|
| 880 | 66 |
this.$slider.find(".ui-slider-handle:first").addClass("Ldt-Slice-left-handle"); |
67 |
this.$slider.find(".ui-slider-handle:last").addClass("Ldt-Slice-right-handle"); |
|
| 965 | 68 |
|
69 |
this.getWidgetAnnotations().forEach(function(_a) { |
|
70 |
_a.on("enter", function() { |
|
| 1033 | 71 |
_this.setBounds(_a.begin, _a.end); |
| 965 | 72 |
}); |
73 |
}); |
|
| 1033 | 74 |
this.player.on("annotation-click", function(_a) { |
75 |
_this.setBounds(_a.begin, _a.end); |
|
76 |
}); |
|
77 |
}; |
|
78 |
||
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
79 |
setBounds(begin, end) { |
| 1033 | 80 |
this.$slider.slider("values", [ begin, end ]); |
| 880 | 81 |
}; |
82 |
||
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
83 |
show() { |
| 880 | 84 |
this.$slider.show(); |
| 1013 | 85 |
}; |
| 880 | 86 |
|
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
87 |
hide() { |
| 880 | 88 |
this.$slider.hide(); |
| 1013 | 89 |
}; |
|
1072
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
90 |
|
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
91 |
}} |
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
92 |
|
|
ac1eacb3aa33
Migrate source and build to vite.js
ymh <ymh.work@gmail.com>
parents:
1033
diff
changeset
|
93 |
export { Slice, sliceStyles }; |