diff options
author | Rogan Creswick <creswick@galois.com> | 2012-03-30 17:07:02 -0700 |
---|---|---|
committer | Rogan Creswick <creswick@galois.com> | 2012-03-30 17:07:02 -0700 |
commit | f6ab6622aab00fe7c2f4c3dc41f786ebbe0f0d73 (patch) | |
tree | 870111038542cd27153e1396ebdc063573249689 /tools/addon-sdk-1.4/examples/annotator/data/selector.js |
initial revision
Diffstat (limited to 'tools/addon-sdk-1.4/examples/annotator/data/selector.js')
-rw-r--r-- | tools/addon-sdk-1.4/examples/annotator/data/selector.js | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/tools/addon-sdk-1.4/examples/annotator/data/selector.js b/tools/addon-sdk-1.4/examples/annotator/data/selector.js new file mode 100644 index 0000000..4c42bb1 --- /dev/null +++ b/tools/addon-sdk-1.4/examples/annotator/data/selector.js @@ -0,0 +1,56 @@ +/* +The selector locates elements that are suitable for annotation and enables +the user to select them. + +On 'mouseenter' events associated with <p> elements: +- if the selector is active and the element is not already annotated +- find the nearest ancestor which has an id attribute: this is supposed to +make identification of this element more accurate +- highlight the element +- bind 'click' for the element to send a message back to the add-on, including +all the information associated with the anchor. +*/ + +var matchedElement = null; +var originalBgColor = null; +var active = false; + +function resetMatchedElement() { + if (matchedElement) { + $(matchedElement).css('background-color', originalBgColor); + $(matchedElement).unbind('click.annotator'); + } +} + +self.on('message', function onMessage(activation) { + active = activation; + if (!active) { + resetMatchedElement(); + } +}); + +$('*').mouseenter(function() { + if (!active || $(this).hasClass('annotated')) { + return; + } + resetMatchedElement(); + ancestor = $(this).closest("[id]"); + matchedElement = $(this).first(); + originalBgColor = $(matchedElement).css('background-color'); + $(matchedElement).css('background-color', 'yellow'); + $(matchedElement).bind('click.annotator', function(event) { + event.stopPropagation(); + event.preventDefault(); + self.port.emit('show', + [ + document.location.toString(), + $(ancestor).attr("id"), + $(matchedElement).text() + ] + ); + }); +}); + +$('*').mouseout(function() { + resetMatchedElement(); +}); |