Thursday, 6 January 2011

execCommand browser compatibility - it's crap

Modern browsers allow you to apply commands to format HTML in a contenteditable element, or an iframe with designmode set on. This functionality enables javascript rich text editors like CKEditor, TinyMCE or Whizzywig
This is the execCommand interface, common to Internet Explorer , Firefox, Chrome, Safari or Opera. Except that it's not common because they all generate different HTML in response to these commands.

There's a test at http://www.quirksmode.org/dom/execCommand/  which I have found very useful for seeing how each browser mangles the HTML - even though it has bugs itself! See also the compatibility table, which would be more helpful if it told you what HTML was produced by each browser.

None of them are entirely without problems but I think there's a clear winner. 

For example, issuing a "bold" command on a text selection gives:
  • <b>   in Chrome 8 and Safari 4.1 (b is NOT a deprecated tag, contrary to what some say)
  • <STRONG>  in IE8 (yes, IE makes all tags UPPERCASE, so not XML compliant)
  • <strong>  in Opera 11 (preferred by some as more semantic)
  • <span style="font-weight: bold;">  in Firefox 3.6 (but you can styleWithCSS=false to get <b>)

Issuing an "indent" command on a paragraph gives:
  • <blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"> in Chrome 8 and Safari 4.1 (!!!)
  • <BLOCKQUOTE style="MARGIN-RIGHT: 0px" dir=ltr> in IE8 (doesn't even quote all the attributes!)
  • <blockquote>  in Opera 11
  • <p style="margin-left: 40px;"> in Firefox 3.6 
So Opera 11 looks like the winner on generating HTML to web standards. The others are all an unholy mess. Internet Explorer's output frequently will not validate. Chrome and Safari insert unnecessary classes and, together with Firefox, use inline styles which will trample all over your carefully crafted stylesheet rules.


Blogs and Pages

Wordpress is blogging software but you can add and edit static pages and use it as a CMS.
According to Blogger Buzz, you can add pages (up to 10?) in Blogger too, but I have not tried this yet.

In Whizzy, everything is a page. But if you could add a tag/label/category/list (pick a name) then you could organise pages in lists. So you can make a page list other pages in a tag/label/category/list: a simple list of links is a menu, a blog is the same list with the page content included, perhaps with just a summary and perhaps with a limited number.

Other features of blogs:

  • syndication via RSS or Atom - also generated from the tag/label/category/list
  • comments - any Whizzy page can have comments up to commentlimit, perhgaps using Disqus

Friday, 17 December 2010

Whizzywig 2011

I am working on new version of Whizzywig for (early) 2011. It will certainly be re-engineered but will probably not preserve all the interfaces of the current Whizzywig version(61). It will
  • use current techniques, best practice and technology
  • be smaller ,lighter
  • minimize the differences in output from different browsers
  • simplify the toolbar whilst at the same time adding more features
  • provide a simple means of extending to add your own controls, or even replace the entire toolbar with your own
The current version will remain available for those of you who have it nailed in to websites and applications.
Here's what I'm planning:
 
Note: the above buttons don't do anything! They just illustrate what the new toolbar may look like!
  1. Whizzywig will have it's own namespace. It won't have global variables that may clash with other javascript that may co-exist on the same page.
    That in turn means that if you have customised your Whizzywig and used the existing global variables (e.g. sels, cssFile) then you'll have change your code to use the new version.
  2. The editor will be a contenteditable div, not an iframe. The contenteditable attribute has been in Internet Explorer since Adam was a boy and is in the W3C HTML 5 spec. It is deployed in all modern Class A browsers but won't work in older versions like Firefox 2.
    Using contenteditable has 2 major advantages: it allows the code to be simpler and means that the editor will inherit all the CSS styles of the surrounding page. It will be much more likely that What You See IS What You Get. In most cases, you won't need the cssFile setting any more.
  3. The editor will have a very small and lightweight core: aiming for about half the size of the current Whizzywig version.  It won't rely on any other files, not even an image sprite for the toolbar. This will make it very fast and simple to deploy.
  4. The font controls won't be on the toolbar by default: in the most common use case of creating HTML fragments to embed in a website, the output will conform to the websites styles as per the CSS rules. Font controls (Font size, Font family, color)  will be available as an extension.
  5. There will be new controls to format Paragraphs (replacing the current [Choose style] pulldown) and Characters. The Character pulldown will introduce big, small, subscript, superscript, underline and remove format.
  6. There will be a new default control to embed HTML or text. This means you can add that YouTube video or widget code without having to resort to Source code view. You can take the Source button off the toolbar for most implementations which will be a lot safer. If you paste in text from Word, it will strip the HTML formatting but preserve the paragraphs. If you paste in a chunk of plain text, it will add paragraph tags appropriately.
  7. There will be context sensitive buttons for Left [⇐] and Right[⇒].
    - If you select an image and click [⇒] it will float the image to the right of the text.
    - If you are in a list or blockquote it will indent the current item.
    - If you are in a text block it will align it to the right.
  8. It will provide more control over the output, making it possible to exclude tags, or write your own output generator (e.g. for BBcode or Textile). The default output will be efficient, valid xhtml. "Efficient" means no nested span tags to provide multiple formatting like color, font and italic.
  9. Extensions will be available for Font selection, Color selection, Tables, Special Characters.
  10. The editor will keep the textarea in sync after each change - no need to call syncTextarea.
  11. Independently there will be a new File/Image Manager, with upload.
Help me by commenting below, or by clicking