UNPKG

videojs-playlist-ui

Version:
7 lines 7.29 kB
/** * videojs-playlist-ui * @version 3.0.8 * @copyright 2018 Brightcove, Inc. * @license Apache-2.0 */ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(require("video.js")):"function"==typeof define&&define.amd?define(["video.js"],t):t(e.videojs)}(this,function(c){"use strict";c=c&&c.hasOwnProperty("default")?c["default"]:c;var e,t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n={},i=(Object.freeze||Object)({"default":n}),l=i&&n||i,a=void 0!==t?t:"undefined"!=typeof window?window:{};"undefined"!=typeof document?e=document:(e=a["__GLOBAL_DOCUMENT_CACHE@4"])||(e=a["__GLOBAL_DOCUMENT_CACHE@4"]=l);var s,d=e,r="undefined"!=typeof window?window:void 0!==t?t:"undefined"!=typeof self?self:{},o=(function(){function u(e){this.value=e}function e(a){var s,r;function o(e,t){try{var n=a[e](t),i=n.value;i instanceof u?Promise.resolve(i.value).then(function(e){o("next",e)},function(e){o("throw",e)}):p(n.done?"return":"normal",n.value)}catch(l){p("throw",l)}}function p(e,t){switch(e){case"return":s.resolve({value:t,done:!0});break;case"throw":s.reject(t);break;default:s.resolve({value:t,done:!1})}(s=s.next)?o(s.key,s.arg):r=null}this._invoke=function e(i,l){return new Promise(function(e,t){var n={key:i,arg:l,resolve:e,reject:t,next:null};r?r=r.next=n:(s=r=n,o(i,l))})},"function"!=typeof a["return"]&&(this["return"]=undefined)}"function"==typeof Symbol&&Symbol.asyncIterator&&(e.prototype[Symbol.asyncIterator]=function(){return this}),e.prototype.next=function(e){return this._invoke("next",e)},e.prototype["throw"]=function(e){return this._invoke("throw",e)},e.prototype["return"]=function(e){return this._invoke("return",e)}}(),function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}),p=function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)},u=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t},h=c.dom||c,f=c.registerPlugin||c.plugin,y=function y(e,t){for(var n=0,i=e.length;n<i;n++)if(e[n]===t)return n;return-1},m={className:"vjs-playlist",playOnSelect:!1,supportsCssPointerEvents:((s=d.createElement("x")).style.cssText="pointer-events:auto","auto"===s.style.pointerEvents)},v=function v(e){e.addClass("vjs-selected")},w=function w(e){e.removeClass("vjs-selected"),e.thumbnail&&h.removeClass(e.thumbnail,"vjs-playlist-now-playing")},C=function C(e){e.addClass("vjs-up-next")},_=function _(e){e.removeClass("vjs-up-next")},j=function j(e){if(!e){var t=d.createElement("div");return t.className="vjs-playlist-thumbnail vjs-playlist-thumbnail-placeholder",t}var n=d.createElement("picture");if(n.className="vjs-playlist-thumbnail","string"==typeof e){var i=d.createElement("img");i.src=e,i.alt="",n.appendChild(i)}else{for(var l=0;l<e.length-1;l++){var a=e[l],s=d.createElement("source");for(var r in a)s[r]=a[r];n.appendChild(s)}var o=e[e.length-1],p=d.createElement("img");for(var u in p.alt="",o)p[u]=o[u];n.appendChild(p)}return n},b=c.getComponent("Component"),E=function(l){function a(e,t,n){if(o(this,a),!t.item)throw new Error("Cannot construct a PlaylistMenuItem without an item option");var i=u(this,l.call(this,e,t));return i.item=t.item,i.playOnSelect=n.playOnSelect,i.emitTapEvents(),i.on(["click","tap"],i.switchPlaylistItem_),i.on("keydown",i.handleKeyDown_),i}return p(a,l),a.prototype.handleKeyDown_=function e(e){13!==e.which&&32!==e.which||this.switchPlaylistItem_()},a.prototype.switchPlaylistItem_=function t(e){this.player_.playlist.currentItem(y(this.player_.playlist(),this.item)),this.playOnSelect&&this.player_.play()},a.prototype.createEl=function n(){var e=d.createElement("li"),t=this.options_.item;if(e.className="vjs-playlist-item",e.setAttribute("tabIndex",0),this.thumbnail=j(t.thumbnail),e.appendChild(this.thumbnail),t.duration){var n=d.createElement("time"),i=c.formatTime(t.duration);n.className="vjs-playlist-duration",n.setAttribute("datetime","PT0H0M"+t.duration+"S"),n.appendChild(d.createTextNode(i)),e.appendChild(n)}var l=d.createElement("span"),a=this.localize("Now Playing");l.className="vjs-playlist-now-playing-text",l.appendChild(d.createTextNode(a)),l.setAttribute("title",a),this.thumbnail.appendChild(l);var s=d.createElement("div");s.className="vjs-playlist-title-container",this.thumbnail.appendChild(s);var r=d.createElement("span"),o=this.localize("Up Next");r.className="vjs-up-next-text",r.appendChild(d.createTextNode(o)),r.setAttribute("title",o),s.appendChild(r);var p=d.createElement("cite"),u=t.name||this.localize("Untitled Video");return p.className="vjs-playlist-name",p.appendChild(d.createTextNode(u)),p.setAttribute("title",u),s.appendChild(p),e},a}(b),g=function(i){function l(e,t){if(o(this,l),!e.playlist)throw new Error("videojs-playlist is required for the playlist component");var n=u(this,i.call(this,e,t));return n.items=[],t.supportsCssPointerEvents&&n.addClass("vjs-csspointerevents"),n.createPlaylist_(),c.browser.TOUCH_ENABLED||n.addClass("vjs-mouse"),e.on(["loadstart","playlistchange"],function(e){n.update()}),e.on("adstart",function(){n.addClass("vjs-ad-playing")}),e.on("adend",function(){n.removeClass("vjs-ad-playing")}),n}return p(l,i),l.prototype.createEl=function e(){var e=this.options_;if(e.el)return e.el;var t=d.createElement("ol");return t.className=e.className,e.el=t},l.prototype.createPlaylist_=function t(){var e=this.player_.playlist()||[],t=this.el_.querySelector(".vjs-playlist-item-list"),n=this.el_.querySelector(".vjs-playlist-ad-overlay");t||((t=d.createElement("ol")).className="vjs-playlist-item-list",this.el_.appendChild(t));for(var i=0;i<this.items.length;i++)t.removeChild(this.items[i].el_);for(var l=this.items.length=0;l<e.length;l++){var a=new E(this.player_,{item:e[l]},this.options_);this.items.push(a),t.appendChild(a.el_)}n||((n=d.createElement("li")).className="vjs-playlist-ad-overlay"),t.appendChild(n);var s=this.player_.playlist.currentItem();if(this.items.length&&0<=s){v(this.items[s]);var r=this.items[s].$(".vjs-playlist-thumbnail");r&&h.addClass(r,"vjs-playlist-now-playing")}},l.prototype.update=function n(){var e=this.player_.playlist();if(this.items.length===e.length){for(var t=0;t<this.items.length;t++)if(this.items[t].item!==e[t])return void this.createPlaylist_();for(var n=this.player_.playlist.currentItem(),i=0;i<this.items.length;i++){var l=this.items[i];i===n?(v(l),d.activeElement!==l.el()&&h.addClass(l.thumbnail,"vjs-playlist-now-playing"),_(l)):i===n+1?(w(l),C(l)):(w(l),_(l))}}else this.createPlaylist_()},l}(b),N=function N(e){var t=void 0,n=void 0;if(!this.playlist)throw new Error("videojs-playlist is required for the playlist component");"undefined"!=typeof r.HTMLElement&&e instanceof r.HTMLElement||e&&1===e.nodeType?(n=e,t=c.mergeOptions(m)):(t=c.mergeOptions(m,e),n=d.querySelector("."+t.className)),t.el=n,this.playlistMenu=new g(this,t)};c.registerComponent("PlaylistMenu",g),c.registerComponent("PlaylistMenuItem",E),f("playlistUi",N)});