| 1 |
/* Prismatic - Plain Flavor Block */ |
| 2 |
|
| 3 |
var |
| 4 |
el = wp.element.createElement, |
| 5 |
registerBlockType = wp.blocks.registerBlockType, |
| 6 |
PlainText = wp.editor.PlainText, |
| 7 |
__ = wp.i18n.__; |
| 8 |
|
| 9 |
registerBlockType('prismatic/blocks', { |
| 10 |
|
| 11 |
title : 'Prismatic', |
| 12 |
icon : 'editor-code', |
| 13 |
category : 'formatting', |
| 14 |
keywords : [ |
| 15 |
__('code', 'prismatic'), |
| 16 |
__('pre', 'prismatic'), |
| 17 |
__('prism', 'prismatic'), |
| 18 |
__('highlight', 'prismatic'), |
| 19 |
__('prismatic', 'prismatic') |
| 20 |
], |
| 21 |
attributes : { |
| 22 |
content : { |
| 23 |
type : 'string', |
| 24 |
source : 'text', |
| 25 |
selector : 'pre code', |
| 26 |
}, |
| 27 |
backgroundColor : { |
| 28 |
type : 'string', |
| 29 |
default : '#f7f7f7', |
| 30 |
}, |
| 31 |
textColor : { |
| 32 |
type : 'string', |
| 33 |
default : '#373737', |
| 34 |
}, |
| 35 |
}, |
| 36 |
|
| 37 |
edit : function(props) { |
| 38 |
|
| 39 |
function onChangeContent(newValue) { |
| 40 |
props.setAttributes({ content: newValue }); |
| 41 |
} |
| 42 |
|
| 43 |
return el( |
| 44 |
PlainText, |
| 45 |
{ |
| 46 |
tagName : 'pre', |
| 47 |
key : 'editable', |
| 48 |
placeholder : __('Add code..', 'prismatic'), |
| 49 |
onChange : onChangeContent, |
| 50 |
className : props.className, |
| 51 |
style : { backgroundColor : props.attributes.backgroundColor, color : props.attributes.textColor }, |
| 52 |
value : props.attributes.content, |
| 53 |
} |
| 54 |
); |
| 55 |
|
| 56 |
}, |
| 57 |
|
| 58 |
save : function(props) { |
| 59 |
return el('pre', null, el('code', null, props.attributes.content)); |
| 60 |
}, |
| 61 |
|
| 62 |
}); |