/home/desid573/cf.desidrivers.com.au/wp-content/themes/Divi/includes/builder/scripts/utils
Edit: /home/desid573/cf.desidrivers.com.au/wp-content/themes/Divi/includes/builder/scripts/utils/utils.js (8196B)
/**
* IMPORTANT: Keep external dependencies as low as possible since this utils might be
* imported by various frontend scripts; need to keep frontend script size low.
*/
// External dependencies
import includes from 'lodash/includes';
import get from 'lodash/get';
import $ from 'jquery';
// Internal dependencies
import { top_window } from '@core/admin/js/frame-helpers';
/**
* Check current page's builder Type.
*
* @since 4.6.0
*
* @param {string} builderType Fe|vb|bfb|tb|lbb|lbp.
*
* @returns {bool}
*/
export const isBuilderType = builderType => builderType === window.et_builder_utils_params.builderType;
/**
* Return condition value.
*
* @since 4.6.0
*
* @param {string} conditionName
*
* @returns {bool}
*/
export const is = conditionName => window.et_builder_utils_params.condition[conditionName];
/**
* Is current page Frontend.
*
* @since 4.6.0
*
* @type {bool}
*/
export const isFE = isBuilderType('fe');
/**
* Is current page Visual Builder.
*
* @since 4.6.0
*
* @type {bool}
*/
export const isVB = isBuilderType('vb');
/**
* Is current page BFB / New Builder Experience.
*
* @since 4.6.0
*
* @type {bool}
*/
export const isBFB = isBuilderType('bfb');
/**
* Is current page Theme Builder.
*
* @since 4.6.0
*
* @type {bool}
*/
export const isTB = isBuilderType('tb');
/**
* Is current page Layout Block Builder.
*
* @type {bool}
*/
export const isLBB = isBuilderType('lbb');
/**
* Is current page uses Divi Theme.
*
* @since 4.6.0
*
* @type {bool}
*/
export const isDiviTheme = is('diviTheme');
/**
* Is current page uses Extra Theme.
*
* @since 4.6.0
*
* @type {bool}
*/
export const isExtraTheme = is('extraTheme');
/**
* Is current page Layout Block Preview.
*
* @since 4.6.0
*
* @type {bool}
*/
export const isLBP = isBuilderType('lbp');
/**
* Check if current window is block editor window (gutenberg editing page).
*
* @since 4.6.0
*
* @type {bool}
*/
export const isBlockEditor = 0 < $(top_window.document).find('.edit-post-layout__content').length;
/**
* Check if current window is builder window (VB, BFB, TB, LBB).
*
* @since 4.6.0
*
* @type {bool}
*/
export const isBuilder = includes(['vb', 'bfb', 'tb', 'lbb'], window.et_builder_utils_params.builderType);
/**
* Get offsets value of all sides.
*
* @since 4.6.0
*
* @param {object} $selector JQuery selector instance.
* @param {number} height
* @param {number} width
*
* @returns {object}
*/
export const getOffsets = ($selector, width = 0, height = 0) => {
// Return previously saved offset if sticky tab is active; retrieving actual offset contain risk
// of incorrect offsets if sticky horizontal / vertical offset of relative position is modified.
const isStickyTabActive = isBuilder && $selector.hasClass('et_pb_sticky') && 'fixed' !== $selector.css('position');
const cachedOffsets = $selector.data('et-offsets');
const cachedDevice = $selector.data('et-offsets-device');
const currentDevice = get(window.ET_FE, 'stores.window.breakpoint', '');
// Only return cachedOffsets if sticky tab is active and cachedOffsets is not undefined and
// cachedDevice equal to currentDevice.
if (isStickyTabActive && cachedOffsets !== undefined && cachedDevice === currentDevice) {
return cachedOffsets;
}
// Get top & left offsets
const offsets = $selector.offset();
// If no offsets found, return empty object
if ('undefined' === typeof offsets) {
return {};
}
// FE sets the flag for sticky module which uses transform as classname on module wrapper while
// VB, BFB, TB, and LB sets the flag on CSS output's