3 lines
6.1 KiB
JavaScript
3 lines
6.1 KiB
JavaScript
/*! @name videojs-playlist-ui @version 3.5.2 @license Apache-2.0 */
|
|
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("global/document"),require("video.js")):"function"==typeof define&&define.amd?define(["global/document","video.js"],e):t.videojsPlaylistUi=e(t.document,t.videojs)}(this,function(t,e){"use strict";function i(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e}t=t&&t.hasOwnProperty("default")?t.default:t;var l,s=(e=e&&e.hasOwnProperty("default")?e.default:e).dom||e,a=e.registerPlugin||e.plugin,n={className:"vjs-playlist",playOnSelect:!1,supportsCssPointerEvents:((l=t.createElement("x")).style.cssText="pointer-events:auto","auto"===l.style.pointerEvents)},r=function(t){t.addClass("vjs-selected")},o=function(t){t.removeClass("vjs-selected"),t.thumbnail&&s.removeClass(t.thumbnail,"vjs-playlist-now-playing")},p=function(t){t.removeClass("vjs-up-next")},d=e.getComponent("Component"),c=function(l){function s(t,e,i){var s;if(!e.item)throw new Error("Cannot construct a PlaylistMenuItem without an item option");return(s=l.call(this,t,e)||this).item=e.item,s.playOnSelect=i.playOnSelect,s.emitTapEvents(),s.on(["click","tap"],s.switchPlaylistItem_),s.on("keydown",s.handleKeyDown_),s}i(s,l);var a=s.prototype;return a.handleKeyDown_=function(t){13!==t.which&&32!==t.which||this.switchPlaylistItem_()},a.switchPlaylistItem_=function(t){this.player_.playlist.currentItem(function(t,e){for(var i=0,l=t.length;i<l;i++)if(t[i]===e)return i;return-1}(this.player_.playlist(),this.item)),this.playOnSelect&&this.player_.play()},a.createEl=function(){var i=t.createElement("li"),l=this.options_.item;"object"==typeof l.data&&Object.keys(l.data).forEach(function(t){var e=l.data[t];i.dataset[t]=e});if(i.className="vjs-playlist-item",i.setAttribute("tabIndex",0),this.thumbnail=function(e){if(!e){var i=t.createElement("div");return i.className="vjs-playlist-thumbnail vjs-playlist-thumbnail-placeholder",i}var l=t.createElement("picture");if(l.className="vjs-playlist-thumbnail","string"==typeof e){var s=t.createElement("img");s.src=e,s.alt="",l.appendChild(s)}else{for(var a=0;a<e.length-1;a++){var n=e[a],r=t.createElement("source");for(var o in n)r[o]=n[o];l.appendChild(r)}var p=e[e.length-1],d=t.createElement("img");for(var c in d.alt="",p)d[c]=p[c];l.appendChild(d)}return l}(l.thumbnail),i.appendChild(this.thumbnail),l.duration){var s=t.createElement("time"),a=e.formatTime(l.duration);s.className="vjs-playlist-duration",s.setAttribute("datetime","PT0H0M"+l.duration+"S"),s.appendChild(t.createTextNode(a)),i.appendChild(s)}var n=t.createElement("span"),r=this.localize("Now Playing");n.className="vjs-playlist-now-playing-text",n.appendChild(t.createTextNode(r)),n.setAttribute("title",r),this.thumbnail.appendChild(n);var o=t.createElement("div");o.className="vjs-playlist-title-container",this.thumbnail.appendChild(o);var p=t.createElement("span"),d=this.localize("Up Next");p.className="vjs-up-next-text",p.appendChild(t.createTextNode(d)),p.setAttribute("title",d),o.appendChild(p);var c=t.createElement("cite"),h=l.name||this.localize("Untitled Video");return c.className="vjs-playlist-name",c.appendChild(t.createTextNode(h)),c.setAttribute("title",h),o.appendChild(c),i},s}(d),h=function(l){function a(t,i){var s;if(!t.playlist)throw new Error("videojs-playlist is required for the playlist component");return(s=l.call(this,t,i)||this).items=[],i.horizontal?s.addClass("vjs-playlist-horizontal"):s.addClass("vjs-playlist-vertical"),i.supportsCssPointerEvents&&s.addClass("vjs-csspointerevents"),s.createPlaylist_(),e.browser.TOUCH_ENABLED||s.addClass("vjs-mouse"),s.on(t,["loadstart","playlistchange","playlistsorted"],function(t){s.update()}),s.on(t,"adstart",function(){s.addClass("vjs-ad-playing")}),s.on(t,"adend",function(){s.removeClass("vjs-ad-playing")}),s.on("dispose",function(){s.empty_(),t.playlistMenu=null}),s.on(t,"dispose",function(){s.dispose()}),s}i(a,l);var n=a.prototype;return n.createEl=function(){return s.createEl("div",{className:this.options_.className})},n.empty_=function(){this.items&&this.items.length&&(this.items.forEach(function(t){return t.dispose()}),this.items.length=0)},n.createPlaylist_=function(){var e=this.player_.playlist()||[],i=this.el_.querySelector(".vjs-playlist-item-list"),l=this.el_.querySelector(".vjs-playlist-ad-overlay");i||((i=t.createElement("ol")).className="vjs-playlist-item-list",this.el_.appendChild(i)),this.empty_();for(var a=0;a<e.length;a++){var n=new c(this.player_,{item:e[a]},this.options_);this.items.push(n),i.appendChild(n.el_)}l?i.appendChild(l):((l=t.createElement("li")).className="vjs-playlist-ad-overlay",i.appendChild(l));var o=this.player_.playlist.currentItem();if(this.items.length&&o>=0){r(this.items[o]);var p=this.items[o].$(".vjs-playlist-thumbnail");p&&s.addClass(p,"vjs-playlist-now-playing")}},n.update=function(){var e=this.player_.playlist();if(this.items.length===e.length){for(var i=0;i<this.items.length;i++)if(this.items[i].item!==e[i])return void this.createPlaylist_();for(var l=this.player_.playlist.currentItem(),a=0;a<this.items.length;a++){var n=this.items[a];a===l?(r(n),t.activeElement!==n.el()&&s.addClass(n.thumbnail,"vjs-playlist-now-playing"),p(n)):a===l+1?(o(n),n.addClass("vjs-up-next")):(o(n),p(n))}}else this.createPlaylist_()},a}(d),u=function(t){for(var e=0;e<t.childNodes.length;e++)if(s.isEl(t.childNodes[e]))return!0;return!1},m=function(i){if(!this.playlist)throw new Error("videojs-playlist plugin is required by the videojs-playlist-ui plugin");if(s.isEl(i)&&(e.log.warn('videojs-playlist-ui: Passing an element directly to playlistUi() is deprecated, use the "el" option instead!'),i={el:i}),i=e.mergeOptions(n,i),this.playlistMenu){var l=this.playlistMenu.el();if(l){var a=l.parentNode,r=l.nextSibling;this.playlistMenu.dispose(),s.emptyEl(l),r?a.insertBefore(l,r):a.appendChild(l),i.el=l}}s.isEl(i.el)||(i.el=function(e){for(var i,l=t.querySelectorAll("."+e),s=0;s<l.length;s++)if(!u(l[s])){i=l[s];break}return i}(i.className)),this.playlistMenu=new h(this,i)};return e.registerComponent("PlaylistMenu",h),e.registerComponent("PlaylistMenuItem",c),a("playlistUi",m),m.VERSION="3.5.2",m});
|