PluginProbe
CBX Map for Google Map & OpenStreetMap / 2.0.1
CBX Map for Google Map & OpenStreetMap v2.0.1
trunk 1.1.10 1.1.11 1.1.12 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5
cbxgooglemap / assets / js / blocks / cbxgooglemap-block.js

cbxgooglemap-block.js in CBX Map for Google Map & OpenStreetMap 2.0.1, at assets/js/blocks/cbxgooglemap-block.js

172 lines 8.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 'use strict';
2
3 (function (blocks, element, components, editor, ServerSideRender, blockEditor) {
4
5 var el = element.createElement,
6 registerBlockType = blocks.registerBlockType,
7 InspectorControls = blockEditor.InspectorControls,
8 RangeControl = components.RangeControl,
9 Panel = components.Panel,
10 PanelBody = components.PanelBody,
11 PanelRow = components.PanelRow,
12 TextControl = components.TextControl,
13 TextareaControl = components.TextareaControl,
14 CheckboxControl = components.CheckboxControl,
15 RadioControl = components.RadioControl,
16 SelectControl = components.SelectControl,
17 ToggleControl = components.ToggleControl,
18 PanelColorPicker = editor.PanelColorSettings,
19 DateTimePicker = components.DateTimePicker,
20 HorizontalRule = components.HorizontalRule,
21 ExternalLink = components.ExternalLink;
22
23 var MediaUpload = wp.editor.MediaUpload;
24
25 var iconEl = el('svg', {width: 20, height: 20},
26 el('path', {d: "M8,0C4.687,0,2,2.687,2,6c0,3.854,4.321,8.663,5,9.398C7.281,15.703,7.516,16,8,16s0.719-0.297,1-0.602 C9.679,14.663,14,9.854,14,6C14,2.687,11.313,0,8,0z M8,10c-2.209,0-4-1.791-4-4s1.791-4,4-4s4,1.791,4,4S10.209,10,8,10z M8,4 C6.896,4,6,4.896,6,6s0.896,2,2,2s2-0.896,2-2S9.104,4,8,4z"})
27 );
28
29 registerBlockType('codeboxr/cbxgooglemap', {
30 title: cbxgooglemap_block.block_title,
31 icon: iconEl,
32 category: cbxgooglemap_block.block_category,
33
34 edit: function (props) {
35 return [
36 el(ServerSideRender, {
37 block: 'codeboxr/cbxgooglemap',
38 attributes: props.attributes,
39 }),
40 el(InspectorControls, {},
41 el(PanelBody, {title: cbxgooglemap_block.general_settings.title, initialOpen: true},
42
43 // Always show this field
44 el(SelectControl,
45 {
46 label: cbxgooglemap_block.general_settings.id,
47 options: cbxgooglemap_block.general_settings.id_options,
48 onChange: (value) => {
49 props.setAttributes({id: value ? parseInt(value) : ''});
50 },
51 value: props.attributes.id
52 }
53 ),
54
55 // Conditionally show rest of fields only if id is not numeric
56 (!props.attributes.id || isNaN(props.attributes.id)) ? el('div', {},
57 [
58 el('p', {className: 'cbxgooglemap_block_note'}, cbxgooglemap_block.general_settings.id_note),
59 el('hr', {}),
60 el('h3', {className: 'cbxgooglemap_block_note_custom_attribute'}, cbxgooglemap_block.general_settings.custom_attribute_note),
61
62 el(SelectControl, {
63 label: cbxgooglemap_block.general_settings.maptype,
64 options: cbxgooglemap_block.general_settings.maptype_options,
65 onChange: (value) => props.setAttributes({maptype: value}),
66 value: props.attributes.maptype
67 }),
68
69 el(TextControl, {
70 label: cbxgooglemap_block.general_settings.lat,
71 onChange: (value) => props.setAttributes({lat: value}),
72 value: props.attributes.lat
73 }),
74
75 el(TextControl, {
76 label: cbxgooglemap_block.general_settings.lng,
77 onChange: (value) => props.setAttributes({lng: value}),
78 value: props.attributes.lng
79 }),
80
81 el(TextControl, {
82 label: cbxgooglemap_block.general_settings.width,
83 onChange: (value) => props.setAttributes({width: value}),
84 value: props.attributes.width
85 }),
86
87 el(TextControl, {
88 label: cbxgooglemap_block.general_settings.height,
89 onChange: (value) => props.setAttributes({height: value}),
90 value: props.attributes.height
91 }),
92
93 el(TextControl, {
94 label: cbxgooglemap_block.general_settings.zoom,
95 onChange: (value) => props.setAttributes({zoom: value}),
96 value: props.attributes.zoom
97 }),
98
99 el(ToggleControl, {
100 label: cbxgooglemap_block.general_settings.scrollwheel,
101 onChange: (value) => props.setAttributes({scrollwheel: value}),
102 checked: props.attributes.scrollwheel
103 }),
104
105 el(ToggleControl, {
106 label: cbxgooglemap_block.general_settings.showinfo,
107 onChange: (value) => props.setAttributes({showinfo: value}),
108 checked: props.attributes.showinfo
109 }),
110
111 el(ToggleControl, {
112 label: cbxgooglemap_block.general_settings.infow_open,
113 onChange: (value) => props.setAttributes({infow_open: value}),
114 checked: props.attributes.infow_open
115 }),
116
117 el(TextControl, {
118 label: cbxgooglemap_block.general_settings.heading,
119 onChange: (value) => props.setAttributes({heading: value}),
120 value: props.attributes.heading
121 }),
122
123 el(TextControl, {
124 label: cbxgooglemap_block.general_settings.address,
125 onChange: (value) => props.setAttributes({address: value}),
126 value: props.attributes.address
127 }),
128
129 el(TextControl, {
130 label: cbxgooglemap_block.general_settings.website,
131 onChange: (value) => props.setAttributes({website: value}),
132 value: props.attributes.website
133 }),
134
135 el(MediaUpload, {
136 label: cbxgooglemap_block.general_settings.mapicon,
137 value: props.attributes.mapicon,
138 onSelect: (media) => {
139 props.setAttributes({mapicon: media.url});
140 },
141 type: 'image',
142 render: function (obj) {
143 return el(components.Button, {
144 className: 'components-icon-button image-block-btn is-button is-default is-large',
145 onClick: obj.open
146 },
147 el('svg', {className: 'dashicon dashicons-edit', width: '20', height: '20'},
148 el('path', {d: "M2.25 1h15.5c.69 0 1.25.56 1.25 1.25v15.5c0 .69-.56 1.25-1.25 1.25H2.25C1.56 19 1 18.44 1 17.75V2.25C1 1.56 1.56 1 2.25 1zM17 17V3H3v14h14zM10 6c0-1.1-.9-2-2-2s-2 .9-2 2 .9 2 2 2 2-.9 2-2zm3 5s0-6 3-6v10c0 .55-.45 1-1 1H5c-.55 0-1-.45-1-1V8c2 0 3 4 3 4s1-3 3-3 3 2 3 2z"})
149 ),
150 el('span', {}, cbxgooglemap_block.general_settings.mapicon_select)
151 );
152 }
153 })
154 ]
155 ) : null
156 )
157 )
158 ];
159 },
160
161 save: function () {
162 return null;
163 },
164 });
165 }(
166 window.wp.blocks,
167 window.wp.element,
168 window.wp.components,
169 window.wp.editor,
170 window.wp.serverSideRender,
171 window.wp.blockEditor
172 ));