Thu, 15 Jan 2015 15:59:08 +0100
Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 /*
6 Locate anchors for annotations and prepare to display the annotations.
8 For each annotation, if its URL matches this page,
9 - get the ancestor whose ID matches the ID in the anchor
10 - look for a <p> element whose content contains the anchor text
12 That's considered a match. Then we:
13 - highlight the anchor element
14 - add an 'annotated' class to tell the selector to skip this element
15 - embed the annottion text as a new attribute
17 For all annotated elements:
18 - bind 'mouseenter' and 'mouseleave' events to the element, to send 'show'
19 and 'hide' messages back to the add-on.
20 */
22 self.on('message', function onMessage(annotations) {
23 annotations.forEach(
24 function(annotation) {
25 if(annotation.url == document.location.toString()) {
26 createAnchor(annotation);
27 }
28 });
30 $('.annotated').css('border', 'solid 3px yellow');
32 $('.annotated').bind('mouseenter', function(event) {
33 self.port.emit('show', $(this).attr('annotation'));
34 event.stopPropagation();
35 event.preventDefault();
36 });
38 $('.annotated').bind('mouseleave', function() {
39 self.port.emit('hide');
40 });
41 });
44 function createAnchor(annotation) {
45 annotationAnchorAncestor = $('#' + annotation.ancestorId)[0] || document.body;
46 annotationAnchor = $(annotationAnchorAncestor).parent().find(
47 ':contains("' + annotation.anchorText + '")').last();
48 annotationAnchor.addClass('annotated');
49 annotationAnchor.attr('annotation', annotation.annotationText);
50 }