aboutsummaryrefslogblamecommitdiffhomepage
path: root/client/src/assets/player/shared/control-bar/next-previous-video-button.ts
blob: b7b986806523921cab12b1f085cd7efd5a56e83b (plain) (tree)
1
2
                              
                                                            















































                                                                                  
import videojs from 'video.js'
import { NextPreviousVideoButtonOptions } from '../../types'

const Button = videojs.getComponent('Button')

class NextPreviousVideoButton extends Button {
  private readonly nextPreviousVideoButtonOptions: NextPreviousVideoButtonOptions

  constructor (player: videojs.Player, options?: NextPreviousVideoButtonOptions) {
    super(player, options as any)

    this.nextPreviousVideoButtonOptions = options

    this.update()
  }

  createEl () {
    const type = (this.options_ as NextPreviousVideoButtonOptions).type

    const button = videojs.dom.createEl('button', {
      className: 'vjs-' + type + '-video'
    }) as HTMLButtonElement
    const nextIcon = videojs.dom.createEl('span', {
      className: 'icon icon-' + type
    })
    button.appendChild(nextIcon)

    if (type === 'next') {
      button.title = this.player_.localize('Next video')
    } else {
      button.title = this.player_.localize('Previous video')
    }

    return button
  }

  handleClick () {
    this.nextPreviousVideoButtonOptions.handler()
  }

  update () {
    const disabled = this.nextPreviousVideoButtonOptions.isDisabled()

    if (disabled) this.addClass('vjs-disabled')
    else this.removeClass('vjs-disabled')
  }
}

videojs.registerComponent('NextVideoButton', NextPreviousVideoButton)
videojs.registerComponent('PreviousVideoButton', NextPreviousVideoButton)