Resume video on peertube link click in embed
authorChocobozzz <me@florianbigard.com>
Mon, 28 May 2018 09:35:18 +0000 (11:35 +0200)
committerChocobozzz <me@florianbigard.com>
Mon, 28 May 2018 09:36:29 +0000 (11:36 +0200)
client/src/assets/player/peertube-link-button.ts

index 6ead78c006c424f1d0be115bae8a2285d687b46c..a47adc2dba5e928fcbeabe1a84515c3221eac2ea 100644 (file)
@@ -4,17 +4,37 @@ const Button: VideoJSComponentInterface = videojsUntyped.getComponent('Button')
 class PeerTubeLinkButton extends Button {
 
   createEl () {
-    return videojsUntyped.dom.createEl('a', {
-      href: window.location.href.replace('embed', 'watch'),
+    return this.buildElement()
+  }
+
+  updateHref () {
+    const currentTime = Math.floor(this.player().currentTime())
+    this.el().setAttribute('href', this.buildHref(currentTime))
+  }
+
+  handleClick () {
+    this.player_.pause()
+  }
+
+  private buildElement () {
+    const el = videojsUntyped.dom.createEl('a', {
+      href: this.buildHref(),
       innerHTML: 'PeerTube',
       title: 'Go to the video page',
       className: 'vjs-peertube-link',
       target: '_blank'
     })
+
+    el.addEventListener('mouseenter', () => this.updateHref())
+
+    return el
   }
 
-  handleClick () {
-    this.player_.pause()
+  private buildHref (time?: number) {
+    let href = window.location.href.replace('embed', 'watch')
+    if (time) href += '?start=' + time
+
+    return href
   }
 }
 Button.registerComponent('PeerTubeLinkButton', PeerTubeLinkButton)