(()=>{document.addEventListener("DOMContentLoaded",(()=>{t()}));const{__:__,_n:_n}=wp.i18n,e={ /* translators: text read by a screen reader when a warning icon is displayed in front of an error message. */ warning:__("Warning.","jetpack-forms"), /* translators: error message shown when one or more fields of the form are invalid. */ invalidForm:__("Please make sure all fields are valid.","jetpack-forms"), /* translators: error message shown when a multiple choice field requires at least one option to be selected. */ checkboxMissingValue:__("Please select at least one option.","jetpack-forms"), /* translators: error message shown when a user enters an invalid date */ invalidDate:__("The date is not valid.","jetpack-forms"), /* translators: text read by a screen reader when a form is being submitted */ submittingForm:__("Submitting form","jetpack-forms"), /* translators: generic error message */ genericError:__("Please correct this field","jetpack-forms"), /* translators: message displayed when errors need to be fixed. %d is the number of errors. */ errorCount:e=>_n("You need to fix %d error.","You need to fix %d errors.",e,"jetpack-forms")},t=()=>{document.querySelectorAll(".wp-block-jetpack-contact-form-container form.contact-form").forEach(r)},r=e=>{e.hasAttribute("novalidate")||e.setAttribute("novalidate",!0);const t={hasInsetLabel:m(e)};let r={};const o=i=>{i.preventDefault(),a(e)||(L(e,r,t),n(e)?(r={},e.removeEventListener("submit",o),x(e)):r=j(e,t))};e.addEventListener("submit",o)},n=e=>{let t=e.checkValidity();if(!t)return!1;const r=f(e);for(const e of r)if(s(e)&&!d(e))return!1;const n=h(e);for(const e of n)if(!u(e))return!1;return t},a=e=>!0===e.getAttribute("data-submitting"),o=e=>"fieldset"===e.tagName.toLowerCase()&&e.classList.contains("grunion-checkbox-multiple-options"),i=e=>"fieldset"===e.tagName.toLowerCase()&&e.classList.contains("grunion-radio-options"),s=e=>e.hasAttribute("data-required"),c=e=>{return"input"===(t=e).tagName.toLowerCase()&&t.classList.contains("jp-contact-form-date")&&e.value?u(e):e.validity.valid;var t},l=e=>{const t=Array.from(e.querySelectorAll('input[type="radio"]'));return t.length>0&&t.every((e=>e.validity.valid))},d=e=>{if(!s(e))return!0;const t=Array.from(e.querySelectorAll('input[type="checkbox"]'));return t.length>0&&t.some((e=>e.checked))},u=t=>{const r=t.getAttribute("data-format"),n=t.value,a=window.jQuery;if(n&&r&&void 0!==a)try{a.datepicker.parseDate(r,n)}catch(r){return t.setCustomValidity(e.invalidDate),!1}return!0},m=e=>{const t=e.querySelector(".wp-block-jetpack-contact-form");if(!t)return!1;const r=t.classList;return r.contains("is-style-outlined")||r.contains("is-style-animated")},p=e=>e.querySelector('[type="submit"]')||e.querySelector('button:not([type="reset"])'),f=e=>Array.from(e.querySelectorAll(".grunion-checkbox-multiple-options")),h=e=>Array.from(e.querySelectorAll("input.jp-contact-form-date")),b=e=>{const t=C((e=>Array.from(e.elements).filter((e=>!["hidden","submit"].includes(e.type)&&null!==e.offsetParent)))(e)),r={simple:t.default,singleChoice:[],multipleChoice:[]},n=t.radios.reduce(((e,t)=>e.includes(t.name)?e:[...e,t.name]),[]);for(const t of n){const n=e.querySelector(`input[type="radio"][name="${t}"]`);if(n){const e=n.closest("fieldset");e&&r.singleChoice.push(e)}}const a=t.checkboxes.reduce(((e,t)=>e.includes(t.name)?e:[...e,t.name]),[]);for(const t of a){const n=e.querySelector(`input[type="checkbox"][name="${t}"]`);if(n){const e=n.closest("fieldset");e&&r.multipleChoice.push(e)}}return r},v=e=>e.querySelector(".contact-form__error"),y=e=>e.querySelectorAll("[aria-invalid]"),g=t=>{const r=document.createDocumentFragment();return r.appendChild((()=>{const t=document.createElement("span"),r=document.createElement("span"),n=document.createElement("i");return r.textContent=e.warning,r.classList.add("visually-hidden"),n.setAttribute("aria-hidden",!0),t.classList.add("contact-form__warning-icon"),t.appendChild(r),t.appendChild(n),t})()),r.appendChild((e=>{const t=document.createElement("span");return t.textContent=e,t})(t)),r},A=e=>{const t=document.createElement("div");return t.id=e,t.classList.add("contact-form__input-error"),t},C=e=>e.reduce(((e,t)=>{switch(t.type){case"radio":e.radios.push(t);break;case"checkbox":t.name.indexOf("[]")===t.name.length-2?e.checkboxes.push(t):e.default.push(t);break;default:e.default.push(t)}return e}),{default:[],radios:[],checkboxes:[]}),L=(e,t,r)=>{k(e,r);for(const r in t)e.querySelectorAll(`[name="${r}"]`).forEach((e=>e.removeEventListener(t[r][0],t[r][1])))},k=(e,t)=>{q(e),E(e,t)},q=e=>{const t=v(e);t&&t.replaceChildren()},E=(e,t)=>{for(const r of y(e))i(r)||o(r)?S(r):w(r,t)},S=e=>{e.removeAttribute("aria-invalid"),e.removeAttribute("aria-describedby");const t=e.querySelector(".contact-form__input-error");t&&t.replaceChildren()},w=(e,t)=>{e.removeAttribute("aria-invalid"),e.removeAttribute("aria-describedby");const r=e.closest(t.hasInsetLabel?".contact-form__inset-label-wrap":".grunion-field-wrap");if(!r)return;const n=r.querySelector(".contact-form__input-error");n&&n.replaceChildren()},x=e=>{_(e),e.setAttribute("data-submitting",!0),e.submit()},_=t=>{const r=p(t);r&&(r.setAttribute("aria-disabled",!0),r.appendChild((()=>{const t=document.createElement("span"),r=document.createElement("span"),n=document.createElement("span");return r.setAttribute("aria-hidden",!0),r.innerHTML='',n.classList.add("visually-hidden"),n.textContent=e.submittingForm,t.classList.add("contact-form__spinner"),t.appendChild(r),t.appendChild(n),t})()))},j=(e,t)=>(N(e,t),M(e,t)),M=(e,t)=>{let r={};const n=()=>T(e);for(const c of y(e)){let l;l=i(c)&&(a=c,Array.from(a.querySelectorAll('input[type="radio"]')).some((e=>e.hasAttribute("required")||e.hasAttribute("aria-required"))))?$(c,n,e,t):o(c)&&s(c)?D(c,n,e,t):F(c,n,e,t),r={...r,...l}}var a;return r},$=(e,t,r,n)=>{const a={},o=()=>{l(e)?S(e):Z(e,r,n),t()},i=e.querySelectorAll('input[type="radio"]');for(const e of i)e.addEventListener("blur",o),e.addEventListener("change",o),a[e.name]=["blur",o],a[e.name]=["change",o];return a},D=(e,t,r,n)=>{const a={},o=()=>{d(e)?S(e):B(e,r,n),t()},i=e.querySelectorAll('input[type="checkbox"]');for(const e of i)e.addEventListener("blur",o),e.addEventListener("change",o),a[e.name]=["blur",o],a[e.name]=["change",o];return a},F=(e,t,r,n)=>{const a=e.validity.valueMissing,o={},i=()=>{c(e)?w(e,n):I(e,r,n),t()},s=()=>{e.validity.valueMissing?I(e,r,n):w(e,n),t()};return e.addEventListener("blur",i),o[e.name]=["blur",i],a&&(e.addEventListener("input",s),o[e.name]=["input",s]),o},N=(e,t)=>{const r=V(e,t);P(e,r)},P=(t,r,n={})=>{let a=v(t);if(!a){a=(()=>{const e=document.createElement("div");return e.classList.add("contact-form__error"),e})();const e=p(t);e?e.parentNode.insertBefore(a,e):t.appendChild(a)}const{disableLiveRegion:s}=n;s?(a.removeAttribute("aria-live"),a.removeAttribute("role")):(a.setAttribute("aria-live","assertive"),a.setAttribute("role","alert"));const c=r.length,l=[e.invalidForm];c>0&&l.push(e.errorCount(c).replace("%d",c)),a.appendChild(g(l.join(" "))),c>0&&a.appendChild(((e,t)=>{const r=document.createElement("ul");for(const n of t){const t=n.id;if(!t)continue;let a;if(a=o(n)||i(n)?n.querySelector("legend"):e.querySelector(`label[for="${t}"]`),!a)continue;const s=document.createElement("li"),c=document.createElement("a");c.textContent=a.innerText,c.setAttribute("href",`#${t}`),s.appendChild(c),r.appendChild(s)}return r})(t,r))},T=e=>{q(e),n(e)||P(e,y(e),{disableLiveRegion:!0})},V=(e,t)=>{const r=[],{simple:n,singleChoice:a,multipleChoice:o}=b(e);for(const a of n)c(a)||(I(a,e,t),r.push(a));for(const n of a)l(n)||(Z(n,e,t),r.push(n));for(const n of o)d(n)||(B(n,e,t),r.push(n));return r},I=(e,t,r)=>{const n=`${e.name}-error`;let a=t.querySelector(`#${n}`);if(!a){a=A(n);const t=e.closest(r.hasInsetLabel?".contact-form__inset-label-wrap":".grunion-field-wrap");t&&t.appendChild(a)}a.replaceChildren(g(e.validationMessage)),e.setAttribute("aria-invalid","true"),e.setAttribute("aria-describedby",n)},Z=(e,t,r)=>{O(e,t,r)},B=(t,r,n)=>{O(t,r,{...n,message:e.checkboxMissingValue})},O=(t,r,n)=>{const a=t.querySelector("input");if(!a)return;const o=`${a.name.replace("[]","")}-error`;let i=r.querySelector(`#${o}`);i||(i=A(o)),i.replaceChildren(g(a.validationMessage||n.message||e.genericError)),t.appendChild(i),t.setAttribute("aria-invalid","true"),t.setAttribute("aria-describedby",o)}})();; /** * Observe how the user enters content into the comment form in order to determine whether it's a bot or not. * * Note that no actual input is being saved here, only counts and timings between events. */ ( function() { // Passive event listeners are guaranteed to never call e.preventDefault(), // but they're not supported in all browsers. Use this feature detection // to determine whether they're available for use. var supportsPassive = false; try { var opts = Object.defineProperty( {}, 'passive', { get : function() { supportsPassive = true; } } ); window.addEventListener( 'testPassive', null, opts ); window.removeEventListener( 'testPassive', null, opts ); } catch ( e ) {} function init() { var input_begin = ''; var keydowns = {}; var lastKeyup = null; var lastKeydown = null; var keypresses = []; var modifierKeys = []; var correctionKeys = []; var lastMouseup = null; var lastMousedown = null; var mouseclicks = []; var mousemoveTimer = null; var lastMousemoveX = null; var lastMousemoveY = null; var mousemoveStart = null; var mousemoves = []; var touchmoveCountTimer = null; var touchmoveCount = 0; var lastTouchEnd = null; var lastTouchStart = null; var touchEvents = []; var scrollCountTimer = null; var scrollCount = 0; var correctionKeyCodes = [ 'Backspace', 'Delete', 'ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'Home', 'End', 'PageUp', 'PageDown' ]; var modifierKeyCodes = [ 'Shift', 'CapsLock' ]; var forms = document.querySelectorAll( 'form[method=post]' ); for ( var i = 0; i < forms.length; i++ ) { var form = forms[i]; var formAction = form.getAttribute( 'action' ); // Ignore forms that POST directly to other domains; these could be things like payment forms. if ( formAction ) { // Check that the form is posting to an external URL, not a path. if ( formAction.indexOf( 'http://' ) == 0 || formAction.indexOf( 'https://' ) == 0 ) { if ( formAction.indexOf( 'http://' + window.location.hostname + '/' ) != 0 && formAction.indexOf( 'https://' + window.location.hostname + '/' ) != 0 ) { continue; } } } form.addEventListener( 'submit', function () { var ak_bkp = prepare_timestamp_array_for_request( keypresses ); var ak_bmc = prepare_timestamp_array_for_request( mouseclicks ); var ak_bte = prepare_timestamp_array_for_request( touchEvents ); var ak_bmm = prepare_timestamp_array_for_request( mousemoves ); var input_fields = { // When did the user begin entering any input? 'bib': input_begin, // When was the form submitted? 'bfs': Date.now(), // How many keypresses did they make? 'bkpc': keypresses.length, // How quickly did they press a sample of keys, and how long between them? 'bkp': ak_bkp, // How quickly did they click the mouse, and how long between clicks? 'bmc': ak_bmc, // How many mouseclicks did they make? 'bmcc': mouseclicks.length, // When did they press modifier keys (like Shift or Capslock)? 'bmk': modifierKeys.join( ';' ), // When did they correct themselves? e.g., press Backspace, or use the arrow keys to move the cursor back 'bck': correctionKeys.join( ';' ), // How many times did they move the mouse? 'bmmc': mousemoves.length, // How many times did they move around using a touchscreen? 'btmc': touchmoveCount, // How many times did they scroll? 'bsc': scrollCount, // How quickly did they perform touch events, and how long between them? 'bte': ak_bte, // How many touch events were there? 'btec' : touchEvents.length, // How quickly did they move the mouse, and how long between moves? 'bmm' : ak_bmm }; var akismet_field_prefix = 'ak_'; if ( this.getElementsByClassName ) { // Check to see if we've used an alternate field name prefix. We store this as an attribute of the container around some of the Akismet fields. var possible_akismet_containers = this.getElementsByClassName( 'akismet-fields-container' ); for ( var containerIndex = 0; containerIndex < possible_akismet_containers.length; containerIndex++ ) { var container = possible_akismet_containers.item( containerIndex ); if ( container.getAttribute( 'data-prefix' ) ) { akismet_field_prefix = container.getAttribute( 'data-prefix' ); break; } } } for ( var field_name in input_fields ) { var field = document.createElement( 'input' ); field.setAttribute( 'type', 'hidden' ); field.setAttribute( 'name', akismet_field_prefix + field_name ); field.setAttribute( 'value', input_fields[ field_name ] ); this.appendChild( field ); } }, supportsPassive ? { passive: true } : false ); form.addEventListener( 'keydown', function ( e ) { // If you hold a key down, some browsers send multiple keydown events in a row. // Ignore any keydown events for a key that hasn't come back up yet. if ( e.key in keydowns ) { return; } var keydownTime = ( new Date() ).getTime(); keydowns[ e.key ] = [ keydownTime ]; if ( ! input_begin ) { input_begin = keydownTime; } // In some situations, we don't want to record an interval since the last keypress -- for example, // on the first keypress, or on a keypress after focus has changed to another element. Normally, // we want to record the time between the last keyup and this keydown. But if they press a // key while already pressing a key, we want to record the time between the two keydowns. var lastKeyEvent = Math.max( lastKeydown, lastKeyup ); if ( lastKeyEvent ) { keydowns[ e.key ].push( keydownTime - lastKeyEvent ); } lastKeydown = keydownTime; }, supportsPassive ? { passive: true } : false ); form.addEventListener( 'keyup', function ( e ) { if ( ! ( e.key in keydowns ) ) { // This key was pressed before this script was loaded, or a mouseclick happened during the keypress, or... return; } var keyupTime = ( new Date() ).getTime(); if ( 'TEXTAREA' === e.target.nodeName || 'INPUT' === e.target.nodeName ) { if ( -1 !== modifierKeyCodes.indexOf( e.key ) ) { modifierKeys.push( keypresses.length - 1 ); } else if ( -1 !== correctionKeyCodes.indexOf( e.key ) ) { correctionKeys.push( keypresses.length - 1 ); } else { // ^ Don't record timings for keys like Shift or backspace, since they // typically get held down for longer than regular typing. var keydownTime = keydowns[ e.key ][0]; var keypress = []; // Keypress duration. keypress.push( keyupTime - keydownTime ); // Amount of time between this keypress and the previous keypress. if ( keydowns[ e.key ].length > 1 ) { keypress.push( keydowns[ e.key ][1] ); } keypresses.push( keypress ); } } delete keydowns[ e.key ]; lastKeyup = keyupTime; }, supportsPassive ? { passive: true } : false ); form.addEventListener( "focusin", function ( e ) { lastKeydown = null; lastKeyup = null; keydowns = {}; }, supportsPassive ? { passive: true } : false ); form.addEventListener( "focusout", function ( e ) { lastKeydown = null; lastKeyup = null; keydowns = {}; }, supportsPassive ? { passive: true } : false ); } document.addEventListener( 'mousedown', function ( e ) { lastMousedown = ( new Date() ).getTime(); }, supportsPassive ? { passive: true } : false ); document.addEventListener( 'mouseup', function ( e ) { if ( ! lastMousedown ) { // If the mousedown happened before this script was loaded, but the mouseup happened after... return; } var now = ( new Date() ).getTime(); var mouseclick = []; mouseclick.push( now - lastMousedown ); if ( lastMouseup ) { mouseclick.push( lastMousedown - lastMouseup ); } mouseclicks.push( mouseclick ); lastMouseup = now; // If the mouse has been clicked, don't record this time as an interval between keypresses. lastKeydown = null; lastKeyup = null; keydowns = {}; }, supportsPassive ? { passive: true } : false ); document.addEventListener( 'mousemove', function ( e ) { if ( mousemoveTimer ) { clearTimeout( mousemoveTimer ); mousemoveTimer = null; } else { mousemoveStart = ( new Date() ).getTime(); lastMousemoveX = e.offsetX; lastMousemoveY = e.offsetY; } mousemoveTimer = setTimeout( function ( theEvent, originalMousemoveStart ) { var now = ( new Date() ).getTime() - 500; // To account for the timer delay. var mousemove = []; mousemove.push( now - originalMousemoveStart ); mousemove.push( Math.round( Math.sqrt( Math.pow( theEvent.offsetX - lastMousemoveX, 2 ) + Math.pow( theEvent.offsetY - lastMousemoveY, 2 ) ) ) ); if ( mousemove[1] > 0 ) { // If there was no measurable distance, then it wasn't really a move. mousemoves.push( mousemove ); } mousemoveStart = null; mousemoveTimer = null; }, 500, e, mousemoveStart ); }, supportsPassive ? { passive: true } : false ); document.addEventListener( 'touchmove', function ( e ) { if ( touchmoveCountTimer ) { clearTimeout( touchmoveCountTimer ); } touchmoveCountTimer = setTimeout( function () { touchmoveCount++; }, 500 ); }, supportsPassive ? { passive: true } : false ); document.addEventListener( 'touchstart', function ( e ) { lastTouchStart = ( new Date() ).getTime(); }, supportsPassive ? { passive: true } : false ); document.addEventListener( 'touchend', function ( e ) { if ( ! lastTouchStart ) { // If the touchstart happened before this script was loaded, but the touchend happened after... return; } var now = ( new Date() ).getTime(); var touchEvent = []; touchEvent.push( now - lastTouchStart ); if ( lastTouchEnd ) { touchEvent.push( lastTouchStart - lastTouchEnd ); } touchEvents.push( touchEvent ); lastTouchEnd = now; // Don't record this time as an interval between keypresses. lastKeydown = null; lastKeyup = null; keydowns = {}; }, supportsPassive ? { passive: true } : false ); document.addEventListener( 'scroll', function ( e ) { if ( scrollCountTimer ) { clearTimeout( scrollCountTimer ); } scrollCountTimer = setTimeout( function () { scrollCount++; }, 500 ); }, supportsPassive ? { passive: true } : false ); } /** * For the timestamp data that is collected, don't send more than `limit` data points in the request. * Choose a random slice and send those. */ function prepare_timestamp_array_for_request( a, limit ) { if ( ! limit ) { limit = 100; } var rv = ''; if ( a.length > 0 ) { var random_starting_point = Math.max( 0, Math.floor( Math.random() * a.length - limit ) ); for ( var i = 0; i < limit && i < a.length; i++ ) { rv += a[ random_starting_point + i ][0]; if ( a[ random_starting_point + i ].length >= 2 ) { rv += "," + a[ random_starting_point + i ][1]; } rv += ";"; } } return rv; } if ( document.readyState !== 'loading' ) { init(); } else { document.addEventListener( 'DOMContentLoaded', init ); } })();;