Skip to content

Commit

Permalink
Fix codacy validation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
markusweigelt committed Oct 6, 2023
1 parent e180146 commit db44aca
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Kitodo/src/main/webapp/WEB-INF/resources/css/kitodo.css
Original file line number Diff line number Diff line change
Expand Up @@ -3084,7 +3084,7 @@ Column content
}

#imagePreviewForm\:mediaDetail #audioWaveformTools > div > button:first-child {
margin-left: 0px;
margin-left: 0;
}

#imagePreviewForm\:mediaDetail #audioWaveformTools > div > button {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* GPL3-License.txt file that was distributed with this source code.
*/

import WaveSurfer from './libs/wavesurfer/wavesurfer.esm.js.jsf'
import WaveSurfer from './libs/wavesurfer/wavesurfer.esm.js.jsf';

class AudioWaveform {
#audioElement;
Expand All @@ -23,15 +23,15 @@ class AudioWaveform {
}

init() {
let self = this
this.#audioElement = document.querySelector('audio.mediaPreviewItem')
if (this.#audioElement && this.#audioElement.getAttribute("data-audio-waveform") != "initialized") {
this.#audioElement.setAttribute("data-audio-waveform", "initialized")
let self = this;
this.#audioElement = document.querySelector('audio.mediaPreviewItem');
if (this.#audioElement && this.#audioElement.getAttribute("data-audio-waveform") !== "initialized") {
this.#audioElement.setAttribute("data-audio-waveform", "initialized");

// add a loader to visualize loading process
this.#loader = document.createElement("div");
this.#loader.innerHTML = '<i class="fa fa-spinner fa-spin"/>'
this.#loader.classList.add('loader')
this.#loader.innerHTML = '<i class="fa fa-spinner fa-spin"/>';
this.#loader.classList.add('loader');
this.#audioElement.parentNode.insertBefore(this.#loader, this.#audioElement);

// when the user agent can play the media
Expand All @@ -40,7 +40,7 @@ class AudioWaveform {
clearTimeout(this.#buildTimeout);
self.#buildTimeout = setTimeout(function() {
self.#build();
}, 500)
}, 500);
}, {once: true});

}
Expand All @@ -53,13 +53,13 @@ class AudioWaveform {

// get the media id from the source parameter
const urlParams = new URLSearchParams(this.#audioElement.src);
let mediaId = urlParams.get('mediaId')
let mediaId = urlParams.get('mediaId');

let waveContainer = document.createElement("div");
waveContainer.setAttribute("id", "wave-container");
waveContainer.onclick = function () {
self.#wavesurfer.playPause()
}
self.#wavesurfer.playPause();
};
waveContainer.style.width = "90%";
waveContainer.style.display = "none";
this.#audioElement.parentNode.insertBefore(waveContainer, this.#audioElement);
Expand All @@ -77,20 +77,20 @@ class AudioWaveform {

this.#wavesurfer.on("decode", function () {
// cache peaks after when audio has been decoded
self.#peaksCache[mediaId] = self.#wavesurfer.getDecodedData().getChannelData(0)
self.#peaksCache[mediaId] = self.#wavesurfer.getDecodedData().getChannelData(0);
});

this.#wavesurfer.on("ready", function () {
waveContainer.style.display = "block";
self.#loader.style.display = "none";

let waveToolsContainer = document.getElementById("audioWaveformTools")
const waveToolsSlider = waveToolsContainer.querySelector('input[type="range"]')
let waveToolsContainer = document.getElementById("audioWaveformTools");
const waveToolsSlider = waveToolsContainer.querySelector('input[type="range"]');

waveToolsSlider.addEventListener('input', (e) => {
const minPxPerSec = e.target.valueAsNumber
self.#wavesurfer.zoom(minPxPerSec)
})
const minPxPerSec = e.target.valueAsNumber;
self.#wavesurfer.zoom(minPxPerSec);
});

waveToolsContainer.querySelectorAll('input[type="checkbox"]').forEach((input) => {
input.onchange = (e) => {
Expand All @@ -104,19 +104,15 @@ class AudioWaveform {
jumpButton.addEventListener('click', function (event) {
event.stopPropagation();
let jumpSeconds = parseInt(this.getAttribute("data-audio-waveform-tools-jump-seconds"));
self.#wavesurfer.setTime(self.#wavesurfer.getCurrentTime() + jumpSeconds)
self.#wavesurfer.setTime(self.#wavesurfer.getCurrentTime() + jumpSeconds);
});
});
});

this.#wavesurfer.on("error", function (e) {
console.error(e);
});
}

}

const audioWaveform= new AudioWaveform()
const audioWaveform= new AudioWaveform();

document.addEventListener("kitodo-metadataditor-mediaview-update", function () {
audioWaveform.init();
Expand Down
2 changes: 1 addition & 1 deletion Kitodo/src/main/webapp/WEB-INF/resources/js/resize.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* For the full copyright and license information, please read the
* GPL3-License.txt file that was distributed with this source code.
*/
/* globals PF */
/* globals PF, metadataEditor */
// jshint unused:false

var SEPARATOR_WIDTH = 3;
Expand Down

0 comments on commit db44aca

Please sign in to comment.