Browse Source

ref(UIUtil): Move all tooltip functions into another file

master
hristoterezov 7 years ago
parent
commit
91e75bf7b9

+ 2
- 1
modules/UI/UI.js View File

11
 import JitsiPopover from "./util/JitsiPopover";
11
 import JitsiPopover from "./util/JitsiPopover";
12
 import messageHandler from "./util/MessageHandler";
12
 import messageHandler from "./util/MessageHandler";
13
 import UIUtil from "./util/UIUtil";
13
 import UIUtil from "./util/UIUtil";
14
+import { activateTooltips } from './util/Tooltip';
14
 import UIEvents from "../../service/UI/UIEvents";
15
 import UIEvents from "../../service/UI/UIEvents";
15
 import EtherpadManager from './etherpad/Etherpad';
16
 import EtherpadManager from './etherpad/Etherpad';
16
 import SharedVideoManager from './shared_video/SharedVideo';
17
 import SharedVideoManager from './shared_video/SharedVideo';
232
     // (2) APP.conference as means of communication between the participants.
233
     // (2) APP.conference as means of communication between the participants.
233
     followMeHandler = new FollowMe(APP.conference, UI);
234
     followMeHandler = new FollowMe(APP.conference, UI);
234
 
235
 
235
-    UIUtil.activateTooltips();
236
+    activateTooltips();
236
 };
237
 };
237
 
238
 
238
 UI.mucJoined = function () {
239
 UI.mucJoined = function () {

+ 2
- 1
modules/UI/recording/Recording.js View File

18
 
18
 
19
 import UIEvents from "../../../service/UI/UIEvents";
19
 import UIEvents from "../../../service/UI/UIEvents";
20
 import UIUtil from '../util/UIUtil';
20
 import UIUtil from '../util/UIUtil';
21
+import { setTooltip } from '../util/Tooltip';
21
 import VideoLayout from '../videolayout/VideoLayout';
22
 import VideoLayout from '../videolayout/VideoLayout';
22
 
23
 
23
 import { setToolboxEnabled } from '../../../react/features/toolbox';
24
 import { setToolboxEnabled } from '../../../react/features/toolbox';
323
     initRecordingButton() {
324
     initRecordingButton() {
324
         const selector = $('#toolbar_button_record');
325
         const selector = $('#toolbar_button_record');
325
 
326
 
326
-        UIUtil.setTooltip(selector, 'liveStreaming.buttonTooltip', 'right');
327
+        setTooltip(selector, 'liveStreaming.buttonTooltip', 'right');
327
 
328
 
328
         selector.addClass(this.baseClass);
329
         selector.addClass(this.baseClass);
329
         selector.attr("data-i18n", "[content]" + this.recordingButtonTooltip);
330
         selector.attr("data-i18n", "[content]" + this.recordingButtonTooltip);

+ 86
- 0
modules/UI/util/Tooltip.js View File

1
+/* global $, APP, AJS */
2
+
3
+/**
4
+ * Associates tooltip element position (in the terms of
5
+ * {@link UIUtil#setTooltip} which do not look like CSS <tt>position</tt>) with
6
+ * AUI tooltip <tt>gravity</tt>.
7
+ */
8
+const TOOLTIP_POSITIONS = {
9
+    'bottom': 'n',
10
+    'bottom-left': 'ne',
11
+    'bottom-right': 'nw',
12
+    'left': 'e',
13
+    'right': 'w',
14
+    'top': 's',
15
+    'top-left': 'se',
16
+    'top-right': 'sw'
17
+};
18
+
19
+/**
20
+ * Sets a global handler for all tooltips. Once invoked, create a new
21
+ * tooltip by merely updating a DOM node with the appropriate class (e.g.
22
+ * <tt>tooltip-n</tt>) and the attribute <tt>content</tt>.
23
+ */
24
+export function activateTooltips() {
25
+    AJS.$('[data-tooltip]').tooltip({
26
+        gravity() {
27
+            return this.getAttribute('data-tooltip');
28
+        },
29
+
30
+        title() {
31
+            return this.getAttribute('content');
32
+        },
33
+
34
+        html: true, // Handle multiline tooltips.
35
+
36
+        // The following two prevent tooltips from being stuck:
37
+        hoverable: false, // Make custom tooltips behave like native ones.
38
+        live: true // Attach listener to document element.
39
+    });
40
+}
41
+
42
+/**
43
+ * Sets the tooltip to the given element.
44
+ *
45
+ * @param element the element to set the tooltip to
46
+ * @param key the tooltip data-i18n key
47
+ * @param position the position of the tooltip in relation to the element
48
+ */
49
+export function setTooltip(element, key, position) {
50
+    if (element) {
51
+        const selector = element.jquery ? element : $(element);
52
+
53
+        selector.attr('data-tooltip', TOOLTIP_POSITIONS[position]);
54
+        selector.attr('data-i18n', `[content]${key}`);
55
+
56
+        APP.translation.translateElement(selector);
57
+    }
58
+}
59
+
60
+/**
61
+ * Sets the tooltip to the given element, but instead of using translation
62
+ * key uses text value.
63
+ *
64
+ * @param element the element to set the tooltip to
65
+ * @param text the tooltip text
66
+ * @param position the position of the tooltip in relation to the element
67
+ */
68
+export function setTooltipText(element, text, position) {
69
+    if (element) {
70
+        removeTooltip(element);
71
+
72
+        element.setAttribute('data-tooltip', TOOLTIP_POSITIONS[position]);
73
+        element.setAttribute('content', text);
74
+    }
75
+}
76
+
77
+/**
78
+ * Removes the tooltip to the given element.
79
+ *
80
+ * @param element the element to remove the tooltip from
81
+ */
82
+export function removeTooltip(element) {
83
+    element.removeAttribute('data-tooltip', '');
84
+    element.removeAttribute('data-i18n','');
85
+    element.removeAttribute('content','');
86
+}

+ 1
- 105
modules/UI/util/UIUtil.js View File

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
  * Associates the default display type with corresponding CSS class
4
  * Associates the default display type with corresponding CSS class
126
         context.putImageData(imgData, 0, 0);
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
      * Inserts given child element as the first one into the container.
112
      * Inserts given child element as the first one into the container.
217
      * @param container the container to which new child element will be added
113
      * @param container the container to which new child element will be added

+ 2
- 2
react/features/filmstrip/components/web/BaseIndicator.js View File

1
 import React, { Component } from 'react';
1
 import React, { Component } from 'react';
2
 
2
 
3
-import UIUtil from '../../../../../modules/UI/util/UIUtil';
3
+import { setTooltip } from '../../../../../modules/UI/util/Tooltip';
4
 
4
 
5
 /**
5
 /**
6
  * React {@code Component} for showing an icon with a tooltip.
6
  * React {@code Component} for showing an icon with a tooltip.
116
     _setTooltip() {
116
     _setTooltip() {
117
         // TODO Replace UIUtil with an AtlasKit component when a suitable one
117
         // TODO Replace UIUtil with an AtlasKit component when a suitable one
118
         // becomes available for tooltips.
118
         // becomes available for tooltips.
119
-        UIUtil.setTooltip(
119
+        setTooltip(
120
             this._rootElement,
120
             this._rootElement,
121
             this.props.tooltipKey,
121
             this.props.tooltipKey,
122
             'top'
122
             'top'

+ 3
- 2
react/features/toolbox/actions.web.js View File

3
 import Recording from '../../../modules/UI/recording/Recording';
3
 import Recording from '../../../modules/UI/recording/Recording';
4
 import SideContainerToggler
4
 import SideContainerToggler
5
     from '../../../modules/UI/side_pannels/SideContainerToggler';
5
     from '../../../modules/UI/side_pannels/SideContainerToggler';
6
-import UIUtil from '../../../modules/UI/util/UIUtil';
6
+
7
+import { removeTooltip } from '../../../modules/UI/util/Tooltip';
7
 import UIEvents from '../../../service/UI/UIEvents';
8
 import UIEvents from '../../../service/UI/UIEvents';
8
 
9
 
9
 import {
10
 import {
226
             unclickable
227
             unclickable
227
         }));
228
         }));
228
 
229
 
229
-        UIUtil.removeTooltip(document.getElementById('toolbar_button_profile'));
230
+        removeTooltip(document.getElementById('toolbar_button_profile'));
230
     };
231
     };
231
 }
232
 }
232
 
233
 

+ 6
- 3
react/features/toolbox/components/ToolbarButton.web.js View File

4
 
4
 
5
 import { translate } from '../../base/i18n';
5
 import { translate } from '../../base/i18n';
6
 
6
 
7
-import UIUtil from '../../../../modules/UI/util/UIUtil';
7
+import {
8
+    setTooltip,
9
+    setTooltipText
10
+} from '../../../../modules/UI/util/Tooltip';
8
 
11
 
9
 import AbstractToolbarButton from './AbstractToolbarButton';
12
 import AbstractToolbarButton from './AbstractToolbarButton';
10
 import {
13
 import {
214
 
217
 
215
             if (!button.unclickable) {
218
             if (!button.unclickable) {
216
                 if (button.tooltipText) {
219
                 if (button.tooltipText) {
217
-                    UIUtil.setTooltipText(this.button,
220
+                    setTooltipText(this.button,
218
                         button.tooltipText,
221
                         button.tooltipText,
219
                         tooltipPosition);
222
                         tooltipPosition);
220
                 } else {
223
                 } else {
221
-                    UIUtil.setTooltip(this.button,
224
+                    setTooltip(this.button,
222
                         button.tooltipKey,
225
                         button.tooltipKey,
223
                         tooltipPosition);
226
                         tooltipPosition);
224
                 }
227
                 }

Loading…
Cancel
Save