Bladeren bron

refactor(UIUtils): merges show and hide functions and cleans visibility setting

j8
yanas 8 jaren geleden
bovenliggende
commit
0f2ba1cefe

+ 2
- 2
modules/UI/UI.js Bestand weergeven

@@ -443,10 +443,10 @@ UI.start = function () {
443 443
         // Display notice message at the top of the toolbar
444 444
         if (config.noticeMessage) {
445 445
             $('#noticeText').text(config.noticeMessage);
446
-            UIUtil.showElement('notice');
446
+            UIUtil.setVisible('notice', true);
447 447
         }
448 448
     } else {
449
-        UIUtil.hideElement('mainToolbarContainer');
449
+        UIUtil.setVisible('mainToolbarContainer', false);
450 450
         FilmStrip.setupFilmStripOnly();
451 451
         messageHandler.enableNotifications(false);
452 452
         JitsiPopover.enabled = false;

+ 2
- 2
modules/UI/recording/Recording.js Bestand weergeven

@@ -392,7 +392,7 @@ var Recording = {
392 392
         let shouldShow = show && _isRecordingButtonEnabled();
393 393
         let id = 'toolbar_button_record';
394 394
 
395
-        UIUtil.showOrHideElement(id, shouldShow);
395
+        UIUtil.setVisible(id, shouldShow);
396 396
     },
397 397
 
398 398
     /**
@@ -476,7 +476,7 @@ var Recording = {
476 476
 
477 477
         // Recording spinner
478 478
         let spinnerId = 'recordingSpinner';
479
-        UIUtil.showOrHideElement(
479
+        UIUtil.setVisible(
480 480
             spinnerId, recordingState === Status.RETRYING);
481 481
     },
482 482
     // checks whether recording is enabled and whether we have params

+ 1
- 5
modules/UI/side_pannels/chat/Chat.js Bestand weergeven

@@ -306,18 +306,14 @@ var Chat = {
306 306
      * @param subject the subject
307 307
      */
308 308
     setSubject (subject) {
309
-        let toggleFunction;
310 309
         if (subject) {
311 310
             subject = subject.trim();
312 311
         }
313 312
 
314
-        toggleFunction = subject ? UIUtil.showElement : UIUtil.hideElement;
315
-        toggleFunction = toggleFunction.bind(UIUtil);
316
-
317 313
         let subjectId = 'subject';
318 314
         let html = linkify(UIUtil.escapeHtml(subject));
319 315
         $(`#${subjectId}`).html(html);
320
-        toggleFunction(subjectId);
316
+        UIUtil.setVisible(subjectId, subject && subject.length > 0);
321 317
     },
322 318
 
323 319
     /**

+ 4
- 4
modules/UI/side_pannels/profile/Profile.js Bestand weergeven

@@ -128,7 +128,7 @@ export default {
128 128
      */
129 129
     showAuthenticationButtons (show) {
130 130
         let id = 'profile_auth_container';
131
-        UIUtil.showOrHideElement(id, show);
131
+        UIUtil.setVisible(id, show);
132 132
     },
133 133
 
134 134
     /**
@@ -138,7 +138,7 @@ export default {
138 138
     showLoginButton (show) {
139 139
         let id = 'profile_button_login';
140 140
 
141
-        UIUtil.showOrHideElement(id, show);
141
+        UIUtil.setVisible(id, show);
142 142
     },
143 143
 
144 144
     /**
@@ -148,7 +148,7 @@ export default {
148 148
     showLogoutButton (show) {
149 149
         let id = 'profile_button_logout';
150 150
 
151
-        UIUtil.showOrHideElement(id, show);
151
+        UIUtil.setVisible(id, show);
152 152
     },
153 153
 
154 154
     /**
@@ -158,7 +158,7 @@ export default {
158 158
     setAuthenticatedIdentity (authIdentity) {
159 159
         let id = 'profile_auth_identity';
160 160
 
161
-        UIUtil.showOrHideElement(id, !!authIdentity);
161
+        UIUtil.setVisible(id, !!authIdentity);
162 162
 
163 163
         $(`#${id}`).text(authIdentity ? authIdentity : '');
164 164
     }

+ 9
- 9
modules/UI/side_pannels/settings/SettingsMenu.js Bestand weergeven

@@ -166,7 +166,7 @@ export default {
166 166
             APP.translation.addLanguageChangedListener(
167 167
                 lng => selectInput[0].dataset.i18n = `languages:${lng}`);
168 168
 
169
-            UIUtil.showElement(wrapperId);
169
+            UIUtil.setVisible(wrapperId, true);
170 170
         }
171 171
         // DEVICES LIST
172 172
         if (UIUtil.isSettingEnabled('devices')) {
@@ -181,9 +181,9 @@ export default {
181 181
                 });
182 182
             // Only show the subtitle if this isn't the only setting section.
183 183
             if (interfaceConfig.SETTINGS_SECTIONS.length > 1)
184
-                UIUtil.showElement("deviceOptionsTitle");
184
+                UIUtil.setVisible("deviceOptionsTitle", true);
185 185
 
186
-            UIUtil.showElement(wrapperId);
186
+            UIUtil.setVisible(wrapperId, true);
187 187
         }
188 188
         // MODERATOR
189 189
         if (UIUtil.isSettingEnabled('moderator')) {
@@ -208,7 +208,7 @@ export default {
208 208
                 emitter.emit(UIEvents.FOLLOW_ME_ENABLED, isFollowMeEnabled);
209 209
             });
210 210
 
211
-            UIUtil.showElement(wrapperId);
211
+            UIUtil.setVisible(wrapperId, true);
212 212
         }
213 213
     },
214 214
 
@@ -245,15 +245,15 @@ export default {
245 245
             // Only show the subtitle if this isn't the only setting section.
246 246
             if (!$("#moderatorOptionsTitle").is(":visible")
247 247
                     && interfaceConfig.SETTINGS_SECTIONS.length > 1)
248
-                UIUtil.showElement("moderatorOptionsTitle");
248
+                UIUtil.setVisible("moderatorOptionsTitle", true);
249 249
 
250
-            UIUtil.showElement("startMutedOptions");
250
+            UIUtil.setVisible("startMutedOptions", true);
251 251
         } else {
252 252
             // Only show the subtitle if this isn't the only setting section.
253 253
             if ($("#moderatorOptionsTitle").is(":visible"))
254
-                UIUtil.hideElement("moderatorOptionsTitle");
254
+                UIUtil.setVisible("moderatorOptionsTitle", false);
255 255
 
256
-            UIUtil.hideElement("startMutedOptions");
256
+            UIUtil.setVisible("startMutedOptions", false);
257 257
         }
258 258
     },
259 259
 
@@ -268,7 +268,7 @@ export default {
268 268
      * @param {boolean} show {true} to show those options, {false} to hide them
269 269
      */
270 270
     showFollowMeOptions (show) {
271
-        UIUtil.showOrHideElement(
271
+        UIUtil.setVisible(
272 272
             "followMeOptions",
273 273
             show && UIUtil.isSettingEnabled('moderator'));
274 274
     },

+ 3
- 3
modules/UI/toolbars/Toolbar.js Bestand weergeven

@@ -398,7 +398,7 @@ Toolbar = {
398 398
             let el = document.getElementById(id);
399 399
             UIUtil.setTooltip(el, 'toolbar.sharedvideo', 'right');
400 400
         }
401
-        UIUtil.showOrHideElement(id, shouldShow);
401
+        UIUtil.setVisible(id, shouldShow);
402 402
     },
403 403
 
404 404
     // checks whether desktop sharing is enabled and whether
@@ -416,7 +416,7 @@ Toolbar = {
416 416
             && UIUtil.isButtonEnabled('sip') && show;
417 417
         let id = 'toolbar_button_sip';
418 418
 
419
-        UIUtil.showOrHideElement(id, shouldShow);
419
+        UIUtil.setVisible(id, shouldShow);
420 420
     },
421 421
 
422 422
     // Shows or hides the dialpad button
@@ -424,7 +424,7 @@ Toolbar = {
424 424
         let shouldShow = UIUtil.isButtonEnabled('dialpad') && show;
425 425
         let id = 'toolbar_button_dialpad';
426 426
 
427
-        UIUtil.showOrHideElement(id, shouldShow);
427
+        UIUtil.setVisible(id, shouldShow);
428 428
     },
429 429
 
430 430
     /**

+ 16
- 48
modules/UI/util/UIUtil.js Bestand weergeven

@@ -240,11 +240,13 @@ const IndicatorFontSizes = {
240 240
     },
241 241
 
242 242
     /**
243
-     * Shows the element given by id.
243
+     * Shows / hides the element given by id.
244 244
      *
245
-     * @param {String} the identifier of the element to show
245
+     * @param {string|HTMLElement} idOrElement the identifier or the element
246
+     *        to show/hide
247
+     * @param {boolean} show <tt>true</tt> to show or <tt>false</tt> to hide
246 248
      */
247
-    showElement(id) {
249
+    setVisible(id, visible) {
248 250
         let element;
249 251
         if (id instanceof HTMLElement) {
250 252
             element = id;
@@ -256,55 +258,20 @@ const IndicatorFontSizes = {
256 258
             return;
257 259
         }
258 260
 
259
-        if(element.classList.contains('hide')) {
261
+        if (!visible)
262
+            element.classList.add('hide');
263
+        else if (element.classList.contains('hide')) {
260 264
             element.classList.remove('hide');
261 265
         }
262 266
 
263 267
         let type = this._getElementDefaultDisplay(element.tagName);
264 268
         let className = SHOW_CLASSES[type];
265
-        element.classList.add(className);
266
-    },
267
-
268
-    /**
269
-     * Shows or hides the element given (optionally by id).
270
-     *
271
-     * @param {string|HTMLElement} idOrElement the identifier or the element
272
-     *        to show/hide
273
-     * @param {boolean} show <tt>true</tt> to show or <tt>false</tt> to hide
274
-     */
275
-    showOrHideElement(idOrElement, show) {
276
-        if (show) {
277
-            this.showElement(idOrElement);
278
-        } else {
279
-            this.hideElement(idOrElement);
280
-        }
281
-    },
282
-
283
-    /**
284
-     * Hides the element given by id.
285
-     *
286
-     * @param {String} the identifier of the element to hide
287
-     */
288
-    hideElement(id) {
289
-        let element;
290
-        if (id instanceof HTMLElement) {
291
-            element = id;
292
-        } else {
293
-            element = document.getElementById(id);
294
-        }
295 269
 
296
-        if (!element) {
297
-            return;
270
+        if (visible) {
271
+            element.classList.add(className);
298 272
         }
299
-
300
-        let type = this._getElementDefaultDisplay(element.tagName);
301
-        let className = SHOW_CLASSES[type];
302
-
303
-        if(element.classList.contains(className)) {
273
+        else if (element.classList.contains(className))
304 274
             element.classList.remove(className);
305
-        }
306
-
307
-        element.classList.add('hide');
308 275
     },
309 276
 
310 277
     /**
@@ -326,12 +293,13 @@ const IndicatorFontSizes = {
326 293
     /**
327 294
      * Shows / hides the element with the given jQuery selector.
328 295
      *
329
-     * @param {jQuery} selector the jQuery selector of the element to show/hide
296
+     * @param {jQuery} jquerySelector the jQuery selector of the element to
297
+     * show / shide
330 298
      * @param {boolean} isVisible
331 299
      */
332
-    setVisibility(selector, isVisible) {
333
-        if (selector && selector.length > 0) {
334
-            selector.css("visibility", isVisible ? "visible" : "hidden");
300
+    setVisibleBySelector(jquerySelector, isVisible) {
301
+        if (jquerySelector && jquerySelector.length > 0) {
302
+            jquerySelector.css("visibility", isVisible ? "visible" : "hidden");
335 303
         }
336 304
     },
337 305
 

+ 1
- 1
modules/UI/videolayout/LargeVideoManager.js Bestand weergeven

@@ -334,7 +334,7 @@ export default class LargeVideoManager {
334 334
 
335 335
         let id = 'localConnectionMessage';
336 336
 
337
-        UIUtil.showOrHideElement(id, show);
337
+        UIUtil.setVisible(id, show);
338 338
 
339 339
         if (show) {
340 340
             // Avatar message conflicts with 'videoConnectionMessage',

+ 13
- 13
modules/UI/videolayout/SmallVideo.js Bestand weergeven

@@ -218,7 +218,7 @@ SmallVideo.prototype.hideIndicator = function () {
218 218
 SmallVideo.prototype.showAudioIndicator = function (isMuted) {
219 219
     let mutedIndicator = this.getAudioMutedIndicator();
220 220
 
221
-    UIUtil.showOrHideElement(mutedIndicator, isMuted);
221
+    UIUtil.setVisible(mutedIndicator, isMuted);
222 222
 
223 223
     this.isAudioMuted = isMuted;
224 224
 };
@@ -268,7 +268,7 @@ SmallVideo.prototype.setVideoMutedView = function(isMuted) {
268 268
 
269 269
     let element = this.getVideoMutedIndicator();
270 270
 
271
-    UIUtil.showOrHideElement(element, isMuted);
271
+    UIUtil.setVisible(element, isMuted);
272 272
 };
273 273
 
274 274
 /**
@@ -505,24 +505,24 @@ SmallVideo.prototype.updateView = function () {
505 505
     // Determine whether video, avatar or blackness should be displayed
506 506
     let displayMode = this.selectDisplayMode();
507 507
     // Show/hide video.
508
-    UIUtil.setVisibility(   this.selectVideoElement(),
509
-                            (displayMode === DISPLAY_VIDEO
508
+    UIUtil.setVisibleBySelector(this.selectVideoElement(),
509
+                                (displayMode === DISPLAY_VIDEO
510 510
                                 || displayMode === DISPLAY_VIDEO_WITH_NAME));
511 511
     // Show/hide the avatar.
512
-    UIUtil.setVisibility(   this.$avatar(),
513
-                            (displayMode === DISPLAY_AVATAR
512
+    UIUtil.setVisibleBySelector(this.$avatar(),
513
+                                (displayMode === DISPLAY_AVATAR
514 514
                                 || displayMode === DISPLAY_AVATAR_WITH_NAME));
515 515
     // Show/hide the display name.
516
-    UIUtil.setVisibility(   this.$displayName(),
517
-                            !this.hideDisplayName
518
-                            && (displayMode === DISPLAY_BLACKNESS_WITH_NAME
516
+    UIUtil.setVisibleBySelector(this.$displayName(),
517
+                                !this.hideDisplayName
518
+                                && (displayMode === DISPLAY_BLACKNESS_WITH_NAME
519 519
                                 || displayMode === DISPLAY_VIDEO_WITH_NAME
520 520
                                 || displayMode === DISPLAY_AVATAR_WITH_NAME));
521 521
     // show hide overlay when there is a video or avatar under
522 522
     // the display name
523
-    UIUtil.setVisibility(   $('#' + this.videoSpanId
523
+    UIUtil.setVisibleBySelector($('#' + this.videoSpanId
524 524
                                 + ' .videocontainer__hoverOverlay'),
525
-                            (displayMode === DISPLAY_AVATAR_WITH_NAME
525
+                                (displayMode === DISPLAY_AVATAR_WITH_NAME
526 526
                                 || displayMode === DISPLAY_VIDEO_WITH_NAME));
527 527
 };
528 528
 
@@ -570,7 +570,7 @@ SmallVideo.prototype.showDominantSpeakerIndicator = function (show) {
570 570
         tooltip: 'speaker'
571 571
     });
572 572
 
573
-    UIUtil.showOrHideElement(indicatorSpan, show);
573
+    UIUtil.setVisible(indicatorSpan, show);
574 574
 };
575 575
 
576 576
 /**
@@ -594,7 +594,7 @@ SmallVideo.prototype.showRaisedHandIndicator = function (show) {
594 594
         tooltip: 'raisedHand'
595 595
     });
596 596
 
597
-    UIUtil.showOrHideElement(indicatorSpan, show);
597
+    UIUtil.setVisible(indicatorSpan, show);
598 598
 };
599 599
 
600 600
 /**

+ 1
- 1
modules/UI/videolayout/VideoLayout.js Bestand weergeven

@@ -1144,7 +1144,7 @@ var VideoLayout = {
1144 1144
     updateResolutionLabel(isResolutionHD) {
1145 1145
         let id = 'videoResolutionLabel';
1146 1146
 
1147
-        UIUtil.showOrHideElement(id, isResolutionHD);
1147
+        UIUtil.setVisible(id, isResolutionHD);
1148 1148
     },
1149 1149
 
1150 1150
     /**

Laden…
Annuleren
Opslaan