Global Constant
Steve Nay's ramblings

Dialoguing module

You may remember my previous two posts about dialoguing. I illustrated two methods for doing it: form submission with watch() and web events. I’ve been using the second of those methods so much that I wanted to abstract it out to a module. a163x121 is the result.

Documentation

Here’s how it works. First, there are two configuration options that you need to specify when you import the module:

There is one method that does it all, called get_data(). Here are the parameters:

Example

I retrofitted the example from this post to use the new module, so the code may look familiar to you. First, I added one line to the meta block:

Then I rewrote the rule a bit:

The original byufb_dir_search() function contained two things: First there were some lines to unhides the search results box and show a progress bar; second there was the dialoguing code. Since the module only handles the dialoguing code, I broke out those first two lines into a new function called byufb_dir_search_prep(), which in turn calls byufb_dir_search(). The “Search” button calls the prep function. I passed the name “byufb_dir_search” to the dialoguing module’s get_data() action so it knows what to name the JavaScript function.

The rule that handles the web event is exactly the same as before; no changes were necessary.

Conclusion

This simplifies the code by abstracting out the mundane JavaScript to get data from the page and raise a web event containing that data.

What do you think?