Using Dreditor on other Drupal sites

Fri, 2013-08-02 10:01 -- drunken monkey

TL; DR:

I have adapted Daniel Kudwien's excellent Dreditor script, or at least the HTML autocomplete part, to work with other Drupal sites. See below to get it.

Let me elaborate …

Most people who regularly use the Drupal.org issue queues will probably (or hopefully) be familiar with Dreditor, Daniel Kudwien's incredibly useful user script which streamlines the UI, helps you to easily review patches and also contains autocompletion for HTML typed in textareas on the site.

That last part would of course also be useful for any other site which lets you enter (possibly filtered) HTML code anywhere, and especially since I started this blog I've really missed this functionality here regularly. I don't like WYSIWYG – I can handle HTML and don't need a eager but incompetent ghostwriter for it; but having to explicitly type the complete syntax is just a drag.

So, I tried just enabling Dreditor for this site, too, and wished for the best, but had no luck. (Note: There's a blog post by xjm which says this should work, but I guess it's outdated. It might work for Drupal 6 sites, though.) I didn't pursue it further at first, but after writing another blog post without autocompletion, I figured debugging the Javascript couldn't be too hard and should certainly be less work in the long run. And indeed, with just a few changes the script suddenly worked perfectly on this site, too.
So, seeing as others might also be glad about that, I decided to publish it here. I also got rid of all Drupal.org-specific extensions, to make the code smaller and easier to review.

Also, I added all other HTML tags that could be useful in site content (not <head> or the like), since Dreditor only contained the ones allowed on Drupal.org. If I missed some, or you'd like some formatted differently (I didn't take the time to format all block elements to include line breaks in the autocompletion), just edit the script's source code yourself, it should be pretty self-explanatory. All the tag completion settings are in Drupal.dreditor.syntaxAutocomplete.prototype.suggestions.html, and pretty straight-forward.

Caveats

Since I changed as little as possible, the script still depends on Drupal being installed on the site, so you'd need more adaptions to make it run on others as well. What's more, I think the main problem was that the original Dreditor script is of course meant for Drupal 6 (since that's what Drupal.org runs) – so my changes were probably (I'm only guessing here) "porting" the script to Drupal 7. I'm therefore not sure if it will run on D6 sites anymore. I'm only using it on this site, and haven't got the time to develop this further to make it work on other sites as well.

The Script Itself

So, without further ado, here it is:

Download/Install the script

(I don't know about other browsers, but if you just click the link in Firefox (and have Greasemonkey active) you'll be immediately prompted to install the script. While I of course guarantee there's nothing fishy with it (as long as I haven't been hacked), you might want to look at the source code first, just to be sure. Good practice on the internet, after all.)

And by the way, the script is of course released under license GPL v2 or later – since it's based on code lying on Drupal.org, there wouldn't be a way around that in any case.

Anyways, I hope this helps a few others. Have fun!

Image credit: screenshot by myself

Comments

Submitted by Austin (not verified) on

Waiting for you to come back again and share same intresting posts.

Add new comment

To prevent spam, submitting full URLs in comments is not allowed. Please omit the "http[s]://" portion of the URL and I will restore the complete URL on review.

Filtered HTML

  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <q> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <sup> <sub> <p> <br>
  • To post pieces of code, surround them with <code>...</code> tags. For PHP code, you can use <?php ... ?>, which will also colour it based on syntax.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.