Fixed Indenting and added changes from @DIYgod

This commit is contained in:
Michael 2017-12-18 01:20:29 -05:00
parent 82ca11d126
commit 88aff9111b
3 changed files with 50 additions and 58 deletions

2
dist/APlayer.min.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -846,66 +846,58 @@ class APlayer {
}
}
/**
/**
* Remove song from playlist
*/
removeSong(indexOfSong) {
if (this.option.music[indexOfSong] != null) { // Check if song exists
const list = this.element.getElementsByClassName('aplayer-list')[0];
var oList = list.getElementsByTagName('ol')[0];
var liList = oList.getElementsByTagName('li'); // Holds the index of the LI tags
if (this.option.music[indexOfSong + 1] != null || this.option.music[indexOfSong - 1] != null) {
if (indexOfSong == this.playIndex) {
if (this.option.music[indexOfSong + 1] != null) { // Play next song if it exists. If not paused.
this.setMusic(indexOfSong + 1);
this.playIndex = this.playIndex -1; //Adjust play index for removed song
}
else if (this.option.music[indexOfSong + 1] == null) { // Play previous song if it exists. If not paused.
this.setMusic(indexOfSong - 1);
}
}
else {
if (indexOfSong < this.playIndex) {
this.playIndex = this.playIndex - 1;
}
}
if (liList[indexOfSong + 1] == null) {
var targetSong = liList[indexOfSong - 1];
targetSong.getElementsByClassName('aplayer-list-index')[0].textContent = indexOfSong;
}
else {
for (let i = 1; i < liList.length; i++) {
if (liList[indexOfSong + i] != null) {
var targetSong = liList[indexOfSong + i];
targetSong.getElementsByClassName('aplayer-list-index')[0].textContent = indexOfSong + i;
}
}
}
this.option.music.splice(indexOfSong, 1); // Delete song from music array
this.audios.splice(indexOfSong, 1); // Delete song from audios array (Has to be)
liList[indexOfSong].remove();
if (this.option.music[0] != null && this.option.music[1] == null) {
this.multiple = false;
this.element.classList.remove('aplayer-withlist');
}
}
var listHeight = parseInt(list.style.height, 10);
list.style.height = (listHeight - 33) + "px";
if (this.option.music[indexOfSong] != null) { // Check if song exists
const list = this.element.getElementsByClassName('aplayer-list')[0];
var oList = list.firstElementChild; // OL tag
var liList = []; // Holds the index of the LI tags
for (let i = 0; i < oList.childNodes.length; i++) {
if (oList.childNodes[i].tagName == 'LI') {
liList.push(i); //Adds the LI tag indexes to array
}
}
if (this.option.music[indexOfSong + 1] != null || this.option.music[indexOfSong - 1] != null) {
if (indexOfSong == this.playIndex) {
if (this.option.music[indexOfSong + 1] != null) { // Play next song if it exists. If not paused.
this.setMusic(indexOfSong + 1);
} else if (this.option.music[indexOfSong + 1] == null) { // Play previous song if it exists. If not paused.
this.setMusic(indexOfSong - 1);
}
this.playIndex = this.playIndex - 1
} else {
if (indexOfSong < this.playIndex) {
this.playIndex = this.playIndex - 1;
}
}
if (oList.childNodes[liList[indexOfSong + 1]] == null) {
var targetSong = oList.childNodes[liList[indexOfSong - 1]];
targetSong.childNodes[3].textContent = indexOfSong;
} else {
for (let i = 1; i < liList.length; i++) {
if (oList.childNodes[liList[indexOfSong + i]] != null) {
var targetSong = oList.childNodes[liList[indexOfSong + i]];
targetSong.childNodes[3].textContent = indexOfSong + i;
}
}
}
this.option.music.splice(indexOfSong, 1); // Delete song from music array
this.audios.splice(indexOfSong, 1); // Delete song from audios array (Has to be)
oList.childNodes[liList[indexOfSong]].remove();
if (this.option.music[0] != null && this.option.music[1] == null) {
this.multiple = false;
this.element.classList.remove('aplayer-withlist');
}
}
list.style.height = "";
} else {
console.error("ERROR: Song does not exist");
}
}
}
else {
console.error("ERROR: Song does not exist");
}
}
/**
* destroy this player
*/