Skip to content

Commit

Permalink
new api: theme
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod committed Mar 13, 2018
1 parent e105283 commit ba76929
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
18 changes: 12 additions & 6 deletions src/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,7 @@ class APlayer {
else {
this.template.pic.style.backgroundImage = '';
}
if (this.options.audio[this.playIndex].theme) {
this.template.pic.style.backgroundColor = this.options.audio[this.playIndex].theme;
this.template.played.style.background = this.options.audio[this.playIndex].theme;
this.template.thumb.style.background = this.options.audio[this.playIndex].theme;
this.template.volume.style.background = this.options.audio[this.playIndex].theme;
}
this.theme();
this.template.title.innerHTML = this.options.audio[this.playIndex].name;
this.template.author.innerHTML = this.options.audio[this.playIndex].artist ? ' - ' + this.options.audio[this.playIndex].artist : '';
const light = this.container.getElementsByClassName('aplayer-list-light')[0];
Expand Down Expand Up @@ -244,6 +239,17 @@ class APlayer {
});
}

theme (color = this.options.audio[this.playIndex].theme, index = this.playIndex) {
this.options.audio[index].theme = color;
this.template.listCurs[index].style.backgroundColor = color;
if (index === this.playIndex) {
this.template.pic.style.backgroundColor = color;
this.template.played.style.background = color;
this.template.thumb.style.background = color;
this.template.volume.style.background = color;
}
}

seek (time) {
time = Math.max(time, 0);
if (this.audio.duration) {
Expand Down
1 change: 1 addition & 0 deletions src/js/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class Template {
this.button = this.container.querySelector('.aplayer-button');
this.list = this.container.querySelector('.aplayer-list');
this.listOl = this.container.querySelector('.aplayer-list ol');
this.listCurs = this.container.querySelectorAll('.aplayer-list-cur');
this.played = this.container.querySelector('.aplayer-played');
this.loaded = this.container.querySelector('.aplayer-loaded');
this.thumb = this.container.querySelector('.aplayer-thumb');
Expand Down
2 changes: 1 addition & 1 deletion src/template/player.art
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<ol{{ if options.listMaxHeight }} style="max-height: {{ options.listMaxHeight }}"{{ /if }}>
{{each options.audio}}
<li>
<span class="aplayer-list-cur" style="background: {{ $value.theme || options.theme }};"></span>
<span class="aplayer-list-cur" style="background-color: {{ $value.theme || options.theme }};"></span>
<span class="aplayer-list-index">{{ $index + 1 }}</span>
<span class="aplayer-list-title">{{ $value.name }}</span>
<span class="aplayer-list-author">{{ $value.artist }}</span>
Expand Down

0 comments on commit ba76929

Please sign in to comment.