PluginProbe
MLSImport: IDX Plugin & MLS Plugin for Real Estate Listings / 7.1.1
MLSImport: IDX Plugin & MLS Plugin for Real Estate Listings v7.1.1
7.2.1 7.2 7.1.2 7.1.1 7.1 7.0.4 7.0.6 7.0.7 6.3.8 6.3.7 6.3.6 6.3.5 6.3.4 6.3.3 6.3.1 trunk 5.7.3 5.7.5 5.8.1 5.8.2 5.8.3 5.8.4 5.8.6 6.0.4 6.0.5 All 36 releases
mlsimport / admin / js / mlsimport-property-sections-block.js

mlsimport-property-sections-block.js in MLSImport: IDX Plugin & MLS Plugin for Real Estate Listings 7.1.1, at admin/js/mlsimport-property-sections-block.js

59 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Editor registration for the standalone single-property section blocks.
3 *
4 * Plain ES5, no build step. Loops the localized MLSImportSections list and
5 * registers one dynamic block per section. Each block renders server-side via
6 * ServerSideRender (the PHP render_callback is the single source of markup).
7 */
8 ( function ( blocks, element, serverSideRender, blockEditor ) {
9 // Bail out if the block API or the localized section list isn't available
10 if ( ! blocks || ! window.MLSImportSections ) {
11 return;
12 }
13
14 // Local aliases and the block icon source
15 var el = element.createElement;
16 var useBlockProps = ( blockEditor || {} ).useBlockProps;
17 var iconUrl = window.MLSImportSectionsIcon || '';
18
19 // Block toolbar/menu icon: the localized image URL, else a Dashicon fallback.
20 // The PNG is 19x14, so it keeps its natural size (width/height auto beats the
21 // width=24 height=24 attributes wp.components.Icon clones onto it) — a forced
22 // square stretched it to 24x24 and blurred it.
23 var icon = iconUrl
24 ? el( 'img', { src: iconUrl, alt: '', style: { width: 'auto', height: 'auto' } } )
25 : 'admin-home';
26
27 // Register one dynamic block per localized property section
28 window.MLSImportSections.forEach( function ( section ) {
29 // Namespaced block name, e.g. "mlsimport/property-gallery"
30 var blockName = 'mlsimport/property-' + section.slug;
31
32 blocks.registerBlockType( blockName, {
33 apiVersion: 2,
34 title: section.title,
35 icon: icon,
36 category: 'mlsimport-property',
37 attributes: {
38 // Optional explicit property id; 0 means "use the current post"
39 id: { type: 'number', default: 0 }
40 },
41 // Editor view: a server-rendered preview of the section
42 edit: function ( props ) {
43 // apiVersion 2 requires useBlockProps() on the edit root, or the
44 // block has no selectable wrapper in the editor.
45 var blockProps = useBlockProps ? useBlockProps() : {};
46 // Render the PHP markup for this block/attributes inside the wrapper
47 return el( 'div', blockProps, el( serverSideRender, {
48 block: blockName,
49 attributes: props.attributes
50 } ) );
51 },
52 // Dynamic block: markup comes from PHP, so nothing is saved to post content
53 save: function () {
54 return null;
55 }
56 } );
57 } );
58 } )( window.wp.blocks, window.wp.element, window.wp.serverSideRender, window.wp.blockEditor );
59