PageSourceSearch

https://infinitypeptide.com/wp-content/plugins/mp3-music-player-by…/iron-audioplayer.js?ver=5.14.2

js infinitypeptide.com collected 2026-10-04 13:28:10 UTC 14,918 bytes, 403 lines download raw bytes

1IRON.previousTrackThreshold = 2; //The number of seconds a track must play before the "Previous" button resets the track to the beginning.
2
3IRON.audioPlayer = (function ($) {
4  "use strict";
5  var autoplayEnable;
6
7  function initPlayer(player) {
8    var audioPlayer = player;
9    audioPlayer.id = audioPlayer.data("id");
10    audioPlayer.hide_progressbar = audioPlayer.data("hide-progressbar") ? true : false;
11    this.audioPlayer = player;
12    var waveContainer = this.audioPlayer.find(".player .wave").attr("id");
13    var playlist = audioPlayer.find(".playlist");
14    this.playlist = playlist;
15    this.autoplayEnable = audioPlayer.data("autoplay");
16    audioPlayer.progressType = audioPlayer.data("progress-bar-style");
17
18    audioPlayer.list = {};
19    audioPlayer.list.tracks = [];
20
21    playlist.find(".sr-playlist-item").each(function () {
22        var $track = $(this);
23        var trackData = {
24            peakFile:             $track.data("peakfile"),
25            mp3:                  $track.data("audiopath"),
26            sourcePostID:         $track.data("post-id"),
27            id:                   $track.data("trackid"), // Its the media attachment ID if set.
28            track_pos:            $track.data("track-pos"),
29            isPreview:            $track.data("is-preview"),
30            peak_allow_frontend:  $track.data("peakfile-allow"),
31        };
32        audioPlayer.list.tracks.push(trackData);
33    });
34
35    $(audioPlayer).css("opacity", 1);
36
37    fetch(this.audioPlayer.attr('data-url-playlist')) // Call the fetch function passing the playlist.json as audioplayer.list parameters
38    .then(response => {
39      if (!response.ok) {
40        throw new Error('Network error: ' + response.status);
41      }
42      return response.json();
43    })
44    .then(data => {
45      this.audioPlayer.list = data;
46    })
47    .catch(error => {
48      console.error('There was a problem retrieving the data: ', error);
49    });
50    
51    this.$audio_el = $("#" + waveContainer).find(".sonaar_media_element")[0];
52    
53   
54    fakeWaveUpdate(this.$audio_el, audioPlayer, playlist);
55    $(audioPlayer).find(".wave").css("opacity", "1");
56    
57    setPlaylist(playlist, this.$audio_el, audioPlayer);
58
59    var trackNumber = playlist.find("li").index();
60    var track = playlist.find("li").eq(trackNumber);
61    if(track.data('tracktime')){
62      audioPlayer.find('.totalTime').text('-' + track.data('tracktime'));
63    }
64
65    setCurrentTrack(playlist.find("li").eq(0), playlist.find("li").index(), audioPlayer, this.$audio_el);
66    setControl(this.$audio_el, audioPlayer, playlist);
67    if(track.data('tracktime')){
68      audioPlayer.find('.totalTime').text('-' + track.data('tracktime'));
69    }
70    sr_playerCTAresponsive();
71  }
72
73  var triggerPlay = function ($audio_el, audioPlayer) {
74    $audio_el.play();
75    togglePlaying(audioPlayer, $audio_el);
76  };
77
78  function setCurrentTrack(track, index, audioPlayer, $audio_el) {
79    audioPlayer.currentTrack = index; 
80    var albumArt = audioPlayer.find(".album .album-art");
81    var album = audioPlayer.find(".album");
82    var trackTitle = audioPlayer.find(".track-title");
83    var trackTime = audioPlayer.find(".track-time");
84    var trackArtist = audioPlayer.find(".sr_it-artists-value");
85    var albumTitle = audioPlayer.find(".sr_it-playlist-title, .album-title");
86    var albumReleaseDate = audioPlayer.find(".srp_subtitle");
87
88    if (audioPlayer.data('hide-artwork') != '1' && audioPlayer.data('hide-artwork') != 'true') {
89      if (track.data("albumart")) {
90        audioPlayer.removeClass('sonaar-no-artwork');
91        if (albumArt.find("img").length) {
92          albumArt.find("img").attr("src", track.data("albumart"));
93        } else {
94          albumArt.css("background-image", "url(" + track.data("albumart") + ")");
95        }
96      } else {
97        audioPlayer.addClass('sonaar-no-artwork');
98      }
99    }
100
101    audioPlayer.data("currentTrack", index);
102    trackTitle.html(track.data("tracktitle"));
103    trackTime.text(track.data("tracktime"));
104    trackArtist.text(track.data("trackartists"));
105    albumReleaseDate.text(track.data("releasedate"));
106    if (audioPlayer.data("playlist_title").length) {
107      albumTitle.text(audioPlayer.data("playlist_title"));
108    } else {
109      albumTitle.text(track.data("albumtitle"));
110    }
111
112    if (audioPlayer.data('playertemplate') == 'skin_boxed_tracklist' && audioPlayer.find('.srp_track_cta').length) {
113      audioPlayer.find('.srp_track_cta .song-store-list-container').remove();
114      audioPlayer.find('.srp_track_cta').append(track.find('.song-store-list-container').clone());
115    }
116
117    audioPlayer.find(".player").removeClass("hide");
118
119    audioPlayer.find(".wave").removeClass("reveal");
120
121    if (!track.data("showloading")) {
122      audioPlayer.find(".player").addClass("hide");
123    } else {
124      audioPlayer.find(".progressLoading").css("opacity", "0.75");
125    }
126
127    IRON.createFakeWave(audioPlayer);
128    
129    setTime(audioPlayer, $audio_el);
130
131    hideEmptyAttribut(track.data("releasedate"), audioPlayer.find(".srp_subtitle"));
132  }
133
134  function setPlaylist(playlist, $audio_el, audioPlayer) {
135    let playlistTimeDuration = 0;
136    playlist.find("li").each(function () {
137
138      setSingleTrack($(this), $(this).index(), $audio_el, audioPlayer);
139
140      if ($(this).data('relatedtrack') != '1') { //Count playlist time duration
141        if ($(this).data('tracktime')) {
142          convertTime($(this).data('tracktime'));
143          playlistTimeDuration = playlistTimeDuration + convertTime($(this).data('tracktime'));
144        } else { // Hide playlist time duration if one track doesnt have time (streaming)
145          audioPlayer.find('.srp_playlist_duration').hide();
146        }
147      }
148
149    });
150    //Output playlist time duration
151    playlistTimeDuration = Math.round(playlistTimeDuration / 60) * 60; //Round to minutes
152    playlistTimeDuration = moment.duration(playlistTimeDuration, "seconds");
153    let durationOutput = (playlistTimeDuration.hours() > 0) ? playlistTimeDuration.hours() + ' ' + audioPlayer.find('.srp_playlist_duration').data('hours-label') + ' ' : '';
154    durationOutput = durationOutput + playlistTimeDuration.minutes() + ' ' + audioPlayer.find('.srp_playlist_duration').data('minutes-label');
155    audioPlayer.find('.srp_playlist_duration').html(durationOutput);
156  }
157
158  function setTime(audioPlayer, $audio_el) {
159    $($audio_el).on("timeupdate", function () {
160      var currentTime = $audio_el.currentTime;
161      var time = moment.duration(currentTime, "seconds");
162      if (time.hours() >= 12 || time.hours() <= 0) {
163        audioPlayer.find(".currentTime").html(moment(time.minutes() + ":" + time.seconds(), "m:s").format("mm:ss"));
164      } else {
165        audioPlayer.find(".currentTime").html(moment(time.hours() + ":" + time.minutes() + ":" + time.seconds(), "h:m:s").format("h:mm:ss"));
166      }
167      if ($audio_el.duration !== Infinity) {
168        var timeLeft = moment.duration($audio_el.duration - $audio_el.currentTime, "seconds");
169        if(timeLeft.milliseconds() > 0){
170          if (timeLeft.hours() >= 12 || timeLeft.hours() <= 0) {
171            audioPlayer.find(".totalTime").html("-" + moment(timeLeft.minutes() + ":" + timeLeft.seconds(), "m:s").format("mm:ss"));
172          } else {
173            audioPlayer.find(".totalTime").html("-" + moment(timeLeft.hours() + ":" + timeLeft.minutes() + ":" + timeLeft.seconds(), "h:m:s").format("h:mm:ss"));
174          }
175        }else{
176          audioPlayer.find(".totalTime").html("");
177        }
178      } else {
179        audioPlayer.find(".totalTime").html("");
180      }
181    });
182    
183  }
184
185  function setControl($audio_el, audioPlayer, playlist) {
186    // var ctrl = audioPlayer.find('.control');
187    audioPlayer.unbind('click');
188    audioPlayer.on("click", ".play, .album .album-art", function (event) {
189      togglePause();
190
191      if (!audioPlayer.hasClass("audio-playing")) {
192        if($($audio_el).attr('src') != ''){
193          play(audioPlayer, $audio_el);
194          triggerPlay($audio_el, audioPlayer);
195        } else {
196          playlist.find("li").eq(0).find("a.audio-track").click();
197        }
198      } else {
199        togglePause();
200      }
201      togglePlaying(audioPlayer, $audio_el);
202      event.preventDefault();
203    });
204    audioPlayer.on("click", ".previous", function (event) {
205      previous(audioPlayer, $audio_el, playlist);
206      event.preventDefault();
207    });
208    audioPlayer.on("click", ".next", function (event) {
209      next(audioPlayer, $audio_el, playlist);
210      event.preventDefault();
211    });
212    audioPlayer.on('mouseenter', '.sr-playlist-item .song-store-list-menu', function () {
213      openStoreListContainer(this);
214    });
215    audioPlayer.on('mouseleave', '.sr-playlist-item .song-store-list-container', function () {
216      closeStoreListContainer(this);
217    });
218  }
219
220  function setSingleTrack(singleTrack, eq, $audio_el, audioPlayer) {
221    singleTrack.find(".audio-track").remove();
222    var tracknumber = eq + 1;
223    var trackplay = $("<span/>", {
224      class: "track-number",
225      html:
226        '<span class="number">' +
227        tracknumber +
228        '</span><i class="sricon-play"></i>',
229    });
230    $("");
231    $("<a/>", {
232      class: "audio-track",
233      click: function (event) {
234        if ($(this).parents('.sr-playlist-item').attr("data-audiopath").length == 0) {
235          return;
236        }
237
238        if (ifTrackIsPlaying($audio_el) && singleTrack.hasClass("current")) {
239          togglePause();
240          togglePlaying(audioPlayer, $audio_el);
241        } else if (singleTrack.hasClass("current")) {
242          play(audioPlayer, $audio_el);
243        } else {
244          togglePause();
245          setCurrentTrack(singleTrack, eq, audioPlayer, $audio_el);
246          setAudio(singleTrack.data("audiopath"), $audio_el, audioPlayer);
247          
248          audioPlayer.find(".playlist li").removeClass("current");
249          singleTrack.addClass("current");
250          triggerPlay($audio_el, audioPlayer);
251          togglePlaying(audioPlayer, $audio_el);
252        }
253        IRON.init_generatePeaks(audioPlayer);
254        event.preventDefault();
255      },
256    })
257      .appendTo(singleTrack)
258      .prepend(trackplay)
259      .append('<div class="tracklist-item-title">' + singleTrack.data("tracktitle") + ' </div><span class="tracklist-item-time">' + singleTrack.data("tracktime") + "</span>");
260    singleTrack.find('.store-list').before(singleTrack.find(".audio-track"));
261  }
262
263  var setAudio = function (audio, $audio_el) {
264    $($audio_el).attr("src", audio);
265    $audio_el.load();
266
267    $(".sonaar_fake_wave").on("click", function (event) {
268      var currentAudio = $(this).find(".sonaar_media_element")[0];
269      var progressedAudio = $(this).width() / event.offsetX;
270      const duration = (currentAudio.duration == 'Infinity')? currentAudio.buffered.end(currentAudio.buffered.length-1) : currentAudio.duration;
271      currentAudio.currentTime = duration / progressedAudio;
272      event.preventDefault();
273    });
274  };
275
276  function togglePlaying(audioPlayer, $audio_el) {
277    $.each(IRON.players, function () {
278      this.audioPlayer.removeClass("audio-playing");
279    });
280
281    if (ifTrackIsPlaying($audio_el)) {
282      audioPlayer.addClass("audio-playing");
283      audioPlayer.find('.currentTime, .totalTime').show();
284      return;
285    }
286
287    audioPlayer.removeClass("audio-playing");
288  }
289
290  function togglePause() {
291    $.each(IRON.players, function () {
292      if (ifTrackIsPlaying(this.$audio_el)) {
293        this.$audio_el.pause();
294      }
295    });
296  }
297
298  function play(audioPlayer, $audio_el) {
299    IRON.init_generatePeaks(audioPlayer);
300    if (!audioPlayer.find(".playlist li").hasClass("current")) {
301      audioPlayer.find("li:first-of-type").addClass("current");
302    }
303    if (ifTrackIsPlaying($audio_el)) {
304      $audio_el.pause();
305    } else {
306      $audio_el.play();
307    }
308    togglePlaying(audioPlayer, $audio_el);
309  }
310
311  function previous(audioPlayer, $audio_el, playlist) {
312    if( $audio_el.currentTime > IRON.previousTrackThreshold ){ //Resets the track to the beginning Or go to the previous track.
313        $audio_el.currentTime = 0;
314        return;
315    }
316
317    var currentTrack = audioPlayer.data("currentTrack");
318    var nextTrack = currentTrack - 1;
319    playlist.find("li").eq(nextTrack).find("a.audio-track").click();
320  }
321
322  function next(audioPlayer, $audio_el, playlist) {
323    var currentTrack = audioPlayer.data("currentTrack");
324    var nextTrack = currentTrack + 1;
325
326    if (!playlist.find("li").eq(nextTrack).length) {
327      nextTrack = 0;
328    }
329    $audio_el.pause();
330    playlist.find("li").eq(nextTrack).find("a.audio-track").click();
331  }
332
333  function getPlayer() {
334    return this;
335  }
336
337  function getplay() {
338    play(this.audioPlayer, this.$audio_el);
339  }
340
341  function ifTrackIsPlaying($audio_el) {
342      return !$audio_el.paused;
343  }
344
345  var fakeWaveUpdate = function ($audio_el, audioPlayer, playlist) {
346    $($audio_el).on("timeupdate", function () {
347      const duration = (this.duration == 'Infinity')? this.buffered.end(this.buffered.length-1) : this.duration;
348      $(audioPlayer)
349        .find(".sonaar_wave_cut")
350        .width(((this.currentTime + 0.35) / duration) * 100 + "%");
351      if ($audio_el.ended) {
352        //When track ended
353        next(audioPlayer, $audio_el, playlist);
354      }
355    });
356  };
357
358  return {
359    init: initPlayer,
360    getPlayer: getPlayer,
361    play: getplay,
362    autoplayEnable: autoplayEnable,
363    triggerPlay: triggerPlay,
364  };
365})(jQuery);
366
367function hideEmptyAttribut(string, selector) {
368  if (string == "") {
369    selector.css("display", "none");
370  } else {
371    selector.css("display", "block");
372  }
373}
374
375
376//Load Music player Content
377function setIronAudioplayers(specificParentSelector) {
378  if (typeof specificParentSelector !== "undefined") {
379    // set all audioplayers or only players inide a specific selector
380    if (!specificParentSelector.includes('"') && !specificParentSelector.includes("'") && jQuery('[data-id="' + specificParentSelector + '"]').hasClass('iron-audioplayer')) { //if specificParentSelector is the iron-audioplayer element (not parent)
381      var playerSelector = jQuery('[data-id="' + specificParentSelector + '"]');
382    } else {
383      var playerSelector = jQuery(specificParentSelector + " .iron-audioplayer");
384    }
385
386    if (IRON.players == "undefined") {
387      IRON.players = []; //dont reset the IRON.players if they already exist and the setIronAudioplayers function is executed from sr-scripts.js
388    }
389  } else {
390    var playerSelector = jQuery(".iron-audioplayer");
391    IRON.players = [];
392  }
393  playerSelector.each(function () {
394
395    if (typeof specificParentSelector == "undefined" && jQuery(this).parents(".elementor-widget-woocommerce-products").length) return;
396
397    if (typeof specificParentSelector == "undefined" && jQuery(this).parents(".elementor-widget-music-player").length) return;
398    var player = Object.create(IRON.audioPlayer);
399    player.init(jQuery(this));
400    IRON.players.push(player);
401  });
402}
403setIronAudioplayers();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.