summaryrefslogtreecommitdiff
path: root/javascript/videojs/src/js/control-bar/time-controls/current-time-display.js
diff options
context:
space:
mode:
Diffstat (limited to 'javascript/videojs/src/js/control-bar/time-controls/current-time-display.js')
-rw-r--r--javascript/videojs/src/js/control-bar/time-controls/current-time-display.js67
1 files changed, 67 insertions, 0 deletions
diff --git a/javascript/videojs/src/js/control-bar/time-controls/current-time-display.js b/javascript/videojs/src/js/control-bar/time-controls/current-time-display.js
new file mode 100644
index 0000000..5047df6
--- /dev/null
+++ b/javascript/videojs/src/js/control-bar/time-controls/current-time-display.js
@@ -0,0 +1,67 @@
+/**
+ * @file current-time-display.js
+ */
+import TimeDisplay from './time-display';
+import Component from '../../component.js';
+
+/**
+ * Displays the current time
+ *
+ * @extends Component
+ */
+class CurrentTimeDisplay extends TimeDisplay {
+
+ /**
+ * Builds the default DOM `className`.
+ *
+ * @return {string}
+ * The DOM `className` for this object.
+ */
+ buildCSSClass() {
+ return 'vjs-current-time';
+ }
+
+ /**
+ * Update current time display
+ *
+ * @param {Event} [event]
+ * The `timeupdate` event that caused this function to run.
+ *
+ * @listens Player#timeupdate
+ */
+ updateContent(event) {
+ // Allows for smooth scrubbing, when player can't keep up.
+ let time;
+
+ if (this.player_.ended()) {
+ time = this.player_.duration();
+ } else if (event && event.target && typeof event.target.pendingSeekTime === 'function' && event.target.pendingSeekTime() !== null) {
+ time = event.target.pendingSeekTime();
+ } else {
+ time = (this.player_.scrubbing()) ? this.player_.getCache().currentTime : this.player_.currentTime();
+ }
+
+ this.updateTextNode_(time);
+ }
+}
+
+/**
+ * The text that is added to the `CurrentTimeDisplay` for screen reader users.
+ *
+ * @type {string}
+ * @private
+ */
+CurrentTimeDisplay.prototype.labelText_ = 'Current Time';
+
+/**
+ * The text that should display over the `CurrentTimeDisplay`s controls. Added to for localization.
+ *
+ * @type {string}
+ * @protected
+ *
+ * @deprecated in v7; controlText_ is not used in non-active display Components
+ */
+CurrentTimeDisplay.prototype.controlText_ = 'Current Time';
+
+Component.registerComponent('CurrentTimeDisplay', CurrentTimeDisplay);
+export default CurrentTimeDisplay;