common.js
2 weeks ago
rest.js
2 weeks ago
search.js
2 weeks ago
site-import.js
2 years ago
svg.js
2 weeks ago
common.js
62 lines
| 1 | import { __ } from '@wordpress/i18n'; |
| 2 | |
| 3 | const untrailingSlashIt = ( str ) => str.replace( /\/$/, '' ); |
| 4 | const trailingSlashIt = ( str ) => untrailingSlashIt( str ) + '/'; |
| 5 | |
| 6 | const ONBOARDING_CAT = { |
| 7 | business: __( 'Business', 'templates-patterns-collection' ), |
| 8 | blog: __( 'Blog', 'templates-patterns-collection' ), |
| 9 | portfolio: __( 'Portfolio', 'templates-patterns-collection' ), |
| 10 | education: __( 'Education', 'templates-patterns-collection' ), |
| 11 | woocommerce: __( 'eCommerce', 'templates-patterns-collection' ), |
| 12 | news: __( 'News', 'templates-patterns-collection' ), |
| 13 | nonprofit: __( 'Non-Profit', 'templates-patterns-collection' ), |
| 14 | health: __( 'Health', 'templates-patterns-collection' ), |
| 15 | }; |
| 16 | |
| 17 | const EDITOR_MAP = { |
| 18 | gutenberg: { |
| 19 | icon: 'gutenberg.jpg', |
| 20 | niceName: 'Gutenberg', |
| 21 | }, |
| 22 | elementor: { |
| 23 | icon: 'elementor.jpg', |
| 24 | niceName: 'Elementor', |
| 25 | }, |
| 26 | }; |
| 27 | |
| 28 | const sendPostMessage = ( data ) => { |
| 29 | const frame = document.getElementById( 'ti-ss-preview' ); |
| 30 | if ( ! frame ) { |
| 31 | return; |
| 32 | } |
| 33 | |
| 34 | frame.contentWindow.postMessage( |
| 35 | { |
| 36 | call: 'starterTemplatePreviewDispatch', |
| 37 | value: data, |
| 38 | }, |
| 39 | '*' |
| 40 | ); |
| 41 | }; |
| 42 | |
| 43 | /** |
| 44 | * Convert text to file URL. |
| 45 | * |
| 46 | * @param {string} text - Text to convert |
| 47 | * @return {string} - File URL |
| 48 | */ |
| 49 | const textToFileURL = ( text ) => { |
| 50 | const blob = new Blob( [ text ], { type: 'text/plain' } ); |
| 51 | return URL.createObjectURL( blob ); |
| 52 | }; |
| 53 | |
| 54 | export { |
| 55 | trailingSlashIt, |
| 56 | untrailingSlashIt, |
| 57 | sendPostMessage, |
| 58 | EDITOR_MAP, |
| 59 | ONBOARDING_CAT, |
| 60 | textToFileURL, |
| 61 | }; |
| 62 |