| 1 |
import Instance from './utils/instance'; |
| 2 |
|
| 3 |
const { ivent } = window; |
| 4 |
|
| 5 |
const { |
| 6 |
version, |
| 7 |
pro, |
| 8 |
|
| 9 |
themeName, |
| 10 |
settings, |
| 11 |
media_sizes: mediaSizes, |
| 12 |
disabledBlocks, |
| 13 |
allowPluginColorPalette, |
| 14 |
allowPluginCustomizer, |
| 15 |
allowTemplates, |
| 16 |
sidebars, |
| 17 |
timezone, |
| 18 |
|
| 19 |
googleMapsAPIKey, |
| 20 |
googleMapsAPIUrl, |
| 21 |
|
| 22 |
googleReCaptchaAPISiteKey, |
| 23 |
googleReCaptchaAPISecretKey, |
| 24 |
|
| 25 |
icons, |
| 26 |
shapes, |
| 27 |
fonts, |
| 28 |
customTypographyList, |
| 29 |
|
| 30 |
admin_url: adminUrl, |
| 31 |
admin_templates_url: adminTemplatesUrl, |
| 32 |
} = window.ghostkitVariables; |
| 33 |
|
| 34 |
// prepare media vars. |
| 35 |
const vars = {}; |
| 36 |
const screenSizes = []; |
| 37 |
Object.keys(mediaSizes).forEach((k) => { |
| 38 |
vars[`media_${k}`] = mediaSizes[k]; |
| 39 |
screenSizes.push(mediaSizes[k]); |
| 40 |
}); |
| 41 |
|
| 42 |
function escapeRegExp(s) { |
| 43 |
return s.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&'); |
| 44 |
} |
| 45 |
|
| 46 |
const GHOSTKIT = { |
| 47 |
version, |
| 48 |
pro, |
| 49 |
|
| 50 |
themeName, |
| 51 |
settings, |
| 52 |
|
| 53 |
disabledBlocks, |
| 54 |
|
| 55 |
allowPluginColorPalette, |
| 56 |
allowPluginCustomizer, |
| 57 |
allowTemplates, |
| 58 |
|
| 59 |
vars, |
| 60 |
replaceVars(str) { |
| 61 |
Object.keys(this.vars).forEach((key) => { |
| 62 |
str = str.replace( |
| 63 |
new RegExp(`#{ghostkitvar:${escapeRegExp(key)}}`, 'g'), |
| 64 |
`(max-width: ${this.vars[key]}px)` |
| 65 |
); |
| 66 |
}); |
| 67 |
|
| 68 |
return str; |
| 69 |
}, |
| 70 |
|
| 71 |
screenSizes, |
| 72 |
sidebars, |
| 73 |
timezone, |
| 74 |
|
| 75 |
googleMapsAPIKey, |
| 76 |
googleMapsAPIUrl, |
| 77 |
|
| 78 |
googleReCaptchaAPISiteKey, |
| 79 |
googleReCaptchaAPISecretKey, |
| 80 |
|
| 81 |
icons, |
| 82 |
shapes, |
| 83 |
fonts, |
| 84 |
customTypographyList, |
| 85 |
|
| 86 |
adminUrl, |
| 87 |
adminTemplatesUrl, |
| 88 |
|
| 89 |
/** |
| 90 |
* Instance helper functions. |
| 91 |
*/ |
| 92 |
instance: Instance, |
| 93 |
|
| 94 |
/** |
| 95 |
* Events helper functions. |
| 96 |
*/ |
| 97 |
events: ivent, |
| 98 |
|
| 99 |
/** |
| 100 |
* Check for block support GhostKit features. |
| 101 |
* |
| 102 |
* @param {Mixed} block - block props / block name |
| 103 |
* @param {string} featureName - feature name |
| 104 |
* @param {Mixed} defaultVal - default return value |
| 105 |
* |
| 106 |
* @return {Mixed} - supports flag |
| 107 |
*/ |
| 108 |
hasBlockSupport(block, featureName, defaultVal = false) { |
| 109 |
if (typeof block === 'string' && wp?.blocks?.getBlockType) { |
| 110 |
block = wp.blocks.getBlockType(block); |
| 111 |
} |
| 112 |
|
| 113 |
if ( |
| 114 |
block && |
| 115 |
block.ghostkit && |
| 116 |
block.ghostkit.supports && |
| 117 |
typeof block.ghostkit.supports[featureName] !== 'undefined' |
| 118 |
) { |
| 119 |
return block.ghostkit.supports[featureName]; |
| 120 |
} |
| 121 |
|
| 122 |
return defaultVal; |
| 123 |
}, |
| 124 |
}; |
| 125 |
|
| 126 |
window.GHOSTKIT = GHOSTKIT; |
| 127 |
|