- composer update -W: core-recommended ^11.4 (11.4.13), drush ^13.8, gin ^5.0, symfony 7 - scan p2 packages.drupal.org: 98/101 modules ont une release compatible D11; contraintes racine+profil relevées - takeover custom: audiofield + bulkdelete (plus de branche D11 upstream), q2d_mod blocs convertis en attributs PHP 8 - patch core 2671162 supprimé (fix mergé dans D11), 2645922 gardé, patches image_field_caption réappliqués - seven retiré (plus dans le core D11), claro déjà présent pour gin - updb OK, change list entity vide, cim OK, cex commit (normalisation config) - allow-plugins symfony/runtime ajouté Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
249 lines
8.1 KiB
JavaScript
249 lines
8.1 KiB
JavaScript
/**
|
|
* DO NOT EDIT THIS FILE.
|
|
* See the following change record for more information,
|
|
* https://www.drupal.org/node/2815083
|
|
* @preserve
|
|
**/
|
|
|
|
(function ($, Drupal, once) {
|
|
'use strict';
|
|
|
|
Drupal.AudiofieldWavesurfer = {};
|
|
|
|
Drupal.AudiofieldWavesurfer.generate = function (context, file, settings) {
|
|
var elements = once('generate-waveform', '#' + file.id, context);
|
|
$.each(elements, function (index, wavecontainer) {
|
|
var wavesurfer = WaveSurfer.create({
|
|
container: '#' + $(wavecontainer).attr('id') + ' .waveform',
|
|
backend: settings.backend,
|
|
audioRate: settings.audioRate,
|
|
autoCenter: settings.autoCenter,
|
|
barGap: settings.barGap,
|
|
barHeight: settings.barHeight,
|
|
barWidth: settings.barWidth,
|
|
cursorColor: settings.cursorColor,
|
|
cursorWidth: settings.cursorWidth,
|
|
forceDecode: settings.forceDecode,
|
|
normalize: settings.normalize,
|
|
progressColor: settings.progressColor,
|
|
responsive: settings.responsive,
|
|
waveColor: settings.waveColor
|
|
});
|
|
|
|
if (typeof file.peakpath !== 'undefined') {
|
|
fetch(file.peakpath)
|
|
.then(response => {
|
|
if (!response.ok) {
|
|
throw new Error("HTTP error " + response.status);
|
|
}
|
|
return response.json();
|
|
})
|
|
.then(peaks => {
|
|
Drupal.AudiofieldWavesurfer.normalizePeaks(peaks);
|
|
|
|
wavesurfer.load(file.path, peaks.data);
|
|
$(wavecontainer).find('.player-button.playpause').html('Play');
|
|
})
|
|
.catch((e) => {
|
|
wavesurfer.load(file.path);
|
|
console.error('error', e);
|
|
});
|
|
}
|
|
else {
|
|
wavesurfer.load(file.path);
|
|
}
|
|
|
|
wavesurfer.setVolume(settings.volume);
|
|
|
|
$(wavecontainer).find('.player-button.playpause').on('click', function (event) {
|
|
Drupal.AudiofieldWavesurfer.PlayPause(wavecontainer, wavesurfer);
|
|
});
|
|
|
|
$(wavecontainer).find('.volume').on('change', function (event) {
|
|
wavesurfer.setVolume($(event.currentTarget).val() / 10);
|
|
});
|
|
|
|
if (!!settings.autoplay) {
|
|
wavesurfer.on('ready', wavesurfer.play.bind(wavesurfer));
|
|
}
|
|
Drupal.AudiofieldWavesurfer.instance = wavesurfer;
|
|
});
|
|
};
|
|
|
|
Drupal.AudiofieldWavesurfer.normalizePeaks = function (peaks) {
|
|
var max = peaks.data[0], min = peaks.data[0];
|
|
var X, scale;
|
|
for (X = 1; X < peaks.data.length; X++) {
|
|
if (max < peaks.data[X]) {
|
|
max = peaks.data[X];
|
|
}
|
|
if (min > peaks.data[X]) {
|
|
min = peaks.data[X];
|
|
}
|
|
}
|
|
scale = 1.0 / Math.max(Math.abs(min), Math.abs(max));
|
|
for (X = 0; X < peaks.data.length; X++) {
|
|
peaks.data[X] *= scale;
|
|
}
|
|
}
|
|
|
|
Drupal.AudiofieldWavesurfer.generatePlaylist = function (context, settings) {
|
|
var elements = once('generate-waveform', '#wavesurfer_playlist-' + settings.unique_id, context);
|
|
$.each(elements, function (index, wavecontainer) {
|
|
var wavesurfer = WaveSurfer.create({
|
|
container: '#' + $(wavecontainer).attr('id') + ' .waveform',
|
|
audioRate: settings.audioRate,
|
|
autoCenter: settings.autoCenter,
|
|
barGap: settings.barGap,
|
|
barHeight: settings.barHeight,
|
|
barWidth: settings.barWidth,
|
|
cursorColor: settings.cursorColor,
|
|
cursorWidth: settings.cursorWidth,
|
|
forceDecode: settings.forceDecode,
|
|
normalize: settings.normalize,
|
|
progressColor: settings.progressColor,
|
|
responsive: settings.responsive,
|
|
waveColor: settings.waveColor
|
|
});
|
|
|
|
wavesurfer.setVolume(settings.volume);
|
|
|
|
var first = $(wavecontainer).find('.playlist .track').first();
|
|
|
|
var label = $(wavecontainer).find('label').first();
|
|
label.html('Playing: ' + first.html());
|
|
|
|
Drupal.AudiofieldWavesurfer.Load(wavecontainer, wavesurfer, first, false);
|
|
|
|
$(wavecontainer).find('.player-button.playpause').on('click', function (event) {
|
|
Drupal.AudiofieldWavesurfer.PlayPause(wavecontainer, wavesurfer);
|
|
});
|
|
|
|
$(wavecontainer).find('.player-button.next').on('click', function (event) {
|
|
Drupal.AudiofieldWavesurfer.Next(wavecontainer, wavesurfer);
|
|
});
|
|
$(wavecontainer).find('.player-button.previous').on('click', function (event) {
|
|
Drupal.AudiofieldWavesurfer.Previous(wavecontainer, wavesurfer);
|
|
});
|
|
|
|
$(wavecontainer).find('.playlist .track').on('click', function (event) {
|
|
if ($(this).hasClass('playing')) {
|
|
Drupal.AudiofieldWavesurfer.PlayPause(wavecontainer, wavesurfer);
|
|
}
|
|
else {
|
|
Drupal.AudiofieldWavesurfer.Load(wavecontainer, wavesurfer, $(event.currentTarget));
|
|
}
|
|
});
|
|
|
|
$(wavecontainer).find('.volume').on('change', function (event) {
|
|
wavesurfer.setVolume($(event.currentTarget).val() / 10);
|
|
});
|
|
|
|
if (!!settings.autoplay) {
|
|
wavesurfer.on('ready', wavesurfer.play.bind(wavesurfer));
|
|
}
|
|
|
|
if (settings.autoplayNextTrack) {
|
|
wavesurfer.on('finish', function (event) {
|
|
Drupal.AudiofieldWavesurfer.Next(wavecontainer, wavesurfer);
|
|
});
|
|
}
|
|
|
|
Drupal.AudiofieldWavesurfer.instance = wavesurfer;
|
|
});
|
|
};
|
|
|
|
Drupal.AudiofieldWavesurfer.PlayPause = function (wavecontainer, wavesurfer) {
|
|
wavesurfer.playPause();
|
|
var button = $(wavecontainer).find('.player-button.playpause');
|
|
if (wavesurfer.isPlaying()) {
|
|
$(wavecontainer).addClass('playing');
|
|
button.html('Pause');
|
|
} else {
|
|
$(wavecontainer).removeClass('playing');
|
|
button.html('Play');
|
|
}
|
|
};
|
|
|
|
Drupal.AudiofieldWavesurfer.Load = function (wavecontainer, wavesurfer, track, playonload = true) {
|
|
|
|
var peakpath = track.attr('data-peakpath');
|
|
if (peakpath !== '') {
|
|
fetch(peakpath)
|
|
.then(response => {
|
|
if (!response.ok) {
|
|
throw new Error("HTTP error " + response.status);
|
|
}
|
|
return response.json();
|
|
})
|
|
.then(peaks => {
|
|
Drupal.AudiofieldWavesurfer.normalizePeaks(peaks);
|
|
|
|
wavesurfer.load(track.attr('data-src'), peaks.data);
|
|
})
|
|
.catch((e) => {
|
|
wavesurfer.load(track.attr('data-src'));
|
|
console.error('error', e);
|
|
});
|
|
}
|
|
else {
|
|
wavesurfer.load(track.attr('data-src'));
|
|
}
|
|
|
|
wavesurfer.on('ready', function (event) {
|
|
if (playonload) {
|
|
$(wavecontainer).removeClass('playing');
|
|
$(wavecontainer).addClass('playing');
|
|
$(wavecontainer).find('.player-button.playpause').html('Pause');
|
|
wavesurfer.play();
|
|
}
|
|
});
|
|
|
|
$(wavecontainer).find('.track').removeClass('playing');
|
|
|
|
track.addClass('playing');
|
|
|
|
$(wavecontainer).find('label').first().html('Playing: ' + track.html());
|
|
};
|
|
|
|
Drupal.AudiofieldWavesurfer.Next = function (wavecontainer, wavesurfer) {
|
|
if (wavesurfer.isPlaying()) {
|
|
Drupal.AudiofieldWavesurfer.PlayPause(wavecontainer, wavesurfer);
|
|
}
|
|
|
|
var track = $(wavecontainer).find('.track.playing').next();
|
|
if (typeof track.attr('data-src') === 'undefined') {
|
|
track = $(wavecontainer).find('.track').first();
|
|
}
|
|
|
|
Drupal.AudiofieldWavesurfer.Load(wavecontainer, wavesurfer, track);
|
|
};
|
|
|
|
Drupal.AudiofieldWavesurfer.Previous = function (wavecontainer, wavesurfer) {
|
|
if (wavesurfer.isPlaying()) {
|
|
Drupal.AudiofieldWavesurfer.PlayPause(wavecontainer, wavesurfer);
|
|
}
|
|
|
|
var track = $(wavecontainer).find('.track.playing').prev();
|
|
if (typeof track.attr('data-src') === 'undefined') {
|
|
track = $(wavecontainer).find('.track').last();
|
|
}
|
|
|
|
Drupal.AudiofieldWavesurfer.Load(wavecontainer, wavesurfer, track);
|
|
};
|
|
|
|
Drupal.behaviors.audiofieldwavesurfer = {
|
|
attach: function attach(context, settings) {
|
|
$.each(settings.audiofieldwavesurfer, function (key, settingEntry) {
|
|
if (settingEntry.playertype === 'default') {
|
|
$.each(settingEntry.files, function (key2, file) {
|
|
Drupal.AudiofieldWavesurfer.generate(context, file, settingEntry);
|
|
});
|
|
} else if (settingEntry.playertype === 'playlist') {
|
|
Drupal.AudiofieldWavesurfer.generatePlaylist(context, settingEntry);
|
|
}
|
|
});
|
|
}
|
|
};
|
|
})(jQuery, Drupal, once);
|