[annotator-dev] changing the annotator-hl class or id

Nick Stenning nick at whiteink.com
Fri Sep 2 10:19:39 UTC 2011


Ewald,

It's since occurred to me that there's no need to modify annotator.coffee to implement this functionality. It would be far better to integrate the code into the Categories plugin, harnessing the `annotationCreated` event to add classes (dependent on categories) to the entries of the `highlights` property for each annotation.

Best,
Nick

On 1 Sep 2011, at 15:22, Nick Stenning wrote:

> Hi Ewald,
> 
> On Thu, Sep 1, 2011 at 14:37, Ewald Zietsman <ewald at siyavula.com> wrote:
>> 
>> Hi,
>> I am trying to assign different colours for different 'categories' of annotations but the mechanics behind the highlighting is a bit over my head.
> 
> No problem. The slicing and dicing of the DOM that annotator does is
> pretty complicated, so don't worry about it!
> 
>> in annotator.coffee I have changed the following code to check whether an annotation has a category attribute and to assign the highlighting accordingly.
>> [...snip...]
> 
> The code you've provided is a bit confused, as you've guessed. The
> `annotation.highlights` array actually contains a list of DOM nodes,
> so I think the easiest way to do what you want is add something like
> the following after line 242 of annotator.coffee:
> 
>      annotation.ranges.push normed.serialize(@wrapper[0], '.annotator-hl')
>      hlElems = this.highlightRange(normed)
>      if annotation.category?
>        $(hlElems).addClass(".annotator-hl-#{annotation.category}")
>      $.merge annotation.highlights, hlElems
> 
> Let me know how you get on with that!
> 
> Best,
> Nick





More information about the annotator-dev mailing list