You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 line
1.4KB

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