mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-11 05:26:15 -08:00
9 lines
2.0 KiB
JavaScript
9 lines
2.0 KiB
JavaScript
/*!
|
|
* artplayer-plugin-playlist.js v3.1.7
|
|
* Github: https://github.com/zhw2590582/ArtPlayer#readme
|
|
* (c) 2017-2019 Harvey Zack
|
|
* Released under the MIT License.
|
|
*/
|
|
|
|
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(t=t||self).artplayerPluginPlaylist=n()}(this,function(){"use strict";return function(h){return function(e){var t=e.constructor.utils,n=t.append,i=t.errorHandle,r=t.sleep,l=t.inverseClass,a=e.player,u=e.events.proxy,o=e.template,c=o.$player,s=o.$video,y=n(c,'\n <div class="artplay-playlist">\n <div class="artplay-playlist-inner"></div>\n </div>\n ');i(Array.isArray(h),"Playlist is not an array type"),i(0<h.length,"Playlist cannot be empty");var f=h.map(function(t){return i(t.url,"Playlist items require url attribute"),i(t.title,"Playlist items require title attribute"),t}),d=y.querySelector(".artplay-playlist-inner");function p(t){var n=f[t];return a.switchUrl(n.url,n.title).then(function(){e.emit("artplayerPluginPlaylist:change",n)})}function v(){var t=f.findIndex(function(t){return t.url===s.src});return i(-1!==t,"Can't find Playlist item"),1===f.length?p(0):p(t+1===f.length?0:t+1)}return d.innerHTML=f.map(function(t,n){return'<div class="artplay-playlist-item" data-option-index="'.concat(n,'">').concat(t.title,"</div>")}).join(""),u(d,"click",function(t){var n=t.target.dataset.optionIndex;n&&Number(n)<=f.length-1&&p(n)}),u(y,"click",function(t){t.target===y&&(y.style.display="none")}),e.on("video:ended",function(){v().then(function(){r(1e3).then(a.play)})}),e.on("afterAttachUrl",function(){var t=f.findIndex(function(t){return t.url===s.src}),n=Array.from(d.children)[t];-1!==t&&n&&l(n,"active")}),{name:"artplayerPluginPlaylist",show:function(){y.style.display="flex"},hide:function(){y.style.display="none"},next:function(){v()},prev:function(){!function(){var t=f.findIndex(function(t){return t.url===s.src});i(-1!==t,"Can't find Playlist item"),1===f.length?p(0):p(t-1==-1?f.length-1:t-1)}()}}}}});
|