Skip to content

Commit 88aff91

Browse files
committed
Fixed Indenting and added changes from @DIYgod
1 parent 82ca11d commit 88aff91

3 files changed

Lines changed: 50 additions & 58 deletions

File tree

dist/APlayer.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/APlayer.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/APlayer.js

Lines changed: 48 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -846,66 +846,58 @@ class APlayer {
846846
}
847847
}
848848

849-
/**
849+
/**
850850
* Remove song from playlist
851851
*/
852852
removeSong(indexOfSong) {
853+
if (this.option.music[indexOfSong] != null) { // Check if song exists
854+
const list = this.element.getElementsByClassName('aplayer-list')[0];
855+
var oList = list.getElementsByTagName('ol')[0];
856+
var liList = oList.getElementsByTagName('li'); // Holds the index of the LI tags
857+
if (this.option.music[indexOfSong + 1] != null || this.option.music[indexOfSong - 1] != null) {
858+
if (indexOfSong == this.playIndex) {
859+
if (this.option.music[indexOfSong + 1] != null) { // Play next song if it exists. If not paused.
860+
this.setMusic(indexOfSong + 1);
861+
this.playIndex = this.playIndex -1; //Adjust play index for removed song
862+
}
863+
else if (this.option.music[indexOfSong + 1] == null) { // Play previous song if it exists. If not paused.
864+
this.setMusic(indexOfSong - 1);
865+
}
866+
}
867+
else {
868+
if (indexOfSong < this.playIndex) {
869+
this.playIndex = this.playIndex - 1;
870+
}
871+
}
872+
if (liList[indexOfSong + 1] == null) {
873+
var targetSong = liList[indexOfSong - 1];
874+
targetSong.getElementsByClassName('aplayer-list-index')[0].textContent = indexOfSong;
875+
}
876+
else {
877+
for (let i = 1; i < liList.length; i++) {
878+
if (liList[indexOfSong + i] != null) {
879+
var targetSong = liList[indexOfSong + i];
880+
targetSong.getElementsByClassName('aplayer-list-index')[0].textContent = indexOfSong + i;
881+
}
882+
}
883+
}
884+
this.option.music.splice(indexOfSong, 1); // Delete song from music array
885+
this.audios.splice(indexOfSong, 1); // Delete song from audios array (Has to be)
886+
liList[indexOfSong].remove();
887+
if (this.option.music[0] != null && this.option.music[1] == null) {
888+
this.multiple = false;
889+
this.element.classList.remove('aplayer-withlist');
890+
}
891+
}
892+
var listHeight = parseInt(list.style.height, 10);
893+
list.style.height = (listHeight - 33) + "px";
853894

854-
if (this.option.music[indexOfSong] != null) { // Check if song exists
855-
const list = this.element.getElementsByClassName('aplayer-list')[0];
856-
var oList = list.firstElementChild; // OL tag
857-
var liList = []; // Holds the index of the LI tags
858-
859-
for (let i = 0; i < oList.childNodes.length; i++) {
860-
if (oList.childNodes[i].tagName == 'LI') {
861-
liList.push(i); //Adds the LI tag indexes to array
862-
}
863-
}
864-
if (this.option.music[indexOfSong + 1] != null || this.option.music[indexOfSong - 1] != null) {
865-
if (indexOfSong == this.playIndex) {
866-
867-
if (this.option.music[indexOfSong + 1] != null) { // Play next song if it exists. If not paused.
868-
this.setMusic(indexOfSong + 1);
869-
} else if (this.option.music[indexOfSong + 1] == null) { // Play previous song if it exists. If not paused.
870-
this.setMusic(indexOfSong - 1);
871-
}
872-
873-
this.playIndex = this.playIndex - 1
874-
875-
} else {
876-
if (indexOfSong < this.playIndex) {
877-
this.playIndex = this.playIndex - 1;
878-
}
879-
}
880-
881-
if (oList.childNodes[liList[indexOfSong + 1]] == null) {
882-
var targetSong = oList.childNodes[liList[indexOfSong - 1]];
883-
targetSong.childNodes[3].textContent = indexOfSong;
884-
} else {
885-
for (let i = 1; i < liList.length; i++) {
886-
if (oList.childNodes[liList[indexOfSong + i]] != null) {
887-
var targetSong = oList.childNodes[liList[indexOfSong + i]];
888-
targetSong.childNodes[3].textContent = indexOfSong + i;
889-
}
890-
}
891-
}
892-
this.option.music.splice(indexOfSong, 1); // Delete song from music array
893-
this.audios.splice(indexOfSong, 1); // Delete song from audios array (Has to be)
894-
oList.childNodes[liList[indexOfSong]].remove();
895-
896-
if (this.option.music[0] != null && this.option.music[1] == null) {
897-
this.multiple = false;
898-
this.element.classList.remove('aplayer-withlist');
899-
}
900-
}
901-
902-
list.style.height = "";
903-
904-
} else {
905-
console.error("ERROR: Song does not exist");
906-
}
907-
908-
}
895+
}
896+
else {
897+
console.error("ERROR: Song does not exist");
898+
}
899+
}
900+
909901
/**
910902
* destroy this player
911903
*/

0 commit comments

Comments
 (0)