Skip to content

Instantly share code, notes, and snippets.

@westonruter
Created August 16, 2018 00:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save westonruter/911bffeff2b60b4204551f139da8ee32 to your computer and use it in GitHub Desktop.
Save westonruter/911bffeff2b60b4204551f139da8ee32 to your computer and use it in GitHub Desktop.
diff --git a/blocks/amp-mathml/index.js b/blocks/amp-mathml/index.js
index 2b0662cb..52c897d4 100644
--- a/blocks/amp-mathml/index.js
+++ b/blocks/amp-mathml/index.js
@@ -33,17 +33,21 @@ export default registerBlockType(
}
},
- edit( { attributes, setAttributes } ) {
+ edit( { attributes, isSelected, setAttributes } ) {
const { dataFormula } = attributes;
- return (
- <PlainText
- key='formula'
- value={ dataFormula }
- placeholder={ __( 'Insert formula', 'amp' ) }
- onChange={ ( value ) => setAttributes( { dataFormula: value } ) }
- />
- );
+ if ( isSelected ) {
+ return (
+ <PlainText
+ key='formula'
+ value={ dataFormula }
+ placeholder={ __( 'Insert formula', 'amp' ) }
+ onChange={ ( value ) => setAttributes( { dataFormula: value } ) }
+ />
+ );
+ } else {
+ return <amp-mathml layout="container" data-formula={ dataFormula }></amp-mathml>
+ }
},
save( { attributes } ) {
diff --git a/includes/admin/class-amp-editor-blocks.php b/includes/admin/class-amp-editor-blocks.php
index 29a06510..46c42e6f 100644
--- a/includes/admin/class-amp-editor-blocks.php
+++ b/includes/admin/class-amp-editor-blocks.php
@@ -138,6 +138,8 @@ class AMP_Editor_Blocks {
array( 'wp-blocks', 'lodash', 'wp-i18n', 'wp-element', 'wp-components' ),
AMP__VERSION
);
+
+ wp_enqueue_script( 'amp-mathml' );
}
wp_enqueue_script(
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment