);
};
const getTruncatedFileName = (fileUrl) => {
const fileName = getFilename(fileUrl);
if (!fileName) {
return '';
}
const parts = fileName.split('.');
if (!parts || parts.length < 2) {
return '';
}
const exceptExtension = parts[0];
const extension = parts[1];
const keepLength = 5;
const removeLength = exceptExtension.length - keepLength - keepLength;
const html = '' + exceptExtension.substring(0, keepLength) + ''
+ '' + exceptExtension.substring(keepLength, removeLength + keepLength) + ''
+ '' + exceptExtension.substring(removeLength + keepLength, exceptExtension.length) + ''
+ "." + extension;
return createInterpolateElement(html, {
span:
});
};
/**
* Tooltip for minify action.
*
* @return {string} Tooltip.
*/
const getMinifyTooltip = () => {
if ( hasDisableSwitch() && ! props.options.block ) {
return __( 'This file type cannot be compressed and will be left alone', 'wphb' );
} else if ( hasMinifiedExtension() || ( isProcessed() && hasNoSavings() ) ) {
return __( 'This file is already compressed', 'wphb' );
} else if ( ! props.options.dont_minify ) {
return __( 'Compression is on for this file, which aims to reduce its size', 'wphb' );
}
return __( 'Compression is off for this file. Turn it on to reduce its size', 'wphb' );
};
/**
* Tooltip for optimize fonts action.
*
* @return {string} Tooltip.
*/
const getFontsTooltip = () => {
if ( props.options.fonts ) {
return __( 'Font is optimized.', 'wphb' );
}
return __( 'Font optimization is off for this file. Turn it on to optimize it.', 'wphb' );
};
/**
* Tooltip for combine action.
*
* @return {string} Tooltip.
*/
const getCombineTooltip = () => {
if ( hasDisableSwitch( 'combine' ) && ! props.options.block ) {
return __( 'This file can’t be combined', 'wphb' );
} else if ( ! props.options.dont_combine ) {
return __( 'Combine is on for this file, which aims to reduce server requests.', 'wphb' );
}
return __( 'Combine is off for this file. Turn it on to combine smaller files together.', 'wphb' );
};
/**
* Tooltip for "Move to footer" action.
*
* @return {string} Tooltip.
*/
const getPositionTooltip = () => {
if ( props.options.position ) {
return __( 'Move to footer is on for this file, which aims to speed up page load.', 'wphb' );
}
return __( 'Move to footer is off for this file. Turn it on to load it from the footer.', 'wphb' );
};
/**
* Tooltip for defer action.
*
* @return {string} Tooltip.
*/
const getDeferTooltip = () => {
if ( props.options.defer ) {
return __( 'This file will be loaded only after the page has rendered.', 'wphb' );
}
return __( 'Click to turn on the force-loading of this file after the page has rendered.', 'wphb' );
};
/**
* Tooltip for async action.
*
* @return {string} Tooltip.
*/
const getAsyncTooltip = () => {
if ( props.options.async ) {
return __( 'Async is enabled for this file, which will download the file asynchronously and execute it as soon as it’s ready. HTML parsing will be paused while the file is executed.', 'wphb' );
}
return __( 'Async is off for this file. Turn it on to download the file asynchronously and execute it as soon as it’s ready. HTML parsing will be paused while the file is executed.', 'wphb' );
};
/**
* Tooltip for inline action.
*
* @return {string} Tooltip.
*/
const getInlineTooltip = () => {
if ( hasDisableSwitch( 'inline' ) && ! props.options.block ) {
return __( 'This file is too large to be inlined. Limits can be overwritten with a "wphb_inline_limit_kb" filter.', 'wphb' );
} else if ( props.options.inline ) {
return __( 'Inline CSS is on for this file, which will add the style attributes to an HTML tag.', 'wphb' );
}
return __( 'Inline CSS is off for this file. Turn it on to add the style attributes to an HTML tag.', 'wphb' );
};
/**
* Tooltip for preload action.
*
* @return {string} Tooltip.
*/
const getPreloadTooltip = () => {
if ( props.options.preload ) {
return __( 'Preload is on for this file, which will download and cache the file so it is immediately available when the site is loaded.', 'wphb' );
}
return __( 'Preload is off for this file. Turn it on to download and cache the file so it is immediately available when the site is loaded.', 'wphb' );
};
/**
* Tooltip for disable action.
*
* @return {string} Tooltip.
*/
const getDisableTooltip = () => {
if ( props.options.block ) {
return __( 'Click to re-include', 'wphb' );
}
return __( "Don't load this file", 'wphb' );
};
/**
* Expand section on mobile view.
*
* @param {Object} e Target element.
*/
const expandSection = ( e ) => {
if ( window.innerWidth < 783 ) {
e.currentTarget.classList.toggle( 'open' );
}
};
/**
* Get shorthand type.
*
* @param {string} type
* @return {string} Type.
*/
const getType = ( type ) => {
const types = {
styles: 'css',
scripts: 'js',
fonts: 'font',
};
return types[ type ];
};
const type = getType( props.type );
const highlightClass = 'wphb-asset-action-highlighted';
const hasHighlightSwitch = (action) => {
const highlighted = getHighlighted();
return highlighted.hasOwnProperty(action) && !!highlighted[action];
};
function getActionToggleClassName(action) {
return classNames({
[highlightClass]: hasHighlightSwitch(action)
});
}
return (