mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-12 06:26:16 -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)["artplayer-plugin-playlist"]=n()}(this,function(){"use strict";function t(e){var t=e.constructor.utils,n=t.append,i=t.errorHandle,r=t.sleep,l=t.inverseClass,a=e.player,o=e.events.proxy,u=e.template,s=u.$player,c=u.$video,y=n(s,'\n <div class="artplay-playlist">\n <div class="artplay-playlist-inner"></div>\n </div>\n '),d=[],f=y.querySelector(".artplay-playlist-inner");function p(t){var n=d[t];return a.switchUrl(n.url,n.title).then(function(){e.emit("artplayerPluginPlaylist:change",n)})}function v(){var t=d.findIndex(function(t){return t.url===c.src});return i(-1!==t,"Can't find Playlist item"),1===d.length?p(0):p(t+1===d.length?0:t+1)}return o(f,"click",function(t){var n=t.target.dataset.optionIndex;n&&Number(n)<=d.length-1&&p(n)}),o(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=d.findIndex(function(t){return t.url===c.src}),n=Array.from(f.children)[t];-1!==t&&n&&l(n,"active")}),{name:"artplayerPluginPlaylist",load:function(t){i(Array.isArray(t),"Playlist is not an array type"),i(0<t.length,"Playlist cannot be empty"),d=t.map(function(t){return i(t.url,"Playlist items require url attribute"),i(t.title,"Playlist items require title attribute"),t}),f.innerHTML=d.map(function(t,n){return'<div class="artplay-playlist-item" data-option-index="'.concat(n,'">').concat(t.title,"</div>")}).join("")},show:function(){y.style.display="flex"},hide:function(){y.style.display="none"},next:function(){v()},prev:function(){!function(){var t=d.findIndex(function(t){return t.url===c.src});i(-1!==t,"Can't find Playlist item"),1===d.length?p(0):p(t-1==-1?d.length-1:t-1)}()}}}return window.artplayerPluginPlaylist=t});
|