Skip to main content

JavaScript Functions

The following function documentation is automatically generated.

Functions

GlobalDescription
scrollNextSectionListener(el, parentSelector)

Bind this function to an element to scroll to the next sibling element by defining your desired parent element.

findParentBlock(el, parent)Element
trigger(eventName, module, details)

Function to fire custom events

hasCookie(name)boolean

Check if a cookie exists

getCookie(name)string | null

Get the value of a cookie by name

setCookie(name, duration, [value])void

Set a cookie with a specified expiration time

parseDuration(duration)number

Parse a duration string into milliseconds

isAdmin()boolean

Check if the current page is in the WordPress admin area

scrollNextSectionListener(el, parentSelector) ⇒

Bind this function to an element to scroll to the next sibling element by defining your desired parent element.

Kind: global function
Returns: void
Api: function

ParamTypeDefaultDescription
elElementThe element that fired the event
parentSelectorstring"acf-block"The class of the parent element to find, default is 'acf-block'

Example

import { scrollNextSectionListener } from 'parentThemeScripts/api/helpers';
const nextButton = document.querySelectorAll('.js-scroll-next');
if (!nextButton) return;
nextButton.forEach((button) => {
scrollNextSectionListener(button, 'custom-parent-class');
});

findParentBlock(el, parent) ⇒ Element

Kind: global function
Returns: Element - the parent element with the class .acf-block
Api: function findParentBlock(el) findParentBlock

ParamTypeDefaultDescription
elElementthe element that fired the event
parentstring"acf-block"the class of the parent element to find, default is 'acf-block'

trigger(eventName, module, details)

Function to fire custom events

Kind: global function

ParamTypeDefaultDescription
eventNamestringevent name prefixed with namespace
modulestringmodule name
detailsobjectfalsedata to pass to event

Example
You can listen for events triggered by this function by using the following syntax:

import { trigger } from 'parentThemeScripts/api/helpers';
trigger('my_event', 'my_module', { foo: 'bar' });

Example

// Listening for the event
document.addEventListener('wp-lemon/my_module/my_event', function(e) {
console.log(e.detail); // { foo: 'bar' }
});

hasCookie(name) ⇒ boolean

Check if a cookie exists

Kind: global function
Returns: boolean - True if the cookie exists, false otherwise
Api: function

ParamTypeDescription
namestringThe name of the cookie to check

Example

import { hasCookie } from 'parentThemeScripts/api/helpers';
if (hasCookie('my_cookie')) {
// Cookie exists
}

getCookie(name) ⇒ string | null

Get the value of a cookie by name

Kind: global function
Returns: string | null - The cookie value, or null if the cookie does not exist
Api: function

ParamTypeDescription
namestringThe name of the cookie to retrieve

Example

import { getCookie } from 'parentThemeScripts/api/helpers';
const value = getCookie('user_preference');
if (value) {
console.log(value); // e.g., 'dark-mode'
}

Example

import { getCookie } from 'parentThemeScripts/api/helpers';
// Use with a default value
const theme = getCookie('theme') || 'light';

setCookie(name, duration, [value]) ⇒ void

Set a cookie with a specified expiration time

Kind: global function
Api: function

ParamTypeDefaultDescription
namestringThe name of the cookie
durationstringThe duration string (e.g., '2 hours', '1 day', '3 months')
[value]string"'1'"The value to store in the cookie

Example

// Set a cookie for 2 hours
import { setCookie } from 'parentThemeScripts/api/helpers';
setCookie('my_cookie', '2 hours');

Example

import { setCookie } from 'parentThemeScripts/api/helpers';
// Set a cookie for 1 day with custom value
setCookie('user_preference', '1 day', 'dark-mode');

Example

import { setCookie } from 'parentThemeScripts/api/helpers';
// Set a cookie for 3 months
setCookie('consent', '3 months', 'accepted');

parseDuration(duration) ⇒ number

Parse a duration string into milliseconds

Kind: global function
Returns: number - The duration in milliseconds

ParamTypeDescription
durationstringThe duration string (e.g., '2 hours', '1 day', '3 months')

Example

const durationMs = parseDuration('2 hours');
console.log(durationMs); // 7200000

isAdmin() ⇒ boolean

Check if the current page is in the WordPress admin area

Kind: global function
Returns: boolean - True if in WordPress admin, false otherwise
Api: function
Example

import { isAdmin } from 'parentThemeScripts/api/helpers';
if (isAdmin()) {
// Disable certain interactions in admin
config.preventClicks = false;
}