-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvorple-tooltips.h
141 lines (110 loc) · 5.82 KB
/
vorple-tooltips.h
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#Ifndef VORPLE_TOOLTIPS;
System_file;
Constant VORPLE_TOOLTIPS;
Include "vorple.h";
! this is a horribly hacky way to implement the rules in the rulebook
Object tooltiprule1 "initialize tooltip timers rule" VorpleInterfaceSetup
with description [; VorpleExecuteJavaScriptCommand("window._v_tooltip_timer=null"); ];
Object tooltiprule2 "initalize prompt tooltip rule" VorpleInterfaceSetup
with description [; VorpleExecuteJavaScriptCommand("$(haven.prompt.get()).find('#lineinput-prefix').powerTip({manual:true,placement:'sw-alt',smartPlacement:true})"); ];
!============================================
! Tooltips that can be activated on request or when the mouse cursor is moved over an element.
! by default, tooltips last for 7 seconds
Global TOOLTIP_DURATION = 7;
!======================================
! Tooltips on mouseover
[ VorpleTooltipMouse text tip id;
! generate a unique identifier
id = UniqueIdentifier();
! place the text
VorplePlaceInlineElement(id, text);
! place the tooltip
VorpleExecuteJavaScriptCommand(BuildCommand("$('.", id, "').last().attr('title','", VorpleEscape(tip), "').powerTip({smartPlacement:true})"));
];
[ VorpleTooltipMouseWithTextName text classes tip id ;
! generate a unique identifier
id = UniqueIdentifier();
! place the text
VorplePlaceInlineElement(id, text);
! place the tooltip
VorpleExecuteJavaScriptCommand(BuildCommand("$('.", id, "').last().addClass('", classes, "').attr('title','", VorpleEscape(tip), "').powerTip({smartPlacement:true})"));
];
[ VorpleTooltipAllElementsMouse tip classes;
VorpleExecuteJavaScriptCommand(BuildCommand("$('.", classes, "').last().attr('title','", VorpleEscape(tip),"').powerTip({smartPlacement:true})"));
];
[ VorpleTooltipElementMouse tip classes;
VorpleTooltipAllElementsMouse(tip, BuildCommand(classes, ":last"));
];
!=======================================
! Tooltips triggered manually
[ VorpleTooltipElementDuration tip classes delay duration delay_milli duration_milli ;
if (duration == 0) { duration = TOOLTIP_DURATION;}
delay_milli = delay*1000;
duration_milli = duration*1000;
if (duration > 0) {
! because there are two IntToString working on the same array, we have to do it by hand
!@output_stream 3 hugehugestr;
bp_output_stream(3, hugehugestr, LEN_HUGEHUGESTR);
print "clearTimeout(_v_tooltip_timer);_v_tooltip_timer=setTimeout(function() {const $t=$('.";
PrintStringOrArray(classes);
print "').last();if($t.length===0) return;$.powerTip.hide();$t.attr('title','";
PrintStringOrArray(VorpleEscape(tip));
print "').powerTip({manual:true,smartPlacement:true});$.powerTip.show($t);_v_tooltip_timer=setTimeout(function() {$.powerTip.hide($t,true);$t.removeAttr('title')},";
PrintStringOrArray(IntToString(duration_milli));
print ");},";
PrintStringOrArray(IntToString(delay_milli));
print ")";
!@output_stream -3;
bp_output_stream(-3);
VorpleExecuteJavaScriptCommand(hugehugestr);
} else {
VorpleExecuteJavaScriptCommand(BuildCommand("clearTimeout(_v_tooltip_timer);_v_tooltip_timer=setTimeout(function() {var $t=$('.", classes,"').last();$.powerTip.hide();$t.attr('title','", VorpleEscape(tip), "').powerTip({manual:true,smartPlacement:true});$.powerTip.show($t)},", IntToString(delay_milli), ")"));
}
];
[ VorpleTooltipElementIndefinitely tip classes delay ;
VorpleTooltipElementDuration(tip, classes, delay, -1);
];
[ VorpleTooltipElement tip classes delay ;
VorpleTooltipElementDuration(tip, classes, delay, 7);
];
!=======================================
! Tooltips on the prompt
[ VorpleTooltipPromptDuration tip delay duration delay_milli duration_milli ;
if (duration == 0) { duration = TOOLTIP_DURATION; }
delay_milli = delay*1000;
duration_milli = duration*1000;
if (duration >= 0) {
! because there are two IntToString working on the same array, we have to do it by hand
!@output_stream 3 hugehugestr;
bp_output_stream(3, hugehugestr, LEN_HUGEHUGESTR);
print "clearTimeout(_v_tooltip_timer);_v_tooltip_timer=setTimeout(function() {const $t=$('#lineinput-prefix');if($t.length===0) return;$.powerTip.hide();$t.data('powertip','";
PrintStringOrArray(VorpleEscape(tip));
print "');$.powerTip.show($t); _v_tooltip_timer=setTimeout(function() {$.powerTip.hide($t,true);$t.removeAttr('title')},";
PrintStringOrArray(IntToString(duration_milli));
print ");},";
PrintStringOrArray(IntToString(delay_milli));
print ")";
!@output_stream -3;
bp_output_stream(-3);
VorpleExecuteJavaScriptCommand(hugehugestr);
} else {
VorpleExecuteJavaScriptCommand(BuildCommand("clearTimeout(_v_tooltip_timer);_v_tooltip_timer=setTimeout(function() {var $t=$('#lineinput-prefix');$.powerTip.hide();$t.data('powertip','", VorpleEscape(tip), "');$.powerTip.show($t)},", IntToString(delay_milli), ")"));
}
];
[ VorpleTooltipPrompt tip delay ;
VorpleTooltipPromptDuration(tip, delay, 7);
];
[ VorpleTooltipPromptIndefinitely tip delay ;
VorpleTooltipPromptDuration(tip, delay, -1);
];
!=======================================
! Hiding tooltips
[ VorpleTooltipHide delay delay_milli; ! TODO: better name ? what does it do? hide last? Hide all?
if (delay == 0) {
VorpleExecuteJavaScriptCommand("clearTimeout(_v_tooltip_timer);$.powerTip.hide()");
} else {
delay_milli = delay*1000;
VorpleExecuteJavaScriptCommand(BuildCommand("clearTimeout(_v_tooltip_timer);_v_tooltip_timer=setTimeout(function() {$.powerTip.hide()}, ", IntToString(delay_milli), ")"));
}
];
#Endif;