| 1 |
var blockStyle = { |
| 2 |
backgroundColor: 'azure', |
| 3 |
color: '#666', |
| 4 |
padding: '15px' |
| 5 |
} |
| 6 |
wp.blocks.registerBlockType('mrplan/mplan-block', { |
| 7 |
title: 'MisterPlan Motor de Reservas', |
| 8 |
icon: 'media-spreadsheet', |
| 9 |
category: 'layout', |
| 10 |
edit: editBlock, |
| 11 |
save: function() { |
| 12 |
return wp.element.createElement( 'h2', { style: blockStyle }, 'Este es el contenido que se salva!!' ); |
| 13 |
} |
| 14 |
} |
| 15 |
) |
| 16 |
|
| 17 |
function editBlock(props){ |
| 18 |
function updateheader(event) { |
| 19 |
props.setAttributes({ |
| 20 |
header: event.target.value |
| 21 |
}) |
| 22 |
} |
| 23 |
function updatecontent(event) { |
| 24 |
props.setAttributes({ |
| 25 |
content: event.target.value |
| 26 |
}) |
| 27 |
} |
| 28 |
var element = null; |
| 29 |
const response = fetch( `https://api.microlink.io?`, { |
| 30 |
cache: 'no-cache', |
| 31 |
headers: { |
| 32 |
'user-agent': 'WP Block', |
| 33 |
'content-type': 'application/json' |
| 34 |
}, |
| 35 |
method: 'GET', |
| 36 |
redirect: 'follow', |
| 37 |
referrer: 'no-referrer', |
| 38 |
}) |
| 39 |
.then( |
| 40 |
returned => { |
| 41 |
element = wp.element.createElement( |
| 42 |
"div", |
| 43 |
null, |
| 44 |
wp.element.createElement( |
| 45 |
"h3", |
| 46 |
null, |
| 47 |
"MisterPlan" |
| 48 |
), |
| 49 |
wp.element.createElement( |
| 50 |
"input", |
| 51 |
{ |
| 52 |
type: "text", |
| 53 |
value: props.attributes.header, |
| 54 |
onChange: updateheader |
| 55 |
} |
| 56 |
), |
| 57 |
wp.element.createElement( |
| 58 |
"p", |
| 59 |
null, |
| 60 |
"Seleccione el motor" |
| 61 |
), |
| 62 |
wp.element.createElement( |
| 63 |
"select",{ |
| 64 |
onChange: updatecontent |
| 65 |
}, |
| 66 |
wp.element.createElement('option', |
| 67 |
{ |
| 68 |
value: '1', |
| 69 |
text: 'a', |
| 70 |
}, 'a') |
| 71 |
), |
| 72 |
); |
| 73 |
} |
| 74 |
); |
| 75 |
|
| 76 |
return element; |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
return "<select><option value='a'>A</option></select>"; |
| 81 |
return wp.element.createElement('select',{ style: blockStyle }, 'Este es el contenido que se salva!!' ) |
| 82 |
} |