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,EAAME,UAAUC,IAAK,wBACrBH,EAAMI,aAAc,iCAAkChB,EAAUC,WAChEW,EAAMd,UAAYE,EAAUE,KAG5BhB,EAAM+B,WAAWC,aAAcN,EAAO1B,GACtC0B,EAAMO,YAAajC,EAAO,EA9DxByB,CAAkBzB,EAAOc,EAC1B,GACE,C","sources":["webpack://accessibility-checker-pro/./src/frontendFixes/Fixes/addLabelToUnlabelledFormFieldsFix.js"],"sourcesContent":["const AddLabelToUnlabelledFormFieldsFixData = window.edac_frontend_fixes?.add_label_to_unlabelled_form_fields || {\n\tenabled: false,\n};\n\nconst AddLabelToUnlabelledFormFieldsFix = () => {\n\tif ( ! AddLabelToUnlabelledFormFieldsFixData.enabled ) {\n\t\treturn;\n\t}\n\n\t// find all form fields on the page, excluding submit buttons.\n\tconst formFields = document.querySelectorAll( 'input:not([type=\"submit\"]), select, textarea' );\n\n\tformFields.forEach( ( field ) => {\n\t\t// If the field is hidden, skip it.\n\t\tif ( field.offsetParent === null ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// If the field has an ID check if there are labels with a for attribute that matches the ID and skip if found.\n\t\tif ( field.id ) {\n\t\t\tconst label = document.querySelector( `label[for=\"${ field.id }\"]` );\n\t\t\tif ( label ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\t// Look at up to 3 parent elements to see if the field is in a label and if so don't add another.\n\t\tlet parentElement = field.parentElement;\n\t\tlet parentElementCount = 0;\n\t\twhile ( parentElementCount < 3 ) {\n\t\t\tif ( parentElement.tagName.toLowerCase() === 'label' ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tparentElement = parentElement.parentElement;\n\t\t\tparentElementCount++;\n\t\t}\n\n\t\t// Is there a labelledby attribute?\n\t\tconst labelledBy = field.getAttribute( 'aria-labelledby' );\n\t\tif ( labelledBy ) {\n\t\t\t// Check if the element with that id has text content and return if non-empty.\n\t\t\tconst labelledByElement = document.getElementById( labelledBy );\n\t\t\tif ( labelledByElement && labelledByElement.innerText.trim() !== '' ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\t// Try get something to use as label text.\n\t\tconst labelData = tryGetLabelData( field );\n\t\tif ( labelData.attribute !== '' && labelData.text !== '' ) {\n\t\t\twrapFieldInLabel( field, labelData );\n\t\t}\n\t} );\n};\n\n/**\n * Try to get label data from the field's attributes.\n *\n * Prefer title, aria-label, name, placeholder in that order.\n *\n * @param {HTMLElement} field\n * @return {Object} - {attribute: string, text: string}\n */\nconst tryGetLabelData = ( field ) => {\n\tconst preferredAttributesOrder = [ 'aria-label', 'placeholder', 'title', 'name' ];\n\n\tconst labelData = {\n\t\tattribute: '',\n\t\ttext: '',\n\t};\n\n\tpreferredAttributesOrder.forEach( ( attributeToCheck ) => {\n\t\tif ( labelData.text.length && labelData.attribute.length ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst attributeText = field.getAttribute( attributeToCheck )?.trim();\n\t\tif ( attributeText && attributeText.length ) {\n\t\t\tlabelData.attribute = attributeToCheck;\n\t\t\tlabelData.text = attributeText;\n\t\t}\n\t} );\n\n\tif ( labelData.text !== '' ) {\n\t\t// Replace underscores with spaces.\n\t\tlabelData.text = labelData.text.replace( /_/g, ' ' );\n\t\t// Seporate words with spaces if camelCase.\n\t\tlabelData.text = labelData.text.replace( /([a-z])([A-Z])/g, '$1 $2' );\n\t\t// Capitalize first letter.\n\t\tlabelData.text = labelData.text.charAt( 0 ).toUpperCase() + labelData.text.slice( 1 );\n\t}\n\n\treturn labelData;\n};\n\n/**\n * Wrap the field in a label element.\n *\n * The label will have a class of 'edac-generated-label' and a data attribute of 'data-edac-generated-label-from' with the attribute used to generate the label.\n *\n * @param {HTMLElement} field\n * @param {Object} labelData - {attribute: string, text: string}\n */\nconst wrapFieldInLabel = ( field, labelData ) => {\n\t// Create a label with the text, and add a class and some data to it.\n\tconst label = document.createElement( 'label' );\n\tlabel.classList.add( 'edac-generated-label' );\n\tlabel.setAttribute( 'data-edac-generated-label-from', labelData.attribute );\n\tlabel.innerText = labelData.text;\n\n\t// Insert the label and put the field inside it.\n\tfield.parentNode.insertBefore( label, field );\n\tlabel.appendChild( field );\n};\n\nexport default AddLabelToUnlabelledFormFieldsFix;\n"],"names":["AddLabelToUnlabelledFormFieldsFixData","window","edac_frontend_fixes","add_label_to_unlabelled_form_fields","enabled","AddLabelToUnlabelledFormFieldsFix","document","querySelectorAll","forEach","field","offsetParent","id","querySelector","parentElement","parentElementCount","tagName","toLowerCase","labelledBy","getAttribute","labelledByElement","getElementById","innerText","trim","labelData","attribute","text","attributeToCheck","length","attributeText","replace","charAt","toUpperCase","slice","tryGetLabelData","wrapFieldInLabel","label","createElement","classList","add","setAttribute","parentNode","insertBefore","appendChild"],"sourceRoot":""}