openannotation/annotator — pull request #369 by csillag (2014-04-23 00:25:26+00:00)
Title: Separating the text selection functionality and the adder button (on extract-ui)

This PR is against the extract-ui branch.

Basically, I have done here what I have described [here](https://github.com/openannotation/annotator/pull/367#issuecomment-41106271).

In order to do this,
* first I had to generalize the format of the data stored about the selection (without actually changing anything in core or the other plugins), see https://github.com/hypothesis/annotator/commit/90a8a4f1d9a33390f331e2ca60365281780b7509
* then I did the actual separation of the plugins in https://github.com/hypothesis/annotator/commit/eaeb9518bbe0f628651fd536a44055f673bdc2d8

Copying the commit messages:

**Generalizing adder button: data format**

When we detect a selection, we store some data, which is later
used when the adder button is clicked.

Before this change, we stored the list of ranges, and then when the
adder button was clicked, we created an annotation out of it.

To make this more generic, I moved the code responsible for creating
the annotation from the list of ranges from the adder button click
to the earlier phase (after detecting a selection).

So now the skeleton for the annotation is created right away, when
a selection is detected, and when the adder button is clicked,
we simply use this skeleton to create the real animation.

(This way, we can decouple the analysis of the selection from the adder
button.)

**Separating text selection and the adder button**

This change cuts the Adder plugin in half:
* The core adder button functionality remain in the Adder plugin.
* Support for annotating text selections goes into the TextSelector plugin.

The goal is to make it possible to use the adder button with different
kinds of selections, too.

Some communication is necessary between the two plugins. I used
API extension of the core Annotator instance.

* `annotator.ignoreMouseup` is set by the Adder plugin, and is read by
the TextSelector plugin, in order not to trigger false selections
by clicking on the adder button itself.
* `annotator.selectedSkeleton` is used by the TextSelector plugin
(and later, by other selector plugins) for storing the annotation
skeleton prepared based on the selection. The adder button takes the
skeleton for here, and uses it to create the actual annotation.
* `annotator.onSuccessfulSelection()` and `annotator.onFailedSelection()`
methods are triggered by successful and failed selection events detected
by the TextSelector plugin. The Adder plugin reacts by showing and hiding
the adder button, respectively.

Other than these integration points, the two plugins are independent
of each other.