Skip to content

Instantly share code, notes, and snippets.

@andreiglingeanu
Created November 24, 2023 08:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreiglingeanu/a9d7b14db20aeaa882c1a7672b890069 to your computer and use it in GitHub Desktop.
Save andreiglingeanu/a9d7b14db20aeaa882c1a7672b890069 to your computer and use it in GitHub Desktop.
import { dispatch, select } from '@wordpress/data'
import swipercss from '!!raw-loader!../../../../libs/swiper/swiper-bundle.min.css'
import { applyFilters } from '@wordpress/hooks'
export default function gspb_Css_Final(id, final_css = '', props = {}) {
let inlineloading = false
if (greenShift_params.isSaveInline) {
inlineloading = true
} else {
if (
!document.body.classList.contains('post-type-post') &&
!document.body.classList.contains('post-type-page')
) {
inlineloading = true
}
/*
let blocksyVersion = 1
if (typeof ct_localizations !== 'undefined') {
let blocksyversion = ct_localizations.theme_version
if (blocksyversion) {
blocksyVersion = blocksyversion.charAt(0)
}
}
if (blocksyVersion >= 2) {
inlineloading = false
}
*/
if (!inlineloading && typeof props.clientId !== 'undefined') {
let block = document.getElementById('block-' + props.clientId)
if (
block &&
block.closest('.block-library-block__reusable-block-container')
) {
inlineloading = true
} else if (block === null) {
inlineloading = true
}
if (!inlineloading && block && block.closest('.wp-block-query')) {
inlineloading = true
}
}
if (
!inlineloading &&
document.querySelector('.is-template-mode') !== null
) {
inlineloading = true
}
if (
!inlineloading &&
typeof props.attributes.background !== 'undefined' &&
props.attributes.background.dynamicEnable
) {
inlineloading = true
}
}
inlineloading = applyFilters(
'greenshift.editor.inlineCssLoading',
inlineloading
)
//Inline for template and widget editors
if (inlineloading && typeof props.setAttributes !== 'undefined') {
if (typeof props.name !== 'undefined') {
if (
props.name === 'greenshift-blocks/swiper' ||
props.name === 'greenshift-blocks/product-gallery'
) {
final_css += swipercss
}
}
let previousstyles =
typeof props.attributes.inlineCssStyles !== 'undefined'
? props.attributes.inlineCssStyles
: ''
if (previousstyles != final_css) {
props.setAttributes({
inlineCssStyles: final_css,
})
}
} else {
if (
typeof props.setAttributes !== 'undefined' &&
typeof props.attributes.inlineCssStyles !== 'undefined'
) {
if (props.attributes.inlineCssStyles) {
props.setAttributes({
inlineCssStyles: null,
})
}
}
// Get The Stored CSS
let storedCSS = select('blockypage-css').getCSS()
if (final_css) {
if (id) {
if (storedCSS[id] != final_css) {
dispatch('blockypage-css').addCSS(id, final_css)
}
}
} else {
if (id in storedCSS) {
dispatch('blockypage-css').removeCSS(id)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment