Me right now
  • Just listened to: Bartok  
  • Currently learning: Little Sweep, Belshazzar  
  • Watching: Bluestone 42, Broadchurch, Foyle  
  • Just recorded: Lead me not  
Do you want singing lessons? Contact ME HERE
Miniblog
  • Should Woods withdraw from the Masters? For the good of the game and as a good example, yes, probably.  1 month ago
  • The Pope has appointed 9 people to oversee Vatican reform. Good. But let's hope politics doesn't now dominate, displacing beatitude-living 1 month ago
  • Now talking seriously about moving house. Urs has seen one that would suit. Scary 6 months ago
  • Rutter makes it to validation: he appears in yesterday's Guardian crossword (25 ac, part of the cluing, not the answer!) 7 months ago
  • Size of grain of rice = its length (L) times radius (R) times pi. Which is why Spaniards eat a rice dish called Pi L R 7 months ago
  • Last night dreamed about having a big house with dining room with huge table and a grand piano... That'll keep me honest.  7 months ago
  • Another bit of WordPress plug-in-ery done 7 months ago
  • Back in the hotseat after the holiday. Lots of Wordpress plug-in work today.  8 months ago
  • Happy to see the Great British Bake Off back again. Don't know why I like it so much, but I do! 9 months ago
  • Another tune written. Might end up as an anthem? 9 months ago
  • HtmlBox – simple post/load stuff

    I have been using the Xinha wysiwyg  software on a particular site, but was getting fed up with it. The latest project required just a small number of wysiwyg options (bold, italic, underline, maybe lists) to create simple, text-only emails. The site, like most of mine, runs with jquery, so I did about 30 seconds research and came up with HtmlBox. It’s free, doesn’t even need you to acknowledge where it comes from, and it’s small (14k).

    That said, the documentation is a little lightweight, too. So while it was very easy to set it up so that an existing textarea could use it, I had to spend a bit of time finding out how to refine it.

    So, to speed it up for others, here are some of the things I found:

    1. Icon set didn’t show. I am intending to use htmlbox multiple times on the site, so I stored it in the /js folder, which I linked to relatively. That’s fine, but it couldn’t then find the icons. It was only when I realised that there was a list of options at the end of the manual that I discovered the ‘idir’ option. Give that option a string which is the path to the icons, and you’re done. There are two icon sets. I use the default.
    2. Couldn’t see the text on a confirmation screen. Before sending the email I have a popup dialog so that I can confirm the text I want to send. This didn’t work at first. Not until I discovered (again, look at the end of the manual) get_text() and get_html(). To get it to work properly, you’ll need to assign your htmlbox call a variable name. So you don’t just go $(“#content”).HtmlBox({options}), you go html_box = $(“#content”).HtmlBox({options}). Now html_box.get_html() will get you the text you’ve typed, with the html codes intact (get_text()) will strip the html. Xhtml is available.
    3. Saving the text. I save the email text to the database so that I can come back and edit it before sending. The non-htmlbox version of the form was just $.post-ed using serialize(), but that didn’t work after htmlbox came along (htmlbox creates its own iframe to replace the textarea). Again get_html() came to the rescue – assign the result of html_box.get_html() to textarea.val() and you’re sorted. In my case it was $(“#main_content”).val(html_box.get_html()), and form.serialize() will happily submit the whole lot.
    4. Getting the text back. Not surprisingly, there’s a set_text() method, too, so that when you pull the text back from the database and want to put it into the htmlbox-ed textarea, all you need do is (in my case) - html_box.set_text(data.email_body).
    I like it. Yet to explore the full extent of HtmlBox, but it’ll easily do for this job.
     
    Post a comment or leave a trackback: Trackback URL.