-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactivate.js
86 lines (69 loc) · 2.69 KB
/
activate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
(function(){
/////////////////////////////////////////////
// Mapping to page content and Help links
/////////////////////////////////////////////
var helpMapUrl = "data/help-map.json",
helpMap = [],
xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(){
if (xhr.readyState == 4) {
helpMap = JSON.parse(xhr.responseText);
activate();
}
}
xhr.open("GET", chrome.extension.getURL(helpMapUrl), true);
xhr.send();
/////////////////////////////////////////////
// Operational variables and container setup
/////////////////////////////////////////////
var page = $(".site");
container = $('<div id="howto-container"></div>'),
highlight = $('<div class="gh-highlight"></div>');
answer = $('<div class="answer"></div>');
$("body").append(container);
container.append(answer);
container.append(highlight);
function activate(){
for(var i=0;i < helpMap.length; i++){
var helpIcon = $('<a class="question" data-selector="helpMap[i].selector" href="' + helpMap[i].helpLink + '"></a>"');
container.append(helpIcon);
var target = $(helpMap[i].selector),
offset = target.offset(),
helpLink = helpMap[i].helpLink + " .article-body p:first-child";
if (offset){
if (offset.top > 0 && offset.left > 0){
helpIcon.css("top", offset.top + "px");
helpIcon.css("left", offset.left + "px");
}
if (offset.top < helpIcon.height()){
helpIcon.addClass("top");
}
helpIcon.mouseover({selector: helpMap[i].selector, link: helpLink, offsetLeft: offset.left, offsetTop: offset.top},
function(event){
highlight.width($(event.data.selector).width());
highlight.height($(event.data.selector).height());
highlight.css("top", event.data.offsetTop + "px");
highlight.css("left", event.data.offsetLeft + "px");
answer.css("top", event.data.offsetTop+$(event.data.selector).height() + ((offset.top < helpIcon.height()) ? helpIcon.height() : 0) + "px");
if( ((answer.width() + event.data.offsetLeft )) > page.width() ){
answer.css("left", (event.data.offsetLeft-answer.width()) + "px");
}
else{
answer.css("left", event.data.offsetLeft + "px");
}
highlight.toggle();
answer.show();
answer.load(event.data.link);
}
);
helpIcon.mouseout({selector: helpMap[i].selector},
function(event){
highlight.toggle();
answer.hide();
answer.html("");
}
);
}
}
}
})();