vr-block.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. 'use strict';
  2. /* global wp */
  3. /* eslint react/react-in-jsx-scope: 0 */
  4. (function (blocks, components, i18n) {
  5. var registerBlockType = blocks.registerBlockType,
  6. UrlInput = blocks.UrlInput;
  7. var Placeholder = components.Placeholder,
  8. SelectControl = components.SelectControl;
  9. var __ = i18n.__;
  10. registerBlockType('jetpack/vr', {
  11. title: __('VR Image', 'jetpack'),
  12. icon: 'embed-photo',
  13. category: 'embed',
  14. support: {
  15. html: false
  16. },
  17. attributes: {
  18. url: {
  19. type: 'string'
  20. },
  21. view: {
  22. type: 'string'
  23. }
  24. },
  25. edit: function edit(props) {
  26. var attributes = props.attributes;
  27. var onSetUrl = function onSetUrl(value) {
  28. return props.setAttributes({ url: value });
  29. };
  30. var onSetView = function onSetView(value) {
  31. return props.setAttributes({ view: value });
  32. };
  33. var renderEdit = function renderEdit() {
  34. if (attributes.url && attributes.view) {
  35. return wp.element.createElement(
  36. 'div',
  37. { className: props.className },
  38. wp.element.createElement('iframe', {
  39. title: __('VR Image', 'jetpack'),
  40. allowFullScreen: 'true',
  41. frameBorder: '0',
  42. width: '100%',
  43. height: '300',
  44. src: 'https://vr.me.sh/view/?view=' + encodeURIComponent(attributes.view) + '&url=' + encodeURIComponent(attributes.url)
  45. })
  46. );
  47. }
  48. return wp.element.createElement(
  49. 'div',
  50. null,
  51. wp.element.createElement(
  52. Placeholder,
  53. {
  54. key: 'placeholder',
  55. instructions: __('Enter URL to VR image', 'jetpack'),
  56. icon: 'format-image',
  57. label: __('VR Image', 'jetpack'),
  58. className: props.className
  59. },
  60. wp.element.createElement(UrlInput, {
  61. value: attributes.url,
  62. onChange: onSetUrl
  63. }),
  64. wp.element.createElement(
  65. 'div',
  66. { style: { marginTop: '10px' } },
  67. wp.element.createElement(SelectControl, {
  68. label: __('View Type', 'jetpack'),
  69. value: attributes.view,
  70. onChange: onSetView,
  71. options: [{ label: '', value: '' }, { label: __('360', 'jetpack'), value: '360' }, { label: __('Cinema', 'jetpack'), value: 'cinema' }]
  72. })
  73. )
  74. )
  75. );
  76. };
  77. return renderEdit();
  78. },
  79. save: function save(props) {
  80. return wp.element.createElement(
  81. 'div',
  82. { className: props.className },
  83. wp.element.createElement('iframe', {
  84. title: __('VR Image', 'jetpack'),
  85. allowFullScreen: 'true',
  86. frameBorder: '0',
  87. width: '100%',
  88. height: '300',
  89. src: 'https://vr.me.sh/view/?view=' + encodeURIComponent(props.attributes.view) + '&url=' + encodeURIComponent(props.attributes.url)
  90. })
  91. );
  92. }
  93. });
  94. })(wp.blocks, wp.components, wp.i18n);