Javascript Library

Accordions

Accordion Javascript

Methods

init()

const accordions = new getAccordions4i(),
wrapper = document.querySelector("#mainContent");
accordions.init(wrapper);
				
open()

accordions.open(document.getElementById("SaleSection"));
				
close()

accordions.close(document.getElementById("SaleSection"));
				
openAll()

accordions.openAll(document.querySelector("#mainContent"));
				
closeAll()

accordions.closeAll(document.querySelector("#mainContent"));
				

Resources

Sass File(s)/sass/components/_accordion.scss
JS File(s)/library/accordions2021.js
JS FunctionsSee Above
Locale KeysNone

Accessibility

None at this time.

Chat

Chat Javascript

Examples

Code
					
<button type="button" class="initChat btnToHyp darkestLink">Chat<span class="visually-hidden"> with a 4imprint Customer Service Representative in new window</span></button>
					
				
Notes

Add initChat class to button initializing 4imprint chat.

Resources

Sass File(s)None
JS File(s)/views/chat/chat2023.js
JS FunctionsSee Above
Locale KeysNone

Accessibility

visually-hidden text must be included in the trigger element.

Checkboxes

Checkbox Helpers Javascript

Find helpful functions at your fingertips with this library file.

Methods

Init()

Adds event listeners to every select all checkboxes with class selectAllBox. Also calls AssessChecks()

const checkboxes = new checkboxes4i();
checkboxes.Init();
				
AssessChecks()

Looks at groups of checkboxes with class checkboxOptions and if all are checked, it checks the select all checkbox

checkboxes.AssessChecks();
				
Check()

Checks one or more checkboxes

const boxes = document.querySelectorAll(".yourClass");
checkboxes.Check(boxes);
				
Uncheck()

Unchecks one or more checkboxes

const boxes = document.querySelectorAll(".yourClass");
checkboxes.Uncheck(boxes);
				
GetPreferences()

Find all checkboxes that are checked and return the users preferences (esp)

const entireSectionWrapper = document.querySelector(".userSubscriptions");
const userPreferences = checkboxes.GetPreferences(entireSectionWrapper);
				
Notes

Select/unselect all checkbox:
has class selectAllBox
has unique ID allSales

Wrapper housing all checkbox options:
has class checkboxOptions
has unique ID: allSalesOptions (FORMAT = selectAllBox ID + "Options")

Resources

Sass File(s)None
JS File(s)/library/checkbox.js
JS FunctionsSee Above
Locale KeysNone

Accessibility

None at this time.

Dialogs

Dialog Javascript

Methods

init()

const exampleDialog = new Dialog4i();
const dialogContent = '<div class="spinner" role="alert" aria-busy="true" aria-atomic="true" aria-label="Loading example dialog, please wait"><div class="bounce1"></div><div class="bounce2"></div><div class="bounce3"></div></div>';
exampleDialog.Init({
	triggerElements: [].slice.call(document.querySelectorAll(".buttonToTriggerDialog")),
	dialogClass: "mediumDialog", 
	title: "Loading Example Dialog", 
	content: dialogContent, 
	onOpen: open,
	onClose: close,
	arrows: {
		left: '<button id="scrollLeft" type="button" class="scrollLeft whiteLink noLine pointer"><svg class="rotate270 show" height="40px" width="40px" focusable="false" role="img" aria-label="Scroll to previous"><title>Scroll to previous</title><use xlink:href="#svgIcon-arrowLine"></use></svg></button>',
		right: '<button id="scrollRight" type="button" class="scrollRight whiteLink noLine pointer"><svg class="rotate90 show" height="40px" width="40px" focusable="false" role="img" aria-label="Scroll to next"><title>Scroll to next</title><use xlink:href="#svgIcon-arrowLine"></use></svg></button>'
	},
	keyEvents: LeftRightArrow
});
				
init() (module)

const exampleDialogs = await SetUpDialogs();
async function SetUpDialogs(){ 
	const { default: Dialog4i } = await import( './../library/dialog4i2022.js?v=1');
	const dialogContent = '<div class="spinner" role="alert" aria-busy="true" aria-atomic="true" aria-label="Loading example dialog, please wait"><div class="bounce1"></div><div class="bounce2"></div><div class="bounce3"></div></div>';
	return new Dialog4i({
		triggerElements: [].slice.call(document.querySelectorAll(".buttonToTriggerDialog")),
		dialogClass: "mediumDialog", 
		title: "Loading Example Dialog", 
		content: dialogContent, 
		onOpen: open,
		onClose: close,
		arrows: {
			left: '<button id="scrollLeft" type="button" class="scrollLeft whiteLink noLine pointer"><svg class="rotate270 show" height="40px" width="40px" focusable="false" role="img" aria-label="Scroll to previous"><title>Scroll to previous</title><use xlink:href="#svgIcon-arrowLine"></use></svg></button>',
			right: '<button id="scrollRight" type="button" class="scrollRight whiteLink noLine pointer"><svg class="rotate90 show" height="40px" width="40px" focusable="false" role="img" aria-label="Scroll to next"><title>Scroll to next</title><use xlink:href="#svgIcon-arrowLine"></use></svg></button>'
		},
		keyEvents: LeftRightArrow
	});	
}
				
BindTriggerElements()

Binds new trigger element events.

exampleDialog.BindTriggerElements(btns);
				
BindCloseElements()

Binds any elements within the content with class close4iDialog to trigger the close() method.

exampleDialog.BindCloseElements();
				
Open()

Only use if absolutely needed.

exampleDialog.Open();
				
Close()

Only use if absolutely needed.

exampleDialog.Close();
				
HideCloseBtn()

Call on open function if hiding the close button in header is needed.

exampleDialog.HideCloseBtn();
				
ShowCloseBtn()

Makes the close button in the header visible again after hiding it.

exampleDialog.ShowCloseBtn();
				

Options

OptionRequiredTypeDescription
triggerElementsRequiredNode(s) or
[ ]
An array of all elements that open the dialog or an empty array.
dialogClassRequired"smallDialog"
"mediumDialog"
"largeDialog"
"xLDialog"
"fullDialog"
Setting the width of your dialog:
smallDialog = 20rem
mediumDialog = 30rem
largeDialog = 40rem
xLDialog = 50rem
fullDialog = 95%
titleRequiredString or
HTML
The heading of the dialog (can be updated later).
contentRequiredHTMLThe initial HTML for the content of the dialog.
arrowsOptional"left"
"right"
HTML
Can specify both "left" & "right" arrow HTML.
onOpenOptionalFunctionFired when the dialog is opened (great for updating the content HTML).
onCloseOptionalFunctionFired on close only when an element with close4iDialog class is clicked.
keyEventsOptionalFunctionFired on keydown when the dialog is open (good to use for left/right arrows).

Resources

Sass File(s)/sass/components/_dialog4i.scss
JS File(s)/library/dialog4i2022.js or
/modules/library/dialog4i2022.js
JS FunctionsSee Above
Locale KeysNone

Accessibility

None at this time.

Fetch

Fetch Javascript

Example

let responseJSON;
try{
	const response = await fetch('/Something/YourURL', {
		method: 'POST', 
		body: JSON.stringify({}),
		headers: { 'Content-Type': 'application/json', 'X-Requested-With': 'fetch' }
	});
	//if(!response.ok) throw new Error(`Error processing request: ${response.statusText}`);
	responseJSON = await response.json();
}catch(error){
	console.error(error);
	// error function here
}

if(responseJSON){
	if(responseJSON.Success) // successful function here
	else //error function here
}
				

Resources

Sass File(s)None
JS File(s)None Required
JS FunctionsSee Above
Locale KeysNone

Accessibility

None at this time.

Forms

Form Javascript

Methods

formValidation()

Runs the form validation and adds error messages or runs successful function.

					
let forms = new forms4i(),

validateForm = e => {
	e.preventDefault();
	forms.formValidation(document.getElementById("styleGuideForm"), formValidationSuccess, e);
},

formValidationSuccess = () => {
	let successMsg = '<p class="text20 textSemiBold displayFlex flexAlignItemsCenter"><svg class="textDarkestGray roundCorners5 bkgdGreen" height="30px" width="30px" focusable="false" aria-hidden="true"><use xlink:href="#svgIcon-checkMark"></use></svg> <span class="marginLeft5">Your form submitted successfully!</span></p>';
	document.getElementById("styleGuideForm").classList.add("hide");
	document.getElementById("styleGuideForm").insertAdjacentHTML("afterend", successMsg);
}; 

btn.addEventListener("click", validateForm);
				
serverValidation()

Runs the form server validation and adds error messages for customer attributes in VS models.

forms.serverValidation(document.getElementById("styleGuideForm"));
				
ClearValidation()

Removes error message box, CSS, and accessibility components related to invalid fields.

forms.ClearValidation();
				
InvalidateField()

Allows the ability to add custom validation to your javascript file.

let errorList = ["Please enter a valid number"];
forms.InvalidateField(formEl, targetEl, errorList);
				
FadeCCImgs()

Initiates validation as user is typing credit card number. cardName can be null.

let cardNum = document.getElementById("cardNumElem"),
btnElement = document.getElementById("btnElem"),
cardName = document.getElementById("savedNameElem");

forms.FadeCCImgs(cardNum, btnElement, cardName);
				
MaskCCNumber()

Adds a mask to credit card number - ie. spaces after 4-digit increments.

let ccMask = document.getElementById("ccMaskElem"),
cardNumber = document.getElementById("cardNumElem");

forms.MaskCCNumber(ccMask, cardNumber);
				
MaskCVVNumber()

Formats the CVV input field so numbers typed in follow the format on a credit card.

let cvvMask = document.getElementById("cvvMaskElem"),
cvvNumber = document.getElementById("cvvElem");

forms.MaskCVVNumber(cvvMask, cvvNumber);
				
MaskPhoneNumber()

Formats the phone number input field so numbers typed in follow the phone number format.
Must also include '/javascript/vanilla-masker.js' file in the bundle before the forms2021.js file.

let phoneMask = document.getElementById("phoneMask"),
phoneNumber = document.getElementById("PhoneNumber");

forms.MaskPhoneNumber(phoneMask, phoneNumber);
				
UnmaskCCNumber()

Removes any masking from Credit Card Number (may be necessary before form submission)

forms.UnmaskCCNumber(document.getElementById("cardNumElem"));
				
GetCreditCardName()

Provides name of credit card based on First Digit of Card Number.

forms.GetCreditCardName(cardNumber));
				
ShowSaveCardName()

Updates HTML and CSS for 'Saved Card' and 'Is Default' options for credit cards.
Param 3: Null can be passed in if the 'IsDefault' checkbox does not exist.

let savedCheck = document.getElementById("isSavedElem"),
savedName = document.getElementById("savedNameElem"),
isDefault = document.getElementById(isDefaultElem);

forms.ShowSaveCardName(savedCheck, savedName, isDefault);
				
BindPasswordButtons()

Binds events for showing/hiding the password field.

forms.BindPasswordButtons();
				

Resources

Sass File(s)/sass/components/_flexform2018.scss
JS File(s)/library/forms2021.js and/or
/library/formcreditcards.js
JS FunctionsSee Above
Locale Keys/ecommerce/forms
/secure/registration/creditcard

Accessibility

None at this time.

Form Helpers

Form Helpers Javascript

Find helpful form submission functions and variables at your fingertips with this library file.

Methods

LoadingIcon

Returns loading icon HTML

const helpers = new formHelpers4i();
helpers.LoadingIcon;
				
HeaderToken

Returns request verification token

helpers.HeaderToken;
				
RecaptchaKey

Returns RecaptchaSiteKey

helpers.RecaptchaKey;
				
RecaptchaName

Returns RecaptchaActionName

helpers.RecaptchaName;
				
ErrorMsgPanel

Returns error box HTML

helpers.ErrorMsgPanel;
				
ShowSuccessStatus()

Displays a green success status; Also focuses on the link if there is one

const elementToInsertBefore = document.querySelector(".btnParent");
const msg = 'Your account has been successfully updated.';
helpers.ShowSuccessStatus(elementToInsertBefore, msg);
				
ShowErrorStatus()

Displays a red error status

const elementToInsertBefore = document.querySelector(".btnParent");
const msg = 'There was an issue updating your account. Please refresh the page and try again or contact us if the issue continues.';
helpers.ShowErrorStatus(elementToInsertBefore, msg);
				
ClearStatus()

Removes all status messages

helpers.ClearStatus();
				
ShowBusyBtn()

Adds a round loading icon to the button text

helpers.ShowBusyBtn(e.currentTarget);
				
ClearBusyBtn()

Removes the loading icon from the button

helpers.ClearBusyBtn();
				
ShowLoadingOverlay()

Inserts a loading overlay to block the UI

const wrapperOfSectionToBlock = document.querySelector(".mySection");
helpers.ShowLoadingOverlay(wrapperOfSectionToBlock)
				
RemoveLoadingOverlay()

Removes the UI blocking loading overlay

helpers.RemoveLoadingOverlay();
				

Resources

Sass File(s)None
JS File(s)/library/forms/formhelpers.js
JS FunctionsSee Above
Locale KeysNone

Accessibility

None at this time.

Image Errors

Image Error Javascript

Replaces broken images with a nice image icon.

Methods

Init()

Already called; Will never be needed.

ImgError4i.Init();
				
ObserveImgs()

Adds event listener when images are dynamically loaded on the page. Only needs to be called once on page init.

ImgError4i.ObserveImgs();
				
Notes

None at this time.

Resources

Sass File(s)None
JS File(s)/library/imgerrors4i.js
JS FunctionsNone
Locale KeysNone

Accessibility

None at this time.

Tables

Tables Javascript

Methods

Init()

const adminTable = new tables4i();
adminTable.Init({
	table: document.getElementById("productTable"),
	url: "/productcards/table",
	paging: {
		itemsToShow: 10,
		label: "Product Paging"
	},
	search: true,
	filter: true
});
				
ReloadTable()
adminTable.ReloadTable();
				
UpdateInitialSearch(searchTerm)

Uses search term value for tables that require a search before loading.

adminTable.UpdateInitialSearch(input.value);
				
UpdateUrl(url)

Uses fetch url that will return all table data.

adminTable.UpdateUrl(fetchURL);
				

Options

OptionRequiredTypeDescription
tableRequiredNode: Table IDThe actual table element.
urlRequiredStringThe route to get table row data.
pagingOptional{}Only include if paging is desired. Holds the values for paging below.
paging.itemsToShowOptionalIntegerThe initial number of rows the table needs to display.
paging.labelOptionalStringThe aria-label for the paging navigation.
searchOptionalBooleenOnly include if searching table is desired. true will allow searching.
filterOptionalBooleenOnly include if filtering table is desired. true will allow filtering.

Resources

Sass File(s)/sass/components/_tables.scss
JS File(s)Please use the table2024js bundle
/library/tables/common.js
/library/tables/filter.js
/library/tables/paging.js
/library/tables/search.js
/library/tables/tables.js
JS FunctionsSee Above.
Locale KeysNone

Accessibility

None at this time.

Tabs

Tabs Javascript

Methods

init()

let tabs = new tabs4i();
let wrapperEl = document.getElementById("copyTabs");
tabs.init(wrapperEl);
				
initTab()

Uses ID of the tab button you want to have open on page load.

tabs.initTab(document.getElementById("tabTwo"));
				
Notes

See Tab Component.

Resources

Sass File(s)/sass/components/_tabs.scss
JS File(s)/library/tabs4i.js
JS FunctionsSee Above.
Locale KeysNone

Accessibility

None at this time.

Tooltips

Tooltips Javascript

Methods

init()

let detailsToolTips = new toolTips();
detailsToolTips.init();
				

Resources

Sass File(s)/sass/components/_tooltips.scss
JS File(s)/library/tooltips.js
JS FunctionsSee Above
Locale KeysNone

Accessibility

None at this time.

Videos

Videos Javascript

Methods

init()

let videoJS = new videos4i();
videoJS.initLinks();
				
allVideoLinks()

Get all elements with the videoLink class.

videoJS.allVideoLinks();
				
initDynamicLink()

Binds dynamically loaded links.

videoJS.initDynamicLink(videoTrigger);
				
initWhyBuyVideo()

videoJS.initWhyBuyVideo();
				
initWeBelieveVideo()

videoJS.initWeBelieveVideo();
				
Notes

See Video Component.

Resources

Sass File(s)/sass/components/_videoplayer2017.scss
JS File(s)/library/getvideodata.js
JS FunctionsSee Above
Locale KeysNone

Accessibility

None at this time.

To Top of page