Browse Source

sub/sup to guten

windhamdavid 4 weeks ago
parent
commit
da6c56eba6
2 changed files with 79 additions and 0 deletions
  1. 53 0
      dw-guten.js
  2. 26 0
      dw_guten.php

+ 53 - 0
dw-guten.js

@@ -0,0 +1,53 @@
+( function( wp ) {
+	
+	var SupButton = function( props ) {
+		return wp.element.createElement(
+			wp.editor.RichTextToolbarButton, {
+				icon: 'arrow-up',
+				title: 'Sup',
+				onClick: function() {
+					props.onChange( wp.richText.toggleFormat(
+						props.value,
+						{ type: 'dw-guten/sup' }
+					) );
+				},
+				isActive: props.isActive,
+			}
+		);
+	}
+
+	var SubButton = function( props ) {
+		return wp.element.createElement(
+			wp.editor.RichTextToolbarButton, {
+				icon: 'arrow-down',
+				title: 'Sub',
+				onClick: function() {
+					props.onChange( wp.richText.toggleFormat(
+						props.value,
+						{ type: 'dw-guten/sub' }
+					) );
+				},
+				isActive: props.isActive,
+			}
+		);
+	}
+
+	wp.richText.registerFormatType(
+		'dw-guten/sup', {
+			title: 'Sup',
+			tagName: 'sup',
+			className: null,
+			edit: SupButton
+		}
+	);
+
+	wp.richText.registerFormatType(
+		'dw-guten/sub', {
+			title: 'Sub',
+			tagName: 'sub',
+			className: null,
+			edit: SubButton
+		}
+	);
+
+} )( window.wp );

+ 26 - 0
dw_guten.php

@@ -0,0 +1,26 @@
+<?php
+/*
+Plugin Name: DW Guten
+Description: move theme functionality to plugin for Gutenberg features
+Author: windhamdavid
+Version: 0.1
+Author URI: https://davidawindham.com
+*/
+
+defined( 'ABSPATH' ) or die( 'yeah right' );
+
+function dw_guten_script_register() {
+	wp_register_script(
+		'dw-guten-js',
+		plugins_url( 'dw-guten.js', __FILE__ ),
+		array( 'wp-rich-text' , 'wp-element', 'wp-editor')
+	);
+}
+add_action( 'init', 'dw_guten_script_register' );
+
+function dw_guten_enqueue () {
+	wp_enqueue_script( 'dw-guten-js');
+}
+add_action( 'enqueue_block_editor_assets', 'dw_guten_enqueue' );
+
+?>