Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | /* |
michael@0 | 6 | Locate anchors for annotations and prepare to display the annotations. |
michael@0 | 7 | |
michael@0 | 8 | For each annotation, if its URL matches this page, |
michael@0 | 9 | - get the ancestor whose ID matches the ID in the anchor |
michael@0 | 10 | - look for a <p> element whose content contains the anchor text |
michael@0 | 11 | |
michael@0 | 12 | That's considered a match. Then we: |
michael@0 | 13 | - highlight the anchor element |
michael@0 | 14 | - add an 'annotated' class to tell the selector to skip this element |
michael@0 | 15 | - embed the annottion text as a new attribute |
michael@0 | 16 | |
michael@0 | 17 | For all annotated elements: |
michael@0 | 18 | - bind 'mouseenter' and 'mouseleave' events to the element, to send 'show' |
michael@0 | 19 | and 'hide' messages back to the add-on. |
michael@0 | 20 | */ |
michael@0 | 21 | |
michael@0 | 22 | self.on('message', function onMessage(annotations) { |
michael@0 | 23 | annotations.forEach( |
michael@0 | 24 | function(annotation) { |
michael@0 | 25 | if(annotation.url == document.location.toString()) { |
michael@0 | 26 | createAnchor(annotation); |
michael@0 | 27 | } |
michael@0 | 28 | }); |
michael@0 | 29 | |
michael@0 | 30 | $('.annotated').css('border', 'solid 3px yellow'); |
michael@0 | 31 | |
michael@0 | 32 | $('.annotated').bind('mouseenter', function(event) { |
michael@0 | 33 | self.port.emit('show', $(this).attr('annotation')); |
michael@0 | 34 | event.stopPropagation(); |
michael@0 | 35 | event.preventDefault(); |
michael@0 | 36 | }); |
michael@0 | 37 | |
michael@0 | 38 | $('.annotated').bind('mouseleave', function() { |
michael@0 | 39 | self.port.emit('hide'); |
michael@0 | 40 | }); |
michael@0 | 41 | }); |
michael@0 | 42 | |
michael@0 | 43 | |
michael@0 | 44 | function createAnchor(annotation) { |
michael@0 | 45 | annotationAnchorAncestor = $('#' + annotation.ancestorId)[0] || document.body; |
michael@0 | 46 | annotationAnchor = $(annotationAnchorAncestor).parent().find( |
michael@0 | 47 | ':contains("' + annotation.anchorText + '")').last(); |
michael@0 | 48 | annotationAnchor.addClass('annotated'); |
michael@0 | 49 | annotationAnchor.attr('annotation', annotation.annotationText); |
michael@0 | 50 | } |