diff -r 000000000000 -r 6474c204b198 addon-sdk/source/examples/annotator/data/selector.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/addon-sdk/source/examples/annotator/data/selector.js Wed Dec 31 06:09:35 2014 +0100 @@ -0,0 +1,73 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* +The selector locates elements that are suitable for annotation and enables +the user to select them. + +On 'mouseenter' events associated with
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(); + } +}); + +function getInnerText(element) { + // jQuery.text() returns content of