-
Notifications
You must be signed in to change notification settings - Fork 22
Creating a Custom Module
Snowball has a modular architecture for handling many different content types. In addition to 20+ native modules, Snowball supports custom modules.
Each module is a bundle of HTML, JavaScript, and JSON files:
"Admin" refers to the module's interface when authoring an article in the WordPress Admin Area. "Template" refers to the output generated by the module in the article.
Place the folder containing your bundle of files at /wordpress/wp-content/uploads/snowball/modules/.
Remember to keep the gulp task running while you're developing a custom module. This task minifies the JavaScript files and concatenates them to generate admins.js and templates.js.
This file defines the metadata for the custom module.
-
name: Name of the module. -
iconClasses: Font Awesome class for the module's icon in the toolbar. -
tags: Space-separated list of categories that the module will be filtered by in the toolbar (basic, media, social, data, meta). Custom modules will automatically have a "custom" category as well.
This file is where you create the admin interface for your module.
- The root element should be a
<form>element. - The values of
<input>and<textarea>elements are automatically saved to the database. - Use the
data-targetattribute to define where the value of an<input>or<textarea>is printed intemplate.html.
This file is where you include any JavaScript required for the module's admin interface. This can be useful for initializing a library, loading data, calculating a value, or triggering an event.
- Wrap your script in an IIFE:
(function ($) {
/* Put Content Here */
})(jQuery);
- When binding events, bind to
#snowball-mainand use event delegation to target your custom block.
$('#snowball-main').on('click', '.snowball-block-custom', function()...
- For dynamically generated data, store the value in an
<input type="hidden">element to save its state and use it in the module's template.
This file is used to generated the module's output based on the values set in the admin interface.
- The root element should be a
<section>element. - The
<section>element should have two classes:snowball-blockandsnowball-block-[name_of_your_module]. - To output the value of any
<input>or<textarea>found inadmin.html, wrap itsdata-targetvalue in{{and}}. For example, the value of a<input type="text" data-target="size"> can be outputted using{{size}}`. - Any styles used for module's output should be added in a
<style scoped>element.
This file is where you include any JavaScript required for the module's output. This can be useful for initializing a library, loading data, calculating a value, or triggering an event.