akzhan/jwysiwyg — pull request #14 by stianlik (2013-01-16 15:26:57+00:00)
Title: Quirks / workarounds

Hi!

I really like your editor, it is a great alternative to heavy-weight editors like CKEditor. However, I have found a couple of issues that I would like to improve upon before using it in my projects.

I have done some refactoring, corrected some URLs, etc. Also implemented the possibility to add custom "quirks", more specifically quirk solutions. I found this convenient when debugging [Issue 345](https://github.com/jwysiwyg/jwysiwyg/issues/345). A workaround for this issue is included (tested in Firefox 18.0), also moved your solution to (Issue 251)[https://github.com/jwysiwyg/jwysiwyg/issues/251] into a quirk-file, in addition to the "keyup"-alternative posted.

My changes may be a bit invasive, but I think that a standard mechanism for fixing quirks will make it easier for other developers to contribute small bugfixes and workarounds. These can be included the same way as plugins. This way quirks can be easily interchanged, and removed for different scenarios (i.e. quirk for IE6 can be removed for sites that do not support IE6, etc.). If you determine a workaround to be applicable in all scenarios, you can easily move it into the main editor-file.

This need some documentation, I'm including a quick description at the bottom. You can find working examples in my commit.

# Quirks

Quirks objects should be used to fix issues with the editor, typically related to weird browser
behavior. Since this may introduce workarounds that don't always follow best practices,
and can be a bit messy, they should be easy to remove when better solutions are found, or they are deprecated.

All quirks objects are placed in the quirks-folder and have the following structure:

```javascript
(function($) {
$.wysiwyg.quirk.register({
/**
* @link https://github.com/jwysiwyg/jwysiwyg/issues/251
* @param {Wysiwyg} editor
*/
init: function(editor) {
// Fix some issue
},
});
})(jQuery);
```

The init function is run when an editor instance is initated, and will pass an instance
of Wysiwyg to the quirk object. This can be used to access all methods, events, and properties of the editor so that quirk objects can modify big parts of the functionality.

A quirk object is shared between all editor instances and therefore it should avoid state
state information for one specific instance as properties. Instead it can a context variable
that is passed to each method if necessary.