Sha256: bb027a00f3a645ee96afcffb46d078e268292b7c5cdd7d2d3925aa2e6397741d

Contents?: true

Size: 1.63 KB

Versions: 12

Compression:

Stored size: 1.63 KB

Contents

pageflow.mediaPlayer.volumeFading = function(player) {
  var originalVolume = player.volume;
  var fadeVolumeDeferred;
  var fadeVolumeInterval;

  player.volume = function(value) {
    if (typeof value !== 'undefined') {
      cancelFadeVolume();
    }

    return originalVolume.apply(player, arguments);
  };

  player.fadeVolume = function(value, duration) {
    if (!pageflow.browser.has('volume control support')) {
      return new jQuery.Deferred().resolve().promise();
    }

    cancelFadeVolume();

    return new $.Deferred(function(deferred) {
      var resolution = 10;
      var startValue = volume();
      var steps = duration / resolution;
      var leap = (value - startValue) / steps;

      if (value === startValue) {
        deferred.resolve();
      }
      else {
        fadeVolumeDeferred = deferred;
        fadeVolumeInterval = setInterval(function() {
          volume(volume() + leap);

          if ((volume() >= value && value >= startValue) ||
              (volume() <= value && value <= startValue)) {

            resolveFadeVolume();
          }
        }, resolution);
      }
    });

    function volume(/* arguments */) {
      return originalVolume.apply(player, arguments);
    }
  };

  player.one('dispose', cancelFadeVolume);

  function resolveFadeVolume() {
    clearInterval(fadeVolumeInterval);
    fadeVolumeDeferred.resolve();

    fadeVolumeInterval = null;
    fadeVolumeDeferred = null;
  }

  function cancelFadeVolume() {
    if (fadeVolumeInterval) {
      clearInterval(fadeVolumeInterval);
      fadeVolumeDeferred.reject();

      fadeVolumeInterval = null;
      fadeVolumeDeferred = null;
    }
  }
};

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
pageflow-12.0.4 app/assets/javascripts/pageflow/media_player/volume_fading.js
pageflow-12.0.3 app/assets/javascripts/pageflow/media_player/volume_fading.js
pageflow-12.0.2 app/assets/javascripts/pageflow/media_player/volume_fading.js
pageflow-12.0.1 app/assets/javascripts/pageflow/media_player/volume_fading.js
pageflow-12.0.0 app/assets/javascripts/pageflow/media_player/volume_fading.js
pageflow-12.0.0.rc7 app/assets/javascripts/pageflow/media_player/volume_fading.js
pageflow-12.0.0.rc6 app/assets/javascripts/pageflow/media_player/volume_fading.js
pageflow-12.0.0.rc5 app/assets/javascripts/pageflow/media_player/volume_fading.js
pageflow-12.0.0.rc4 app/assets/javascripts/pageflow/media_player/volume_fading.js
pageflow-12.0.0.rc3 app/assets/javascripts/pageflow/media_player/volume_fading.js
pageflow-12.0.0.rc2 app/assets/javascripts/pageflow/media_player/volume_fading.js
pageflow-12.0.0.rc1 app/assets/javascripts/pageflow/media_player/volume_fading.js