<commit_before>//Copyright 2014 Globo.com Player authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

import UIContainerPlugin from 'base/ui_container_plugin'
import Events from 'base/events'
import Styler from 'base/styler'
import template from 'base/template'
import posterStyle from './public/poster.scss'
import posterHTML from './public/poster.html'
import playIcon from 'icons/01-play.svg'

export default class PosterPlugin extends UIContainerPlugin {
  get name() { return 'poster' }
  get template() { return template(posterHTML) }
  get shouldRender() { return this.container.playback.name !== 'html_img'}

  get attributes() {
    return {
      'class': 'player-poster',
      'data-poster': ''
    }
  }

  get events() {
    return {
      'click': 'clicked'
    }
  }

  constructor(container) {
    super(container)
    this.hasStartedPlaying = false
    this.playRequested = false
    this.render()
    process.nextTick(() => this.update())
  }

  bindEvents() {
    this.listenTo(this.container, Events.CONTAINER_STOP, this.onStop)
    this.listenTo(this.container, Events.CONTAINER_PLAY, this.onPlay)
    this.listenTo(this.container, Events.CONTAINER_ENDED, this.onStop)
    this.listenTo(this.container, Events.CONTAINER_STATE_BUFFERING, this.update)
    this.listenTo(this.container, Events.CONTAINER_STATE_BUFFERFULL, this.update)
    this.listenTo(this.container, Events.CONTAINER_OPTIONS_CHANGE, this.render)
  }

  stopListening() {
    super.stopListening()
  }

  onPlay() {
    this.hasStartedPlaying = true
    this.update()
  }

  onStop() {
    this.hasStartedPlaying = false
    this.playRequested = false
    this.update()
  }

  showPlayButton(show) {
    if (show && (!this.options.chromeless || this.options.allowUserInteraction)) {
      this.$playButton.show()
      this.$el.addClass('clickable')
    } else {
      this.$playButton.hide()
      this.$el.removeClass('clickable')
    }
  }

  clicked() {
    if (!this.options.chromeless || this.options.allowUserInteraction) {
      this.playRequested = true
      this.update()
      this.container.play()
    }
    return false
  }

  shouldHideOnPlay() {
    // Audio broadcasts should keep the poster up; video should hide poster while playing.
    return !((this.container.playback.name == 'html5_audio') || this.options.audioOnly)
  }

  update() {
    if (!this.shouldRender) {
      return
    }
    let showPlayButton = !this.playRequested  && !this.hasStartedPlaying && !this.container.buffering
    this.showPlayButton(showPlayButton)
    if (!this.hasStartedPlaying) {
      this.container.disableMediaControl()
      this.$el.show()
    } else {
      this.container.enableMediaControl()
      if (this.shouldHideOnPlay()) {
        this.$el.hide()
      }
    }
  }

  render() {
    if (!this.shouldRender) {
      return
    }
    let style = Styler.getStyleFor(posterStyle, {baseUrl: this.options.baseUrl})
    this.$el.html(this.template())
    this.$el.append(style)
    if (this.options.poster) {<commit_msg>poster: use playback isAudioOnly property instead of options<commit_after>//Copyright 2014 Globo.com Player authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

import UIContainerPlugin from 'base/ui_container_plugin'
import Events from 'base/events'
import Styler from 'base/styler'
import template from 'base/template'
import posterStyle from './public/poster.scss'
import posterHTML from './public/poster.html'
import playIcon from 'icons/01-play.svg'

export default class PosterPlugin extends UIContainerPlugin {
  get name() { return 'poster' }
  get template() { return template(posterHTML) }
  get shouldRender() { return this.container.playback.name !== 'html_img'}

  get attributes() {
    return {
      'class': 'player-poster',
      'data-poster': ''
    }
  }

  get events() {
    return {
      'click': 'clicked'
    }
  }

  constructor(container) {
    super(container)
    this.hasStartedPlaying = false
    this.playRequested = false
    this.render()
    process.nextTick(() => this.update())
  }

  bindEvents() {
    this.listenTo(this.container, Events.CONTAINER_STOP, this.onStop)
    this.listenTo(this.container, Events.CONTAINER_PLAY, this.onPlay)
    this.listenTo(this.container, Events.CONTAINER_ENDED, this.onStop)
    this.listenTo(this.container, Events.CONTAINER_STATE_BUFFERING, this.update)
    this.listenTo(this.container, Events.CONTAINER_STATE_BUFFERFULL, this.update)
    this.listenTo(this.container, Events.CONTAINER_OPTIONS_CHANGE, this.render)
  }

  stopListening() {
    super.stopListening()
  }

  onPlay() {
    this.hasStartedPlaying = true
    this.update()
  }

  onStop() {
    this.hasStartedPlaying = false
    this.playRequested = false
    this.update()
  }

  showPlayButton(show) {
    if (show && (!this.options.chromeless || this.options.allowUserInteraction)) {
      this.$playButton.show()
      this.$el.addClass('clickable')
    } else {
      this.$playButton.hide()
      this.$el.removeClass('clickable')
    }
  }

  clicked() {
    if (!this.options.chromeless || this.options.allowUserInteraction) {
      this.playRequested = true
      this.update()
      this.container.play()
    }
    return false
  }

  shouldHideOnPlay() {
    // Audio broadcasts should keep the poster up; video should hide poster while playing.
    return !((this.container.playback.name == 'html5_audio') || this.container.playback.isAudioOnly)
  }

  update() {
    if (!this.shouldRender) {
      return
    }
    let showPlayButton = !this.playRequested  && !this.hasStartedPlaying && !this.container.buffering
    this.showPlayButton(showPlayButton)
    if (!this.hasStartedPlaying) {
      this.container.disableMediaControl()
      this.$el.show()
    } else {
      this.container.enableMediaControl()
      if (this.shouldHideOnPlay()) {
        this.$el.hide()
      }
    }
  }

  render() {
    if (!this.shouldRender) {
      return
    }
    let style = Styler.getStyleFor(posterStyle, {baseUrl: this.options.baseUrl})
    this.$el.html(this.template())
    this.$el.append(style)
    if (this.options.poster) {
{'fraction_non_alphanumeric': 0.12424145640370489, 'fraction_numerical': 0.002235707441711913, 'mean_word_length': 3.2576478585995923, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1335218', 'n_tokens_mistral': 2015, 'n_tokens_neox': 1959, 'n_words': 397}