| 1 |
import { __ } from '@wordpress/i18n' |
| 2 |
import { isString, toLower } from 'lodash' |
| 3 |
import { useUserStore } from '@library/state/User' |
| 4 |
|
| 5 |
/** |
| 6 |
* Will check if the given string contains the search string |
| 7 |
* |
| 8 |
* @param {string} string |
| 9 |
* @param {string} searchString |
| 10 |
*/ |
| 11 |
|
| 12 |
export function search(string, searchString) { |
| 13 |
// type validation |
| 14 |
if (!isString(string) || !isString(searchString)) { |
| 15 |
return false |
| 16 |
} |
| 17 |
|
| 18 |
// changing case |
| 19 |
string = toLower(string) |
| 20 |
searchString = toLower(searchString) |
| 21 |
|
| 22 |
// comparing |
| 23 |
return -1 !== searchString.indexOf(string) ? true : false |
| 24 |
} |
| 25 |
|
| 26 |
export const openModal = (source) => setModalVisibility(source, 'open') |
| 27 |
// export const closeModal = () => setModalVisibility('', 'close') |
| 28 |
export function setModalVisibility(source = 'broken-event', state = 'open') { |
| 29 |
useUserStore.setState({ |
| 30 |
entryPoint: source, |
| 31 |
}) |
| 32 |
window.dispatchEvent( |
| 33 |
new CustomEvent(`extendify::${state}-library`, { |
| 34 |
detail: source, |
| 35 |
bubbles: true, |
| 36 |
}), |
| 37 |
) |
| 38 |
} |
| 39 |
|
| 40 |
export function getPluginDescription(plugin) { |
| 41 |
switch (plugin) { |
| 42 |
case 'editorplus': |
| 43 |
return 'Editor Plus' |
| 44 |
case 'ml-slider': |
| 45 |
return 'MetaSlider' |
| 46 |
} |
| 47 |
return plugin |
| 48 |
} |
| 49 |
|
| 50 |
export function getTaxonomyName(key) { |
| 51 |
switch (key) { |
| 52 |
case 'siteType': |
| 53 |
return __('Site Type', 'extendify') |
| 54 |
case 'patternType': |
| 55 |
return __('Content', 'extendify') |
| 56 |
case 'layoutType': |
| 57 |
return __('Page Types', 'extendify') |
| 58 |
} |
| 59 |
return key |
| 60 |
} |
| 61 |
|