Guest User

Untitled

a guest
Feb 23rd, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. (function (wp) {
  2. //WordPress APIs
  3. //Render function
  4. var el = wp.element.createElement;
  5. //Translations
  6. var __ = wp.i18n.__;
  7. //Text input control
  8. var TextControl = wp.blocks.InspectorControls.TextControl;
  9. //Create block
  10. wp.blocks.registerBlockType('shelob9/metatest2', {
  11. title: __('Meta 2 and Markup', 'metatest'),
  12. category: 'common',
  13. edit: function (props) {
  14. //Make sure "fake_content" and "content" are in sync
  15. if( props.attributes.fake_content !== props.attributes.content ){
  16. props.setAttributes({fake_content: props.attributes.content });
  17.  
  18. }
  19. //Edit interface
  20. return el(
  21. 'div',
  22. {
  23.  
  24. },
  25. [
  26. el(
  27. 'p',
  28. {
  29. className: props.className
  30. },
  31. props.attributes.content
  32. ),
  33. el(
  34. TextControl,
  35. {
  36. label: __('Content', 'metatest'),
  37. value: props.attributes.fake_content,
  38. onChange: function (value) {
  39. //Update both attributes
  40. props.setAttributes({
  41. fake_content: value,
  42. content: value
  43. });
  44. }
  45. },
  46. )
  47. ]
  48. )
  49.  
  50. },
  51. save: function (props) {
  52. return el(
  53. 'p',
  54. {className: props.className},
  55. //Save the non-meta attribute
  56. props.attributes.fake_content
  57. );
  58. }
  59. });
  60. })(
  61. window.wp
  62. );
Add Comment
Please, Sign In to add comment