Introduction
The gform.utils
object in Gravity Forms provides a collection of utility functions and modules to assist developers in performing common tasks such as DOM manipulation, data processing, browser compatibility, etc.
Note: You can access comprehensive documentation for gform.utils at: https://docs.js.gravity.com/js-utils/
Overview
Name | Type | Description |
---|---|---|
addAsyncFilter | Function | Adds an asynchronous filter for event-driven processing. |
addFilter | Function | Adds a synchronous filter for event-driven processing. |
animate | Module | Provides animation-related utilities. |
applyBrowserClasses | Function | Applies browser-specific classes to the DOM for styling or scripting purposes. |
arrayEquals | Function | Checks if two arrays are equal. |
arrayToInt | Function | Converts an array of values to integers. |
aspectRatioToPadding | Function | Converts an aspect ratio to a padding value for responsive layouts. |
bodyLock | Module | Manages body scroll locking for modal or overlay scenarios. |
browsers | Function | Detects browser information for compatibility checks. |
checkNotificationPromise | Function | Checks for notification API support in the browser. |
clipboard | Function | Interacts with the system clipboard for copy/paste functionality. |
cloneDeep | Function | Creates a deep copy of an object or array. |
consoleError | Function | Logs an error message to the console with formatting. |
consoleInfo | Function | Logs an info message to the console with formatting. |
consoleLog | Function | Logs a message to the console with formatting. |
consoleWarn | Function | Logs a warning message to the console with formatting. |
convertElements | Function | Converts elements for DOM manipulation or processing. |
cookieStorage | Module | Manages cookie-based storage operations. |
debounce | Function | Debounces a function to limit execution frequency. |
deepMerge | Function | Merges two objects deeply, preserving nested properties. |
delay | Function | Delays execution of a function for a specified time. |
delegate | Function | Sets up event delegation for efficient event handling. |
dragHorizontal | Function | Enables horizontal drag functionality for elements. |
escapeHtml | Function | Escapes HTML characters to prevent XSS or rendering issues. |
escapeScripts | Function | Escapes script tags to prevent execution in unsafe contexts. |
filter | Function | Filters an array based on a provided condition. |
filterObject | Function | Filters an object’s properties based on a condition. |
findNestedObject | Function | Finds a nested object by key within a parent object. |
fnvHash | Function | Generates an FNV hash for a given input. |
focusLoop | Function | Manages focus trapping within a container for accessibility. |
getAttachmentImageUrl | Function | Retrieves the URL of an attachment image. |
getChildren | Function | Retrieves child elements of a given DOM node. |
getClosest | Function | Finds the closest ancestor element matching a selector. |
getConfig | Function | Retrieves configuration settings for a component or module. |
getCoords | Function | Gets the coordinates of an element relative to the viewport. |
getFocusable | Function | Retrieves focusable elements within a container for accessibility. |
getHiddenHeight | Function | Calculates the height of a hidden element. |
getNode | Function | Retrieves a single DOM node based on a selector or reference. |
getNodes | Function | Retrieves multiple DOM nodes based on a selector. |
hasClassFromArray | Function | Checks if an element has any class from a provided array. |
hasScrollbar | Function | Detects if an element has a visible scrollbar. |
insertAfter | Function | Inserts an element after a specified target in the DOM. |
insertBefore | Function | Inserts an element before a specified target in the DOM. |
isEmptyObject | Function | Checks if an object is empty. |
isEqual | Function | Compares two values for equality, including nested structures. |
isExternalLink | Function | Determines if a URL is an external link. |
isFileLink | Function | Checks if a link points to a file resource. |
isFormDirty | Function | Checks if a form has unsaved changes. |
isFunction | Function | Verifies if a value is a function. |
isImageLink | Function | Checks if a link points to an image resource. |
isJestTest | Function | Detects if the code is running in a Jest test environment. |
isJson | Function | Validates if a string is valid JSON. |
isNumber | Function | Checks if a value is a number. |
isObject | Function | Verifies if a value is an object. |
isRtl | Function | Detects if the document is in right-to-left (RTL) mode. |
localStorage | Module | Manages local storage operations for persistent data. |
matchesOrContainedInSelectors | Function | Checks if an element matches or is contained within provided selectors. |
mimicFn | Function | Copies properties and methods from one function to another. |
normalizeUrl | Function | Normalizes a URL for consistent formatting. |
objectAssign | Function | Merges objects using Object.assign-like functionality. |
objectToAttributes | Function | Converts an object to HTML attributes string. |
objectToFormData | Function | Converts an object to FormData for form submissions. |
openNewTab | Function | Opens a URL in a new browser tab. |
parseUrl | Function | Parses a URL into its components. |
popup | Function | Manages popup window functionality. |
queryToJson | Function | Converts a query string to a JSON object. |
ready | Function | Executes a callback when the DOM is fully loaded. |
removeClassThatContains | Function | Removes classes from an element that contain a specific string. |
removeFilter | Function | Removes a previously added filter. |
resize | Function | Handles window resize events with throttling. |
runOnce | Function | Ensures a function runs only once. |
saferHtml | Function | Sanitizes HTML to prevent XSS while allowing safe tags. |
sessionStorage | Module | Manages session storage operations for temporary data. |
setAttributes | Function | Sets multiple attributes on a DOM element. |
shouldLoadChunk | Function | Determines if a JavaScript chunk should be loaded. |
simpleBar | Module | Provides custom scrollbar functionality. |
slide | Module | Manages slide animations for elements. |
slugify | Function | Converts a string into a URL-friendly slug. |
spacerClasses | Function | Generates spacer classes for layout control. |
speak | Function | Utilizes the Web Speech API for text-to-speech functionality. |
sprintf | Function | Formats strings using placeholders, similar to sprintf in PHP. |
trigger | Function | Triggers a custom or native DOM event. |
uniqueId | Function | Generates a unique ID for elements or objects. |
updateQueryVar | Function | Updates a query variable in a URL. |
viewport | Module | Provides utilities for working with the viewport (e.g., dimensions, scroll position). |
visible | Function | Checks if an element is visible in the DOM. |
vsprintf | Function | Formats strings with an array of arguments, similar to vsprintf in PHP. |