| 9 | }; |
| 10 | |
| 11 | class QualitySelectorControllBar extends videojs.getComponent('Button') { |
| 12 | constructor(player: any, options?: any) { |
| 13 | super(player, options); |
| 14 | this.addClass('vjs-quality-selector flex justify-center items-center'); |
| 15 | |
| 16 | const iconElement = videojs.dom.createEl('i', { |
| 17 | className: 'vjs-icon-hd text-xl', |
| 18 | }); |
| 19 | this.el().appendChild(iconElement); |
| 20 | |
| 21 | const dropUpMenu = videojs.dom.createEl('div', { |
| 22 | className: 'vjs-custom-dropup-menu absolute hidden', |
| 23 | }); |
| 24 | |
| 25 | dropUpMenu.innerHTML = ` |
| 26 | <ul class="bg-white dark:bg-gray-800 shadow-lg rounded-md mt-1"> |
| 27 | <li class="px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-700 cursor-pointer text-black dark:text-white" data-quality="1080">1080p</li> |
| 28 | <li class="px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-700 cursor-pointer text-black dark:text-white" data-quality="720">720p</li> |
| 29 | <li class="px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-700 cursor-pointer text-black dark:text-white" data-quality="360">360p</li> |
| 30 | </ul> |
| 31 | `; |
| 32 | |
| 33 | const dropUpMenuElement = this.el().appendChild(dropUpMenu) as HTMLElement; |
| 34 | |
| 35 | this.on('click', () => { |
| 36 | const isVisible = dropUpMenuElement.style.display === 'block'; |
| 37 | dropUpMenuElement.style.display = isVisible ? 'none' : 'block'; |
| 38 | }); |
| 39 | this.on('touchend', (e: any) => { |
| 40 | e.preventDefault(); |
| 41 | const isVisible = dropUpMenuElement.style.display === 'block'; |
| 42 | dropUpMenuElement.style.display = isVisible ? 'none' : 'block'; |
| 43 | }); |
| 44 | dropUpMenuElement.querySelectorAll('li').forEach((item) => { |
| 45 | item.addEventListener('click', (e: any) => { |
| 46 | e.stopPropagation(); //prevent bubbling up |
| 47 | const quality = e.target.getAttribute('data-quality'); |
| 48 | const urlParams = new URLSearchParams(window.location.search); |
| 49 | if (quality !== urlParams.get('quality')) { |
| 50 | changeVideoQuality(quality, player); |
| 51 | } |
| 52 | dropUpMenuElement.style.display = 'none'; |
| 53 | }); |
| 54 | item.addEventListener('touchend', (e: any) => { |
| 55 | const quality = e.target.getAttribute('data-quality'); |
| 56 | if (quality) { |
| 57 | changeVideoQuality(quality, player); |
| 58 | } |
| 59 | dropUpMenuElement.style.display = 'none'; |
| 60 | dropUpMenuElement.style.display = 'none'; |
| 61 | }); |
| 62 | }); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | if (typeof window !== 'undefined') { |
| 67 | // @ts-ignore |
nothing calls this directly
no outgoing calls
no test coverage detected