{"version":3,"file":"jobs.min.js","sources":["scripts/jobs.min.js"],"sourcesContent":["/**************************************************************************\r\nName: jobs.js\r\nDescription: Scripts for careers page; mainly covers YouTube video embedding.\r\nDate Created: 2022-08-17 by Owen Haggerty\r\nModified: \r\n**************************************************************************/\r\nconst playIconSvg = '';\r\n\r\nvar ytPlayer;\r\n\r\nwindow.addEventListener(\"load\",function(){\r\n\t/* Initializes the video player by loading the YouTube api */\r\n\tlet apiImportTag = document.createElement(\"script\");\r\n\tapiImportTag.src = \"https://www.youtube.com/iframe_api\";\r\n\tdocument.body.appendChild(apiImportTag);\r\n\t//When the youtube script is loaded onYouTubeIframeAPIReady will be called automatically\r\n});\r\n\r\nfunction addVideoToList(title, video){\r\n\t/* Adds an element to the video list */\r\n\t//Check that the video thumbnail can be fetched\r\n\tlet imgUrl = getVideoThumbnailURL(video, getWebp=true);\r\n\tif(imgUrl === \"\") return;\r\n\t//Add the button wrapper\r\n\tlet wrapper = document.createElement(\"button\");\r\n\twrapper.setAttribute(\"type\",\"button\");\r\n\twrapper.dataset.video = video;\r\n\twrapper.dataset.name = title;\r\n\twrapper.classList.add(\"careers-video-list-entry\");\r\n\twrapper.addEventListener(\"click\", videoListClickListener);\r\n\tdocument.querySelector(\".careers-video-list\").appendChild(wrapper);\r\n\t//Add the thumbnail image\r\n\tlet thumbWrapper = document.createElement(\"div\");\r\n\tthumbWrapper.classList.add(\"careers-video-list-thumbnail-wrapper\");\r\n\twrapper.appendChild(thumbWrapper);\r\n\tlet thumb = document.createElement(\"img\");\r\n\tthumb.src = imgUrl;\r\n\tthumb.setAttribute(\"alt\",title + \" thumbnail image\");\r\n\tthumb.classList.add(\"careers-video-list-thumbnail\");\r\n\tthumb.addEventListener(\"load\",checkImageLoad);\r\n\tthumbWrapper.appendChild(thumb);\r\n\t//Add the overlay\r\n\tlet overlay = document.createElement(\"div\");\r\n\toverlay.classList.add(\"careers-video-list-overlay\");\r\n\twrapper.appendChild(overlay);\r\n\t//Add the play icon\r\n\tlet playIcon = document.createElement(\"div\");\r\n\twrapper.appendChild(playIcon);\r\n\tplayIcon.outerHTML = playIconSvg;\r\n\t//Add the title text\r\n\tlet vidTitle = document.createElement(\"div\");\r\n\tvidTitle.textContent = title;\r\n\tvidTitle.classList.add(\"careers-video-list-title\");\r\n\twrapper.appendChild(vidTitle);\r\n}\r\n\r\nfunction getVideoIdFromUrl(videoUrl){\r\n\t/* Gets the video ID from a YouTube url */\r\n\tlet idIndex = /v=[A-Za-z0-9\\-_]{11}/.exec(videoUrl);\r\n\tif(idIndex === null){\r\n\t\t//No match for the video id was found\r\n\t\treturn \"\";\r\n\t}\r\n\treturn videoUrl.substr(idIndex.index + 2, 11);\r\n}\r\n\r\nfunction getVideoThumbnailURL(video, getWebp=false){\r\n\t/* Takes a video ID or URL and returns the video's thumbnail URL (or an empty string if the thumbnail URL could not be found)*/\r\n\tlet videoID = video;\r\n\tif(!/^[A-Za-z0-9\\-_]{11}$/.test(video)){\r\n\t\t//The video URL was passed in, need to extract the ID\r\n\t\tvideoID = getVideoIdFromUrl(video);\r\n\t\tif(videoID === \"\") return \"\";\r\n\t}\r\n\t//Assemble and return the image url\r\n\tlet imgURL = \"http://img.youtube.com/\"\r\n\tif(getWebp === true) imgURL += \"vi_webp/\" + videoID + \"/maxresdefault.webp\";\r\n\telse imgURL += \"vi/\" + videoID + \"/maxresdefault.jpg\";\r\n\treturn imgURL;\r\n}\r\n\r\nfunction checkImageLoad(event){\r\n\t/* Listener for image loading. Replaces the image with the .jpg version if it failed */\r\n\tlet img = event.target;\r\n\timg.removeEventListener(\"error\",checkImageLoad);\r\n\t//Check if the default missing image was loaded\r\n\tif(!this.complete || (this.naturalWidth === 120 && this.naturalHeight === 90)){\r\n\t\tlet videoListEntry = img.parentElement.parentElement;\r\n\t\tlet jpgURL = getVideoThumbnailURL(videoListEntry.dataset.video, getWebp=false);\r\n\t\tif(jpgURL !== \"\") img.src = jpgURL;\r\n\t}\r\n}\r\n\r\nfunction onYouTubeIframeAPIReady(){\r\n\t/* Called when the YouTube api loads, initializes the video thumbnails and click listeners and creates a youtube player */\r\n\tytPlayer = new YT.Player(\"careersVideo\", {\r\n\t\theight: 675,\r\n\t\twidth: 1200,\r\n\t\tplayerVars: {rel: 0},\r\n\t\tevents: {\r\n\t\t\t\"onReady\": function(){\r\n\t\t\t\t/* Continues the initialization once the player is ready */\r\n\t\t\t\t//Add the click listener to the video overlay\r\n\t\t\t\tdocument.querySelector(\".careers-video-overlay\").addEventListener(\"click\",playVideo);\r\n\t\t\t\tif(videoEmbedIDs !== undefined && videoEmbedIDs.length !== undefined && videoEmbedIDs.length > 0){\r\n\t\t\t\t\t//Initialize the video list\r\n\t\t\t\t\tfor(let i=0; i