/*
* APPAREL VARIABLES SCRIPT
*/
// Collect all form fields and tabs into collections
const attributesArray = document.getElementsByClassName('form-field');
const productTabArray = document.getElementsByClassName('tab-title');
// Set repeated strings as variables to be more DRY and less spaghetti
const valueStyle = '
';
const canvas3001url = 'https://www.bellacanvas.com/product/3001u/3001-cv-ss-tee-usa.html';
const bayside5040url = 'https://www.usabayside.com/system/files/product/spec/5040_Bayside.pdf?download=1';
const canvas6005url = 'https://www.bellacanvas.com/product/6005/6005-be-jrsy-ss-v-neck-tee.html';
const royalApparelurl = 'http://www.royalapparel.net/product-specifications';
// Iterate through form field collection
Array.prototype.forEach.call(attributesArray, attribute => {
// Initialize reusable loop variables
const fieldControl = attribute.getElementsByClassName('form-field-control')[0];
const formFieldTitle = attribute.getElementsByClassName('form-field-title')[0];
const formData = attribute.getElementsByClassName('form-input')[0];
const optionZero = attribute.getElementsByTagName('option')[0];
const optionOne = attribute.getElementsByTagName('option')[1];
let hiddenField;
let attributeValue;
let hiddenFieldHTML;
let descriptionHTML;
const hideLabelAndValue = () => {
fieldControl.style.display = 'none';
formFieldTitle.style.display = 'none';
};
// Ignore empty form field elements
if (formFieldTitle !== undefined) {
hiddenField = formFieldTitle.innerHTML;
// APPAREL STYLE
if (hiddenField.includes('Apparel Style')) {
formFieldTitle.innerHTML = 'Apparel Style';
// Attribute Value is the option i.e. 'Unisex' or 'Ladies Cut'
attributeValue = optionOne.innerHTML;
// Set Attribute Value styling and display Attribute Value
hiddenFieldHTML = `${valueStyle}${attributeValue}
`;
// Hide Dropdown selector in lieu of Attribute Value display above
hiddenFieldHTML += `
`;
// Inject hiddenFieldHTML into form-field-control span element
fieldControl.innerHTML = hiddenFieldHTML;
hideLabelAndValue();
}
// APPAREL COLOR
if (hiddenField.includes('Apparel Color')) {
formFieldTitle.innerHTML = 'Apparel Color';
// If Apparel Color form field contains dropdown or select element, set optionOne as Attribute Value
if (optionZero.innerHTML.includes('Pick One')) {
optionOne.selected = true;
attributeValue = optionOne.innerHTML;
} else {
// If no dropdown/select element, set optionZero as Attribute Value
attributeValue = optionZero.innerHTML;
}
hiddenFieldHTML = `${valueStyle}${attributeValue}`;
hiddenFieldHTML += `
`;
fieldControl.innerHTML = hiddenFieldHTML;
hideLabelAndValue();
}
// APPAREL BRAND
if (hiddenField.includes('Apparel Brand')) {
formFieldTitle.innerHTML = 'Apparel Brand';
// Apparel Brand is dropdown so set optionOne as default value
attributeValue = optionOne.innerHTML;
descriptionHTML = `${valueStyle}${attributeValue}`;
if (descriptionHTML.includes('Canvas Jersey Tee (3001U) Made in USA')) {
// Canvas 3001U
descriptionHTML = `${valueStyle}${attributeValue}:
100% combed and ring-spun cotton, 30 single 4.2oz. fabric (Heather Grey is 10% polyester).
For sizing and fit information, click here:
Bella + Canvas `;
} else if (descriptionHTML.includes('Bayside 5040 Unisex Tee')) {
// Bayside 5040
descriptionHTML = `${valueStyle}${attributeValue}:
100% cotton, 5.4oz. fabric, Made-In-USA tee. For sizing and fit information, download product specs here:
5040_Bayside.pdf `;
} else if (descriptionHTML.includes('Bella 6005 Ladies V-Neck Tee')) {
// Canvas 6005
descriptionHTML = `${valueStyle}${attributeValue}:
100% combed and ring-spun cotton, 30 single 4.2oz. fabric. For sizing and fit information, click here:
Bella + Canvas `;
} else if (descriptionHTML.includes('Royal')) {
// Royal
descriptionHTML = `${valueStyle}${attributeValue}:
100% combed and ring-spun cotton, 30 single 4.2oz. fabric. For sizing and fit information, click here:
Royal Apparel