Skip to content

Commit

Permalink
add plugin registry to markdown field
Browse files Browse the repository at this point in the history
  • Loading branch information
mibewh committed Aug 7, 2020
1 parent 4872c20 commit 0918ce4
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/js/fields/advanced/MarkdownField.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,20 @@

if (!self.editor)
{
// Replace toolbar buttons with configured plugins
var toolbar = self.options.markdown.toolbar;
if (toolbar && Alpaca.isArray(toolbar))
{
for (var i = 0; i < toolbar.length; i++)
{
var toolbarItem = toolbar[i];
if (Alpaca.isString(toolbarItem) && toolbarItem in Alpaca.Fields.MarkdownField.ToolbarButtonPlugins )
{
toolbar[i] = Alpaca.Fields.MarkdownField.ToolbarButtonPlugins[toolbarItem];
}
}
}

self.editor = new SimpleMDE(self.options.markdown);
}

Expand Down Expand Up @@ -195,6 +209,13 @@
/* end_builder_helpers */
});

Alpaca.Fields.MarkdownField.ToolbarButtonPlugins = {};

Alpaca.Fields.MarkdownField.registerToolbarButtonPlugin = function(key, config)
{
Alpaca.Fields.MarkdownField.ToolbarButtonPlugins[key] = config;
};

Alpaca.registerFieldClass("markdown", Alpaca.Fields.MarkdownField);

})(jQuery);

0 comments on commit 0918ce4

Please sign in to comment.