1/** 2 * Job share link: toggle social popover (LinkedIn, Facebook, Twitter). 3 */ 4(function () { 5 'use strict'; 6 7 var ROOT_SELECTOR = '.rgp-job-share'; 8 var TRIGGER_SELECTOR = '.rgp-job-share__trigger'; 9 var OPEN_CLASS = 'rgp-job-share--open'; 10 var BOUND_ATTR = 'data-rgp-job-share-bound'; 11 12 function closeShare(root) { 13 if (!root) { 14 return; 15 } 16 var trigger = root.querySelector(TRIGGER_SELECTOR); 17 var popover = root.querySelector('.rgp-job-share__popover'); 18 root.classList.remove(OPEN_CLASS); 19 if (trigger) { 20 trigger.setAttribute('aria-expanded', 'false'); 21 } 22 if (popover) { 23 popover.hidden = true; 24 } 25 } 26 27 function closeAllShares(except) { 28 document.querySelectorAll(ROOT_SELECTOR + '.' + OPEN_CLASS).forEach(function (root) { 29 if (except && root === except) { 30 return; 31 } 32 closeShare(root); 33 }); 34 } 35 36 function openShare(root) { 37 var trigger = root.querySelector(TRIGGER_SELECTOR); 38 var popover = root.querySelector('.rgp-job-share__popover'); 39 if (!trigger || !popover) { 40 return; 41 } 42 closeAllShares(root); 43 root.classList.add(OPEN_CLASS); 44 trigger.setAttribute('aria-expanded', 'true'); 45 popover.hidden = false; 46 } 47 48 function toggleShare(root) { 49 if (root.classList.contains(OPEN_CLASS)) { 50 closeShare(root); 51 } else { 52 openShare(root); 53 } 54 } 55 56 function onTriggerClick(e) { 57 var trigger = e.currentTarget; 58 var root = trigger.closest(ROOT_SELECTOR); 59 if (!root) { 60 return; 61 } 62 e.preventDefault(); 63 e.stopPropagation(); 64 toggleShare(root); 65 } 66 67 function bindTriggers(scope) { 68 var root = scope && scope.querySelectorAll ? scope : document; 69 root.querySelectorAll(TRIGGER_SELECTOR + ':not([' + BOUND_ATTR + '])').forEach(function (trigger) { 70 trigger.setAttribute(BOUND_ATTR, '1'); 71 trigger.addEventListener('click', onTriggerClick); 72 }); 73 } 74 75 document.addEventListener('click', function (e) { 76 if (e.target.closest(TRIGGER_SELECTOR)) { 77 return; 78 } 79 if (!e.target.closest(ROOT_SELECTOR)) { 80 closeAllShares(null); 81 } 82 }); 83 84 document.addEventListener('keydown', function (e) { 85 if (e.key === 'Escape') { 86 closeAllShares(null); 87 } 88 }); 89 90 if (document.readyState === 'loading') { 91 document.addEventListener('DOMContentLoaded', function () { 92 bindTriggers(document); 93 }); 94 } else { 95 bindTriggers(document); 96 } 97 98 if (typeof MutationObserver !== 'undefined') { 99 var debounceTimer; 100 var observer = new MutationObserver(function () { 101 clearTimeout(debounceTimer); 102 debounceTimer = setTimeout(function () { 103 bindTriggers(document); 104 }, 100); 105 }); 106 observer.observe(document.documentElement, { childList: true, subtree: true }); 107 } 108})();
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.