Kaynağa Gözat

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

master
hristoterezov 7 yıl önce
ebeveyn
işleme
91e75bf7b9

+ 2
- 1
modules/UI/UI.js Dosyayı Görüntüle

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

+ 2
- 1
modules/UI/recording/Recording.js Dosyayı Görüntüle

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

+ 86
- 0
modules/UI/util/Tooltip.js Dosyayı Görüntüle

@@ -0,0 +1,86 @@
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 Dosyayı Görüntüle

@@ -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

+ 2
- 2
react/features/filmstrip/components/web/BaseIndicator.js Dosyayı Görüntüle

@@ -1,6 +1,6 @@
1 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 6
  * React {@code Component} for showing an icon with a tooltip.
@@ -116,7 +116,7 @@ class BaseIndicator extends Component {
116 116
     _setTooltip() {
117 117
         // TODO Replace UIUtil with an AtlasKit component when a suitable one
118 118
         // becomes available for tooltips.
119
-        UIUtil.setTooltip(
119
+        setTooltip(
120 120
             this._rootElement,
121 121
             this.props.tooltipKey,
122 122
             'top'

+ 3
- 2
react/features/toolbox/actions.web.js Dosyayı Görüntüle

@@ -3,7 +3,8 @@
3 3
 import Recording from '../../../modules/UI/recording/Recording';
4 4
 import SideContainerToggler
5 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 8
 import UIEvents from '../../../service/UI/UIEvents';
8 9
 
9 10
 import {
@@ -226,7 +227,7 @@ export function setProfileButtonUnclickable(unclickable: boolean): Function {
226 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 Dosyayı Görüntüle

@@ -4,7 +4,10 @@ import React from 'react';
4 4
 
5 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 12
 import AbstractToolbarButton from './AbstractToolbarButton';
10 13
 import {
@@ -214,11 +217,11 @@ class ToolbarButton extends AbstractToolbarButton {
214 217
 
215 218
             if (!button.unclickable) {
216 219
                 if (button.tooltipText) {
217
-                    UIUtil.setTooltipText(this.button,
220
+                    setTooltipText(this.button,
218 221
                         button.tooltipText,
219 222
                         tooltipPosition);
220 223
                 } else {
221
-                    UIUtil.setTooltip(this.button,
224
+                    setTooltip(this.button,
222 225
                         button.tooltipKey,
223 226
                         tooltipPosition);
224 227
                 }

Loading…
İptal
Kaydet