mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-08 19:06:15 -08:00
9 lines
2.2 KiB
JavaScript
9 lines
2.2 KiB
JavaScript
/*!
|
|
* artplayer-plugin-playlist.js v3.1.19
|
|
* 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(t){return function(n){var e=n.constructor.utils,r=e.append,i=e.errorHandle,a=e.sleep,l=e.inverseClass,o=n.player,s=n.events.proxy,u=n.template,c=u.$player,y=u.$video,f=r(c,'\n <div class="artplayer-playlist">\n <div class="artplayer-playlist-inner artplayer-backdrop-filter"></div>\n </div>\n ');i(Array.isArray(t),"Playlist is not an array type"),i(t.length>0,"Playlist cannot be empty");var p=t.map((function(t){return i(t.url,"Playlist items require url attribute"),i(t.title,"Playlist items require title attribute"),t})),d=f.querySelector(".artplayer-playlist-inner");function v(t){var e=p[t];return o.switchUrl(e.url,e.title).then((function(){n.emit("artplayerPluginPlaylist:change",e)}))}function h(){var t=p.findIndex((function(t){return t.url===y.src}));return i(-1!==t,"Can't find Playlist item"),1===p.length?v(0):v(t+1===p.length?0:t+1)}return d.innerHTML=p.map((function(t,n){return'<div class="artplayer-playlist-item" data-option-index="'.concat(n,'">').concat(t.title,"</div>")})).join(""),s(d,"click",(function(t){var n=t.target.dataset.optionIndex;n&&Number(n)<=p.length-1&&v(n)})),s(f,"click",(function(t){t.target===f&&c.classList.remove("artplayer-playlist-show")})),n.on("video:ended",(function(){h().then((function(){a(1e3).then((function(){o.play=!0}))}))})),n.on("afterAttachUrl",(function(){var t=p.findIndex((function(t){return t.url===y.src})),n=Array.from(d.children)[t];-1!==t&&n&&l(n,"active")})),{name:"artplayerPluginPlaylist",show:function(){c.classList.add("artplayer-playlist-show")},hide:function(){c.classList.remove("artplayer-playlist-show")},next:function(){h()},prev:function(){var t;t=p.findIndex((function(t){return t.url===y.src})),i(-1!==t,"Can't find Playlist item"),1===p.length?v(0):v(t-1==-1?p.length-1:t-1)}}}}}));
|