|
|
@@ -1,22 +1,4 @@
|
|
1
|
|
-/* global $, APP, AJS, interfaceConfig */
|
|
2
|
|
-
|
|
3
|
|
-import KeyboardShortcut from '../../keyboardshortcut/keyboardshortcut';
|
|
4
|
|
-
|
|
5
|
|
-/**
|
|
6
|
|
- * Associates tooltip element position (in the terms of
|
|
7
|
|
- * {@link UIUtil#setTooltip} which do not look like CSS <tt>position</tt>) with
|
|
8
|
|
- * AUI tooltip <tt>gravity</tt>.
|
|
9
|
|
- */
|
|
10
|
|
-const TOOLTIP_POSITIONS = {
|
|
11
|
|
- 'bottom': 'n',
|
|
12
|
|
- 'bottom-left': 'ne',
|
|
13
|
|
- 'bottom-right': 'nw',
|
|
14
|
|
- 'left': 'e',
|
|
15
|
|
- 'right': 'w',
|
|
16
|
|
- 'top': 's',
|
|
17
|
|
- 'top-left': 'se',
|
|
18
|
|
- 'top-right': 'sw'
|
|
19
|
|
-};
|
|
|
1
|
+/* global $, interfaceConfig */
|
|
20
|
2
|
|
|
21
|
3
|
/**
|
|
22
|
4
|
* Associates the default display type with corresponding CSS class
|
|
|
@@ -126,92 +108,6 @@ const IndicatorFontSizes = {
|
|
126
|
108
|
context.putImageData(imgData, 0, 0);
|
|
127
|
109
|
},
|
|
128
|
110
|
|
|
129
|
|
- /**
|
|
130
|
|
- * Sets a global handler for all tooltips. Once invoked, create a new
|
|
131
|
|
- * tooltip by merely updating a DOM node with the appropriate class (e.g.
|
|
132
|
|
- * <tt>tooltip-n</tt>) and the attribute <tt>content</tt>.
|
|
133
|
|
- */
|
|
134
|
|
- activateTooltips() {
|
|
135
|
|
- AJS.$('[data-tooltip]').tooltip({
|
|
136
|
|
- gravity() {
|
|
137
|
|
- return this.getAttribute('data-tooltip');
|
|
138
|
|
- },
|
|
139
|
|
-
|
|
140
|
|
- title() {
|
|
141
|
|
- return this.getAttribute('content');
|
|
142
|
|
- },
|
|
143
|
|
-
|
|
144
|
|
- html: true, // Handle multiline tooltips.
|
|
145
|
|
-
|
|
146
|
|
- // The following two prevent tooltips from being stuck:
|
|
147
|
|
- hoverable: false, // Make custom tooltips behave like native ones.
|
|
148
|
|
- live: true // Attach listener to document element.
|
|
149
|
|
- });
|
|
150
|
|
- },
|
|
151
|
|
-
|
|
152
|
|
- /**
|
|
153
|
|
- * Sets the tooltip to the given element.
|
|
154
|
|
- *
|
|
155
|
|
- * @param element the element to set the tooltip to
|
|
156
|
|
- * @param key the tooltip data-i18n key
|
|
157
|
|
- * @param position the position of the tooltip in relation to the element
|
|
158
|
|
- */
|
|
159
|
|
- setTooltip(element, key, position) {
|
|
160
|
|
- if (element) {
|
|
161
|
|
- const selector = element.jquery ? element : $(element);
|
|
162
|
|
-
|
|
163
|
|
- selector.attr('data-tooltip', TOOLTIP_POSITIONS[position]);
|
|
164
|
|
- selector.attr('data-i18n', `[content]${key}`);
|
|
165
|
|
-
|
|
166
|
|
- APP.translation.translateElement(selector);
|
|
167
|
|
- }
|
|
168
|
|
- },
|
|
169
|
|
-
|
|
170
|
|
- /**
|
|
171
|
|
- * Sets the tooltip to the given element, but instead of using translation
|
|
172
|
|
- * key uses text value.
|
|
173
|
|
- *
|
|
174
|
|
- * @param element the element to set the tooltip to
|
|
175
|
|
- * @param text the tooltip text
|
|
176
|
|
- * @param position the position of the tooltip in relation to the element
|
|
177
|
|
- */
|
|
178
|
|
- setTooltipText(element, text, position) {
|
|
179
|
|
- if (element) {
|
|
180
|
|
- UIUtil.removeTooltip(element);
|
|
181
|
|
-
|
|
182
|
|
- element.setAttribute('data-tooltip', TOOLTIP_POSITIONS[position]);
|
|
183
|
|
- element.setAttribute('content', text);
|
|
184
|
|
- }
|
|
185
|
|
- },
|
|
186
|
|
-
|
|
187
|
|
- /**
|
|
188
|
|
- * Removes the tooltip to the given element.
|
|
189
|
|
- *
|
|
190
|
|
- * @param element the element to remove the tooltip from
|
|
191
|
|
- */
|
|
192
|
|
- removeTooltip(element) {
|
|
193
|
|
- element.removeAttribute('data-tooltip', '');
|
|
194
|
|
- element.removeAttribute('data-i18n','');
|
|
195
|
|
- element.removeAttribute('content','');
|
|
196
|
|
- },
|
|
197
|
|
-
|
|
198
|
|
- /**
|
|
199
|
|
- * Internal util function for generating tooltip title.
|
|
200
|
|
- *
|
|
201
|
|
- * @param element
|
|
202
|
|
- * @returns {string|*}
|
|
203
|
|
- * @private
|
|
204
|
|
- */
|
|
205
|
|
- _getTooltipText(element) {
|
|
206
|
|
- let title = element.getAttribute('content');
|
|
207
|
|
- let shortcut = element.getAttribute('shortcut');
|
|
208
|
|
- if(shortcut) {
|
|
209
|
|
- let shortcutString = KeyboardShortcut.getShortcutTooltip(shortcut);
|
|
210
|
|
- title += ` ${shortcutString}`;
|
|
211
|
|
- }
|
|
212
|
|
- return title;
|
|
213
|
|
- },
|
|
214
|
|
-
|
|
215
|
111
|
/**
|
|
216
|
112
|
* Inserts given child element as the first one into the container.
|
|
217
|
113
|
* @param container the container to which new child element will be added
|