Project the editor revisited

In the previous project, we created a simple module to automatically load any JavaScript files indicated in the .info file. In this project, we are going to create a module that provides features for a specific JavaScript tool.

This project will improve the Simple Editor project we did in Chapter 4. Here, we will package an editor as a module, making it easy to use in many themes. We'll also make a little more use of PHP as a way of passing configuration options from the server to the client.

The goal of this project is to illustrate server-side PHP code can be used to generate JavaScript for the client. Here's a theme you may notice as we go: There is more than one way to write code like this, and in some cases, it's hard to tell which is preferable. We will run into two specific cases during our coding where we will need to make decisions about how something ought to be done.

We are going to make some improvements on the Simple Editor, add a few features, and rewrite some parts in light of what we now know. We will call our new editor Better Editor.

When we wrote our Simple Editor back in Chapter 4, we had not yet learned about themes. Instead of using theme functions to edit our code, we simply built strings where needed. Here, we are going to progress to theme functions.

Also, Simple Editor had only a few buttons, and adding more buttons required laborious re-writing of the code. Several things needed to be changed for each new button.

In Better Editor, we are going to change the way buttons are created. We will make it possible for the server to dictate what buttons get created. This means we will be writing a little extra PHP code for this section. Once again, it is simple code. Even if you are new to PHP, this code should be easy to follow.

Now, let's create our module.

Was this article helpful?

0 0

Post a comment