Sha256: faceab59581b7de769d8756e85b6630868a688bfaf42b2730efaf80984f4534b

Contents?: true

Size: 2 KB

Versions: 22

Compression:

Stored size: 2 KB

Contents

pageflow.mediaPlayer.volumeBinding = function(player, settings, options) {
  options = options || {};

  var originalPlay = player.play;
  var originalPause = player.pause;

  var volumeFactor = 'volumeFactor' in options ? options.volumeFactor : 1;

  player.play = function() {
    player.volume(player.targetVolume());
    listenToVolumeSetting();

    return originalPlay.call(player);
  };

  player.playAndFadeIn = function(duration) {
    if (!player.paused() && !player.intendingToPause()) {
      return new jQuery.Deferred().resolve().promise();
    }

    player.intendToPlay();
    player.volume(0);

    return $.when(originalPlay.call(player)).then(function() {
      listenToVolumeSetting();
      return player.fadeVolume(player.targetVolume(), duration).then(null, function() {
        return new jQuery.Deferred().resolve().promise();
      });
    });
  };

  player.pause = function() {
    stopListeningToVolumeSetting();
    originalPause.call(player);
  };

  player.fadeOutAndPause = function(duration) {
    if (player.paused() && !player.intendingToPlay()) {
      return new jQuery.Deferred().resolve().promise();
    }

    player.intendToPause();
    stopListeningToVolumeSetting();

    return player.fadeVolume(0, duration).always(function() {
      return player.ifIntendingToPause().then(function() {
        originalPause.call(player);
      });
    });
  };

  player.changeVolumeFactor = function(factor, duration) {
    volumeFactor = factor;
    return player.fadeVolume(player.targetVolume(), duration);
  };

  player.targetVolume = function() {
    return settings.get('volume') * volumeFactor;
  };

  function listenToVolumeSetting() {
    player.on('dispose', stopListeningToVolumeSetting);
    settings.on('change:volume', onVolumeChange);
  }

  function stopListeningToVolumeSetting() {
    player.off('dispose', stopListeningToVolumeSetting);
    settings.off('change:volume', onVolumeChange);
  }

  function onVolumeChange(model, value) {
    player.fadeVolume(player.targetVolume(), 40);
  }
};

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
pageflow-12.3.0 app/assets/javascripts/pageflow/media_player/volume_binding.js
pageflow-13.0.0.beta7 app/assets/javascripts/pageflow/media_player/volume_binding.js
pageflow-13.0.0.beta6 app/assets/javascripts/pageflow/media_player/volume_binding.js
pageflow-13.0.0.beta5 app/assets/javascripts/pageflow/media_player/volume_binding.js
pageflow-13.0.0.beta4 app/assets/javascripts/pageflow/media_player/volume_binding.js
pageflow-13.0.0.beta3 app/assets/javascripts/pageflow/media_player/volume_binding.js
pageflow-13.0.0.beta2 app/assets/javascripts/pageflow/media_player/volume_binding.js
pageflow-13.0.0.beta1 app/assets/javascripts/pageflow/media_player/volume_binding.js
pageflow-12.2.0 app/assets/javascripts/pageflow/media_player/volume_binding.js
pageflow-12.1.0 app/assets/javascripts/pageflow/media_player/volume_binding.js
pageflow-12.0.4 app/assets/javascripts/pageflow/media_player/volume_binding.js
pageflow-12.0.3 app/assets/javascripts/pageflow/media_player/volume_binding.js
pageflow-12.0.2 app/assets/javascripts/pageflow/media_player/volume_binding.js
pageflow-12.0.1 app/assets/javascripts/pageflow/media_player/volume_binding.js
pageflow-12.0.0 app/assets/javascripts/pageflow/media_player/volume_binding.js
pageflow-12.0.0.rc7 app/assets/javascripts/pageflow/media_player/volume_binding.js
pageflow-12.0.0.rc6 app/assets/javascripts/pageflow/media_player/volume_binding.js
pageflow-12.0.0.rc5 app/assets/javascripts/pageflow/media_player/volume_binding.js
pageflow-12.0.0.rc4 app/assets/javascripts/pageflow/media_player/volume_binding.js
pageflow-12.0.0.rc3 app/assets/javascripts/pageflow/media_player/volume_binding.js