Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
65 lines (32 sloc) 4.26 KB

Editor plugins

I want to make it easy for people to add their own editors to 1999.io, playing various roles.

The plugins described here appear in the new PlugIns menu in 1999.io. When you choose one of the plugins a new page opens. What's on that page is entirely up to the plugin author. The first plugin I'm releasing is a simple lightweight template editor.

Plugins talk to the server via the JavaScript API. The user does not have to log in to the plugin because they have access to the same credentials 1999.io has since they run in the same domain. The data is stored in localStorage, but you don't have to worry about that, because you access the server through the API, they already know what to do with the localStorage values.

Obviously, sysops have to be careful about the plugins they run.

Key point: The plugins can do anything 1999.io does. It would be possible to write a whole new editor for 1999.io websites. Or write specialized tools that do things that 1999.io does not do. The hope is that, over time, many such plugins will be written.

How to configure

There's a new top-level section in config.json, plugIns, for configuring the pluglins. Here's an example config.json that has a plugIns section.

Each plugin has an identifier, which is the name of the sub-object, a value called name, which is what's displayed in the PlugIns menu in 1999.io, and url which is the address of the HTML page for the plugin.

How the plugins are accessed

Suppose you have a plugin whose identifier is imageEdit, and your server is running on designshop.com.

Then the address of the plugin would be http://designshop.com/plugin?name=imageEdit

The templateEdit plugin

The only plugin I'm releasing along with the plugins feature is templateEdit.

When you choose it from the PlugIns menu, a new page opens with the text of template in the edit box.

When you click the Update button, the template is saved. This means that all future page builds on this site will flow through this version of the template.

This is not reversible. You will no longer be able to edit the template using the outline editor in the Main menu in 1999.io. This is a very important point.

However there is an escape clause. If you have access to the server, you can reverse it by deleting misc/template.html in the user's public folder.

Writing your own plugin

The source code for the templateEdit plugin is in the code folder in this repo. It's meant to serve as example code for the kinds of things plugins do.

Using plugins in the editor

Here's a blog post on the 1999 user blog, showing how to access the PlugIns menu in the 1999.io editor.

The Editors menu in 1999.io

Here's a video that demos the Editors menu in 1999.io.

This is how you get an editor to appear in that menu, on the server.

Here's an example config.json that adds one item to the menu, the HTML source editor.

A few facts about the Editors menu.

  1. The user must enable the Editors menu in the Misc panel of the Settings dialog.

  2. They are only activated when the user is editing a post.

  3. When the command is chosen, the editor, which is just an HTML page, is loaded, and it's provided with parameters about the item through localStorage.

  4. The user edits the text of the item in the editor, and when they save, it is then sent to the server via the nodeStorage API. Since the editor is served through the same domain as 1999.io, it has access to the Twitter credentials. Obviously you should be careful about installing editors written by other people.

  5. I've written an example HTML editor, do a view source on this page to see how it works.