default options
This commit is contained in:
+23
-2
@@ -1,4 +1,25 @@
|
||||
function APlayer(option) {
|
||||
// handle options error
|
||||
if (!('music' in option && 'title' in option.music && 'author' in option.music && 'url' in option.music && 'pic' in option.music)) {
|
||||
throw 'APlayer Error: Music, music.title, music.author, music.url, music.pic are required in options';
|
||||
}
|
||||
if (option.element === null) {
|
||||
throw 'APlayer Error: element option null';
|
||||
}
|
||||
|
||||
// default options
|
||||
var defaultOption = {
|
||||
element: document.getElementsByClassName('aplayer')[0],
|
||||
narrow: false,
|
||||
autoplay: false,
|
||||
showlrc: false
|
||||
};
|
||||
for (var defaultKey in defaultOption) {
|
||||
if (defaultOption.hasOwnProperty(defaultKey) && !option.hasOwnProperty(defaultKey)) {
|
||||
option[defaultKey] = defaultOption[defaultKey];
|
||||
}
|
||||
}
|
||||
|
||||
this.option = option;
|
||||
}
|
||||
|
||||
@@ -8,11 +29,10 @@ APlayer.prototype.init = function () {
|
||||
|
||||
// parser lrc
|
||||
if (this.option.showlrc) {
|
||||
var lines = [];
|
||||
this.lrcTime = [];
|
||||
this.lrcLine = [];
|
||||
var lrcs = this.element.getElementsByClassName('aplayer-lrc-content')[0].innerHTML;
|
||||
lines = lrcs.split(/\n/);
|
||||
var lines = lrcs.split(/\n/);
|
||||
var timeExp = /\[(\d{2})\:(\d{2})\.(\d{2})\]/;
|
||||
var lrcExp = /](.*)$/;
|
||||
for (var i = 0; i < lines.length; i++) {
|
||||
@@ -109,6 +129,7 @@ APlayer.prototype.init = function () {
|
||||
}, 500);
|
||||
});
|
||||
|
||||
// audio download error
|
||||
this.audio.addEventListener('error', function () {
|
||||
_self.element.getElementsByClassName('aplayer-author')[0].innerHTML = ' - ' + '加载失败 ╥﹏╥';
|
||||
});
|
||||
|
||||
@@ -187,15 +187,6 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height;
|
||||
font-size: 12px;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
a {
|
||||
margin-right: 7px;
|
||||
font-size: 14px;
|
||||
color: #000;
|
||||
&:hover {
|
||||
color: #E90F24;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.aplayer-controller {
|
||||
|
||||
Reference in New Issue
Block a user