forked from toolness/hackasaurus-parable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main-page.js
125 lines (107 loc) · 2.96 KB
/
main-page.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
function updateBugsLeftText(n) {
var help = $(".help");
help.find(".remaining").text(n);
help.find(".singular").hide();
help.find(".plural").hide();
help.find(".not-done").hide();
help.find(".done").hide();
if (n == 0) {
help.find(".done").show();
} else {
help.find(".not-done").show();
if (n == 1) {
help.find(".singular").show();
} else {
help.find(".plural").show();
}
}
}
function absoluteURL(url) {
var a = $('<a></a>').attr('href', url);
return a[0].href;
}
function installHints(ui, hints) {
var currentTarget = null;
function genericChange() {
currentTarget = ui.focusedOverlay.getPrimaryElement();
hints.refresh(currentTarget);
}
ui.focusedOverlay.on('change', genericChange);
ui.styleInfoOverlay.on('show', genericChange);
ui.styleInfoOverlay.on('hide', genericChange);
ui.styleInfoOverlay.on('lock', function(info) {
currentTarget = info.element;
hints.refresh(currentTarget);
});
function domEventChange() {
hints.refresh(currentTarget);
}
$(".webxray-row").live({
mouseover: domEventChange,
mouseout: domEventChange
});
}
function BugDisplay(bugs) {
var fixedBefore = {};
var self = {
update: function update() {
var bugsLeft = 0;
for (var name in bugs) {
var bug = bugs[name];
if (!bug.isFixed())
bugsLeft++;
else {
if (!(name in fixedBefore)) {
fixedBefore[name] = true;
if (bug.achievement)
$(bug.achievement).delay(500).slideDown().delay(2500).slideUp();
if (bug.onAchieved)
bug.onAchieved();
}
}
}
updateBugsLeftText(bugsLeft);
}
};
self.update();
return self;
}
jQuery.fn.extend({
propArray: function(prop) {
return $.makeArray(this.map(function() {
return this[prop];
}));
}
});
function buildPageMods(extraMods) {
var mods = {
stylesheets: $("link.include-in-remix-dialog").propArray('href'),
scripts: $("script.include-in-remix-dialog").propArray('src')
};
['stylesheets', 'scripts'].forEach(function(modType) {
var absURLs = extraMods[modType].map(absoluteURL);
mods[modType] = mods[modType].concat(absURLs);
});
mods.scripts.push(absoluteURL('remix-dialog-pagemod.js'));
return mods;
}
function init() {
var bugDisplay = BugDisplay(bugs);
if (navigator.platform.match(/^Mac/))
$(".non-mac").hide();
else
$(".mac").hide();
$("#bookmarklet").click(function() {
$(this).addClass("loading");
});
window.webxrayWhenGogglesLoad = function(ui) {
var hints = HintManager(ui);
$("#bookmarklet").removeClass("loading");
bugHints.forEach(hints.plant);
installHints(ui, hints);
ui.commandManager.on('state-change', bugDisplay.update);
ui.mixMaster.setDialogPageMods(buildPageMods(remixDialogPageMods));
ui.styleInfoOverlay.setPropertyNames(stylePropertiesToShow);
ui.focusedOverlay.set($("#bookmarklet")[0]);
};
}