domUtils.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // control panel hide/show
  2. // shortcuts
  3. let domUtils = function () {
  4. let optionPanel = document.getElementById('panel')
  5. let progres = document.getElementById('controls')
  6. function hidepanel(bool) {
  7. if (!bool) {
  8. optionPanel.style.right = "15px"
  9. optionPanel.style.opacity = 1
  10. progres.style.opacity = 1
  11. } else {
  12. optionPanel.style.right = "-315px"
  13. optionPanel.style.opacity = 0
  14. progres.style.opacity = 0
  15. }
  16. }
  17. function miam(mess, type, duration = 1000, pos = "top-left") {
  18. bulmaToast.toast({
  19. message: mess,
  20. type: type,
  21. dismissible: true,
  22. duration: duration,
  23. position: pos,
  24. "single": false,
  25. // animate: { in: 'fadeIn', out: 'fadeOut' }
  26. })
  27. }
  28. document.addEventListener("keydown", function (event) {
  29. // console.log("event.key", event.key)
  30. let usedKeys = ["p", " ", "m"]
  31. if (usedKeys.indexOf(event.key) !== -1) { // touche - debug info
  32. event.preventDefault();
  33. if (event.key == "m") { // m for muted
  34. if (!videoPlayer.muted) videoPlayer.muted = true
  35. else videoPlayer.muted = false
  36. // notif("success", "mute", videoPlayer.muted)
  37. miam(videoPlayer.muted ? "Mute" : "Unmute", 'is-primary')
  38. }
  39. if (event.key == " ") { // space for pause
  40. if (!videoPlayer.paused) {
  41. videoPlayer.pause()
  42. miam('Video Paused.', 'is-primary')
  43. }
  44. else {
  45. videoPlayer.play()
  46. miam('Video is playing.', 'is-primary')
  47. }
  48. }
  49. if (event.key === "p") { // P for panel
  50. event.preventDefault();
  51. if (optionPanel.style.opacity == 0) hidepanel(false)
  52. else hidepanel(true)
  53. }
  54. }
  55. });
  56. function centerVideo(){
  57. let wrapLoca = document.getElementById('wrap')
  58. wrapLoca.style.left = `calc(50vw - ${wrapLoca.offsetWidth / 2}px)`
  59. wrapLoca.style.top = `calc(50vh - ${wrapLoca.offsetHeight / 2}px)`
  60. localStorage.setItem('playerTop', wrapLoca.style.top);
  61. localStorage.setItem('playerLeft', wrapLoca.style.left);
  62. }
  63. miam("Press 'P' to open the Menu.", 'is-info', 4000, "top-center")
  64. }
  65. export { domUtils };