1(function () { 2 'use strict'; 3 4 var CONTAINER = 'cf7m-star-rating'; 5 var INPUT_SEL = '[data-cf7m-star-input]'; 6 var STAR_SEL = '.cf7m-star'; 7 var ON_CLASS = 'cf7m-star--on'; 8 9 function getValue(container) { 10 var input = container.querySelector(INPUT_SEL); 11 return input ? parseInt(input.value, 10) || 0 : 0; 12 } 13 14 function setValue(container, value, focusIndex) { 15 var input = container.querySelector(INPUT_SEL); 16 if (input) input.value = value; 17 highlight(container, value); 18 updateRovingTabindex(container, value); 19 if (typeof focusIndex === 'number') { 20 var stars = container.querySelectorAll(STAR_SEL); 21 if (stars[focusIndex]) stars[focusIndex].focus(); 22 } 23 } 24 25 function highlight(container, upTo) { 26 var stars = container.querySelectorAll(STAR_SEL); 27 var n = parseInt(upTo, 10) || 0; 28 stars.forEach(function (star, i) { 29 var on = i + 1 <= n; 30 star.classList.toggle(ON_CLASS, on); 31 star.setAttribute('aria-checked', i + 1 === n ? 'true' : 'false'); 32 }); 33 } 34 35 /** 36 * Roving tabindex: only one button in the group is in the tab order at a 37 * time â the currently-selected one, or the first if nothing selected. 38 */ 39 function updateRovingTabindex(container, value) { 40 var stars = container.querySelectorAll(STAR_SEL); 41 var v = parseInt(value, 10) || 0; 42 var focusable = v > 0 ? v - 1 : 0; 43 stars.forEach(function (star, i) { 44 star.tabIndex = i === focusable ? 0 : -1; 45 }); 46 } 47 48 function initOne(container) { 49 if (container.dataset.cf7mStarInit) return; 50 container.dataset.cf7mStarInit = '1'; 51 52 var stars = container.querySelectorAll(STAR_SEL); 53 var max = stars.length; 54 var val = getValue(container); 55 highlight(container, val); 56 updateRovingTabindex(container, val); 57 58 stars.forEach(function (star, i) { 59 var starValue = i + 1; 60 star.addEventListener('click', function () { 61 setValue(container, starValue); 62 }); 63 star.addEventListener('keydown', function (e) { 64 var current = getValue(container); 65 switch (e.key) { 66 case 'Enter': 67 case ' ': 68 e.preventDefault(); 69 setValue(container, starValue); 70 break; 71 case 'ArrowRight': 72 case 'ArrowUp': 73 e.preventDefault(); 74 setValue(container, Math.min(max, current + 1), Math.min(max, current + 1) - 1); 75 break; 76 case 'ArrowLeft': 77 case 'ArrowDown': 78 e.preventDefault(); 79 if (current > 0) { 80 var next = current - 1; 81 setValue(container, next, next > 0 ? next - 1 : 0); 82 } 83 break; 84 case 'Home': 85 e.preventDefault(); 86 setValue(container, 0, 0); 87 break; 88 case 'End': 89 e.preventDefault(); 90 setValue(container, max, max - 1); 91 break; 92 } 93 }); 94 star.addEventListener('mouseenter', function () { 95 highlight(container, starValue); 96 }); 97 }); 98 99 container.addEventListener('mouseleave', function () { 100 highlight(container, getValue(container)); 101 }); 102 } 103 104 function init() { 105 document.querySelectorAll('.' + CONTAINER).forEach(initOne); 106 } 107 108 function onReady() { 109 init(); 110 if (typeof jQuery !== 'undefined') { 111 jQuery(document).on( 112 'wpcf7mailsent wpcf7invalid wpcf7spam wpcf7mailfailed wpcf7submit', 113 function () { 114 setTimeout(init, 100); 115 } 116 ); 117 } 118 } 119 120 if (document.readyState === 'loading') { 121 document.addEventListener('DOMContentLoaded', onReady); 122 } else { 123 onReady(); 124 } 125})();
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.