forked from toolness/hackasaurus-parable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hints.js
105 lines (96 loc) · 2.64 KB
/
hints.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
var HintFilters = {
matches: function(selector) {
return function(ui, target) {
var query = $(selector);
return target && $(target).is(selector);
};
},
isOnCssProperty: function(name) {
return function(ui, target) {
var rowHover = $("div.webxray-row:hover");
if (rowHover.length) {
var row = rowHover[0];
var widget = ui.jQuery(row).data("propertyWidget");
if (widget.name == name && !widget.isBeingEdited())
return true;
}
return false;
};
},
isStyleOverlayLocked: function(isLocked) {
return function(ui, target) {
return (ui.styleInfoOverlay.isLocked() == isLocked);
};
},
isStyleOverlayVisible: function(isVisible) {
return function(ui, target) {
return (ui.styleInfoOverlay.isVisible() == isVisible);
};
},
notFixed: function(bug) {
return function() {
return !bug.isFixed(this.context);
};
}
};
var RemixDialogHintFilters = {
matches: function(selector) {
return function(ui, target) {
var parent = $(target).closest(".element");
if (parent) {
var linkedNode = parent.data("linked-node");
return $(linkedNode).is(selector);
}
return false;
};
},
isOnAttributeValue: function(attr) {
return function(ui, target) {
return ($(target).is(".attributes .value input") &&
$(target).parent().prev(".name").text() == attr);
};
},
isOnTextNode: function() {
return function(ui, target) {
return $(target).is(".element .text textarea");
};
},
notFixed: HintFilters.notFixed
};
function HintManager(ui, filters, context) {
var hints = [];
filters = filters || HintFilters;
var self = {
context: context,
plant: function(options) {
var content = $(options.content).clone();
var filterList = [];
for (var filterName in options.when) {
var arg = options.when[filterName];
var filter = filters[filterName];
if (!filter)
throw new Error("unknown 'when' option: " + filterName);
filterList.push(filter(arg));
}
$(document.body).append(content);
content.hide();
hints.push({
content: content,
filterList: filterList
});
},
refresh: function refresh(currentTarget) {
hints.forEach(function(hint) {
for (var i = 0; i < hint.filterList.length; i++) {
var filter = hint.filterList[i];
if (!filter.call(self, ui, currentTarget)) {
hint.content.hide();
return;
}
};
hint.content.fadeIn();
});
}
};
return self;
}