1// https://gist.github.com/alirezas/c4f9f43e9fe1abba9a4824dd6fc60a55 2function fadeIn(el, display) { 3 function fade() { 4 var val = parseFloat(el.style.opacity) 5 if (!((val += 0.05) > 1)) { 6 el.style.opacity = val 7 requestAnimationFrame(fade) 8 } 9 } 10 el.style.opacity = 0 11 el.style.display = display || 'block' 12 fade() 13} 14function fadeOut(el) { 15 function fade() { 16 if ((el.style.opacity -= 0.05) < 0) { 17 el.style.display = 'none' 18 } else { 19 requestAnimationFrame(fade) 20 } 21 } 22 el.style.opacity = 1 23 fade() 24} 25 26// Close the parent .announcement when a button is clicked 27// And store the closed announcement ID in a cookie 28// so we don't show it again to the same user 29function closeHandler(event) { 30 var announcement = event.target.closest('.announcement') 31 var announcementId = announcement.getAttribute('data-announcement-id') 32 var expireDays = parseInt(announcement.getAttribute('data-expire-days') || 365) 33 var cookieName = 'announcements_dismiss' 34 var cookieValue = Cookies.get(cookieName) 35 36 // Pause video iframes inside the announcement (if any) 37 // Requires the site calling this script to be under HTTPS 38 announcement.querySelectorAll('iframe').forEach(function (iframe) { 39 var isVimeo = iframe.src.search('vimeo') !== -1 40 var msg 41 if (isVimeo) { 42 msg = { method: 'pause' } 43 } else { 44 msg = { event: 'command', func: 'pauseVideo' } 45 } 46 iframe.contentWindow.postMessage(JSON.stringify(msg), '*') 47 }) 48 49 // Parse the cookie as an array separated by _ 50 // and add the current announcement ID to the dismissed list 51 cookieValue = cookieValue ? cookieValue.split('_') : [] 52 if (cookieValue.indexOf(announcementId) === -1) { 53 cookieValue.push(announcementId) 54 } 55 cookieValue = cookieValue.join('_') 56 Cookies.set(cookieName, cookieValue, { expires: expireDays }) 57 58 // Close the announcement with a fade 59 fadeOut(announcement) 60} 61 62window.addEventListener('DOMContentLoaded', function () { 63 // Show announcements (include delay as needed) 64 document.querySelectorAll('.announcement').forEach(function (announcement) { 65 var delay = parseInt(announcement.getAttribute('data-appearance-delay') || 0) 66 setTimeout(function () { fadeIn(announcement) }, delay) 67 }) 68 69 // Bind the close buttons on each announcement 70 document.querySelectorAll('.close-announcement, [data-announcement-close]').forEach(function (button) { 71 button.addEventListener('click', closeHandler) 72 }) 73})
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.