瀏覽代碼

ref(jQuery) Replace some jQuery with JS (#13102)

factor2
Robert Pintilii 2 年之前
父節點
當前提交
ac8e088e50
沒有連結到貢獻者的電子郵件帳戶。

+ 19
- 19
modules/UI/UI.js 查看文件

5
 
5
 
6
 import Logger from '@jitsi/logger';
6
 import Logger from '@jitsi/logger';
7
 import EventEmitter from 'events';
7
 import EventEmitter from 'events';
8
-import $ from 'jquery';
9
 
8
 
10
 import { isMobileBrowser } from '../../react/features/base/environment/utils';
9
 import { isMobileBrowser } from '../../react/features/base/environment/utils';
11
 import { setColorAlpha } from '../../react/features/base/util';
10
 import { setColorAlpha } from '../../react/features/base/util';
106
     VideoLayout.resizeVideoArea();
105
     VideoLayout.resizeVideoArea();
107
 
106
 
108
     if (isMobileBrowser()) {
107
     if (isMobileBrowser()) {
109
-        $('body').addClass('mobile-browser');
108
+        document.body.classList.add('mobile-browser');
110
     } else {
109
     } else {
111
-        $('body').addClass('desktop-browser');
110
+        document.body.classList.add('desktop-browser');
112
     }
111
     }
113
 
112
 
114
     if (config.backgroundAlpha !== undefined) {
113
     if (config.backgroundAlpha !== undefined) {
115
-        const backgroundColor = $('body').css('background-color');
114
+        const backgroundColor = getComputedStyle(document.body).getPropertyValue('background-color');
116
         const alphaColor = setColorAlpha(backgroundColor, config.backgroundAlpha);
115
         const alphaColor = setColorAlpha(backgroundColor, config.backgroundAlpha);
117
 
116
 
118
-        $('body').css('background-color', alphaColor);
117
+        document.body.style.backgroundColor = alphaColor;
119
     }
118
     }
120
 
119
 
121
     if (config.iAmRecorder) {
120
     if (config.iAmRecorder) {
134
 UI.registerListeners
133
 UI.registerListeners
135
     = () => UIListeners.forEach((value, key) => UI.addListener(key, value));
134
     = () => UIListeners.forEach((value, key) => UI.addListener(key, value));
136
 
135
 
136
+/**
137
+ *
138
+ */
139
+function onResize() {
140
+    VideoLayout.onResize();
141
+}
142
+
137
 /**
143
 /**
138
  * Setup some DOM event listeners.
144
  * Setup some DOM event listeners.
139
  */
145
  */
140
 UI.bindEvents = () => {
146
 UI.bindEvents = () => {
141
-    /**
142
-     *
143
-     */
144
-    function onResize() {
145
-        VideoLayout.onResize();
146
-    }
147
-
148
     // Resize and reposition videos in full screen mode.
147
     // Resize and reposition videos in full screen mode.
149
-    $(document).on(
150
-            'webkitfullscreenchange mozfullscreenchange fullscreenchange',
151
-            onResize);
148
+    document.addEventListener('webkitfullscreenchange', onResize);
149
+    document.addEventListener('mozfullscreenchange', onResize);
150
+    document.addEventListener('fullscreenchange', onResize);
152
 
151
 
153
-    $(window).resize(onResize);
152
+    window.addEventListener('resize', onResize);
154
 };
153
 };
155
 
154
 
156
 /**
155
 /**
157
  * Unbind some DOM event listeners.
156
  * Unbind some DOM event listeners.
158
  */
157
  */
159
 UI.unbindEvents = () => {
158
 UI.unbindEvents = () => {
160
-    $(document).off(
161
-            'webkitfullscreenchange mozfullscreenchange fullscreenchange');
159
+    document.removeEventListener('webkitfullscreenchange', onResize);
160
+    document.removeEventListener('mozfullscreenchange', onResize);
161
+    document.removeEventListener('fullscreenchange', onResize);
162
 
162
 
163
-    $(window).off('resize');
163
+    window.removeEventListener('resize', onResize);
164
 };
164
 };
165
 
165
 
166
 /**
166
 /**

+ 3
- 5
modules/UI/videolayout/Filmstrip.js 查看文件

1
 /* global APP, interfaceConfig */
1
 /* global APP, interfaceConfig */
2
 
2
 
3
-import $ from 'jquery';
4
-
5
 import { getVerticalFilmstripVisibleAreaWidth, isFilmstripVisible } from '../../../react/features/filmstrip';
3
 import { getVerticalFilmstripVisibleAreaWidth, isFilmstripVisible } from '../../../react/features/filmstrip';
6
 
4
 
7
 const Filmstrip = {
5
 const Filmstrip = {
14
         // horizontal film strip mode for calculating how tall large video
12
         // horizontal film strip mode for calculating how tall large video
15
         // display should be.
13
         // display should be.
16
         if (isFilmstripVisible(APP.store) && !interfaceConfig.VERTICAL_FILMSTRIP) {
14
         if (isFilmstripVisible(APP.store) && !interfaceConfig.VERTICAL_FILMSTRIP) {
17
-            return $('.filmstrip').outerHeight();
15
+            return document.querySelector('.filmstrip').offsetHeight;
18
         }
16
         }
19
 
17
 
20
         return 0;
18
         return 0;
21
     },
19
     },
22
 
20
 
23
     /**
21
     /**
24
-     * Returns the width of the vertical filmstip if the filmstrip is visible and 0 otherwise.
22
+     * Returns the width of the vertical filmstrip if the filmstrip is visible and 0 otherwise.
25
      *
23
      *
26
-     * @returns {number} - The width of the vertical filmstip if the filmstrip is visible and 0 otherwise.
24
+     * @returns {number} - The width of the vertical filmstrip if the filmstrip is visible and 0 otherwise.
27
      */
25
      */
28
     getVerticalFilmstripWidth() {
26
     getVerticalFilmstripWidth() {
29
         return isFilmstripVisible(APP.store) ? getVerticalFilmstripVisibleAreaWidth() : 0;
27
         return isFilmstripVisible(APP.store) ? getVerticalFilmstripVisibleAreaWidth() : 0;

+ 20
- 20
modules/UI/videolayout/LargeVideoManager.js 查看文件

128
          */
128
          */
129
         this.videoTrack = undefined;
129
         this.videoTrack = undefined;
130
 
130
 
131
-        this.$container = $('#largeVideoContainer');
131
+        this.container = document.getElementById('largeVideoContainer');
132
 
132
 
133
-        this.$container.css({
134
-            display: 'inline-block'
135
-        });
133
+        this.container.style.display = 'inline-block';
136
 
134
 
137
-        this.$container.hover(
138
-            e => this.onHoverIn(e),
139
-            e => this.onHoverOut(e)
140
-        );
135
+        this.container.addEventListener('mouseenter', e => this.onHoverIn(e));
136
+        this.container.addEventListener('mouseleave', e => this.onHoverOut(e));
141
 
137
 
142
         // Bind event handler so it is only bound once for every instance.
138
         // Bind event handler so it is only bound once for every instance.
143
         this._onVideoResolutionUpdate
139
         this._onVideoResolutionUpdate
172
 
168
 
173
         ReactDOM.unmountComponentAtNode(this._dominantSpeakerAvatarContainer);
169
         ReactDOM.unmountComponentAtNode(this._dominantSpeakerAvatarContainer);
174
 
170
 
175
-        this.$container.css({ display: 'none' });
171
+        this.container.style.display = 'none';
176
     }
172
     }
177
 
173
 
178
     /**
174
     /**
540
      * @returns {void}
536
      * @returns {void}
541
      */
537
      */
542
     updatePresenceLabel(id) {
538
     updatePresenceLabel(id) {
543
-        const isConnectionMessageVisible
544
-            = $('#remoteConnectionMessage').is(':visible');
539
+        const isConnectionMessageVisible = getComputedStyle(
540
+            document.getElementById('remoteConnectionMessage')).display !== 'none';
545
 
541
 
546
         if (isConnectionMessageVisible) {
542
         if (isConnectionMessageVisible) {
547
             this.removePresenceLabel();
543
             this.removePresenceLabel();
549
             return;
545
             return;
550
         }
546
         }
551
 
547
 
552
-        const presenceLabelContainer = $('#remotePresenceMessage');
548
+        const presenceLabelContainer = document.getElementById('remotePresenceMessage');
553
 
549
 
554
-        if (presenceLabelContainer.length) {
550
+        if (presenceLabelContainer) {
555
             ReactDOM.render(
551
             ReactDOM.render(
556
                 <Provider store = { APP.store }>
552
                 <Provider store = { APP.store }>
557
                     <I18nextProvider i18n = { i18next }>
553
                     <I18nextProvider i18n = { i18next }>
560
                             className = 'presence-label' />
556
                             className = 'presence-label' />
561
                     </I18nextProvider>
557
                     </I18nextProvider>
562
                 </Provider>,
558
                 </Provider>,
563
-                presenceLabelContainer.get(0));
559
+                presenceLabelContainer);
564
         }
560
         }
565
     }
561
     }
566
 
562
 
570
      * @returns {void}
566
      * @returns {void}
571
      */
567
      */
572
     removePresenceLabel() {
568
     removePresenceLabel() {
573
-        const presenceLabelContainer = $('#remotePresenceMessage');
569
+        const presenceLabelContainer = document.getElementById('remotePresenceMessage');
574
 
570
 
575
-        if (presenceLabelContainer.length) {
576
-            ReactDOM.unmountComponentAtNode(presenceLabelContainer.get(0));
571
+        if (presenceLabelContainer) {
572
+            ReactDOM.unmountComponentAtNode(presenceLabelContainer);
577
         }
573
         }
578
     }
574
     }
579
 
575
 
582
      * @param {boolean} show
578
      * @param {boolean} show
583
      */
579
      */
584
     showWatermark(show) {
580
     showWatermark(show) {
585
-        $('.watermark').css('visibility', show ? 'visible' : 'hidden');
581
+        const watermark = document.querySelectorAll('.watermark');
582
+
583
+        watermark.forEach(el => {
584
+            el.style.visibility = show ? 'visible' : 'hidden';
585
+        });
586
     }
586
     }
587
 
587
 
588
     /**
588
     /**
607
         }
607
         }
608
 
608
 
609
         if (show) {
609
         if (show) {
610
-            $('#remoteConnectionMessage').css({ display: 'block' });
610
+            document.getElementById('remoteConnectionMessage').style.display = 'block';
611
         } else {
611
         } else {
612
-            $('#remoteConnectionMessage').hide();
612
+            document.getElementById('remoteConnectionMessage').style.display = 'none';
613
         }
613
         }
614
     }
614
     }
615
 
615
 

+ 15
- 18
modules/UI/videolayout/VideoContainer.js 查看文件

223
          * @type {boolean}
223
          * @type {boolean}
224
          */
224
          */
225
         this.avatarDisplayed = false;
225
         this.avatarDisplayed = false;
226
-        this.$avatar = $('#dominantSpeaker');
226
+        this.avatar = document.getElementById('dominantSpeaker');
227
 
227
 
228
         /**
228
         /**
229
-         * A jQuery selector of the remote connection message.
230
-         * @type {jQuery|HTMLElement}
229
+         * The HTMLElements of the remote connection message.
230
+         * @type {HTMLElement}
231
          */
231
          */
232
-        this.$remoteConnectionMessage = $('#remoteConnectionMessage');
233
-
234
-        this.$remotePresenceMessage = $('#remotePresenceMessage');
232
+        this.remoteConnectionMessage = document.getElementById('remoteConnectionMessage');
233
+        this.remotePresenceMessage = document.getElementById('remotePresenceMessage');
235
 
234
 
236
         this.$wrapper = $('#largeVideoWrapper');
235
         this.$wrapper = $('#largeVideoWrapper');
237
 
236
 
241
          * video anyway.
240
          * video anyway.
242
          */
241
          */
243
         this.$wrapperParent = this.$wrapper.parent();
242
         this.$wrapperParent = this.$wrapper.parent();
244
-        this.avatarHeight = $('#dominantSpeakerAvatarContainer').height();
243
+        this.avatarHeight = document.getElementById('dominantSpeakerAvatarContainer').getBoundingClientRect().height;
245
         this.$video[0].onplaying = function(event) {
244
         this.$video[0].onplaying = function(event) {
246
             if (typeof resizeContainer === 'function') {
245
             if (typeof resizeContainer === 'function') {
247
                 resizeContainer(event);
246
                 resizeContainer(event);
358
      * @returns {void}
357
      * @returns {void}
359
      */
358
      */
360
     positionRemoteStatusMessages() {
359
     positionRemoteStatusMessages() {
361
-        this._positionParticipantStatus(this.$remoteConnectionMessage);
362
-        this._positionParticipantStatus(this.$remotePresenceMessage);
360
+        this._positionParticipantStatus(this.remoteConnectionMessage);
361
+        this._positionParticipantStatus(this.remotePresenceMessage);
363
     }
362
     }
364
 
363
 
365
     /**
364
     /**
369
      * @private
368
      * @private
370
      * @returns {void}
369
      * @returns {void}
371
      */
370
      */
372
-    _positionParticipantStatus($element) {
371
+    _positionParticipantStatus(element) {
373
         if (this.avatarDisplayed) {
372
         if (this.avatarDisplayed) {
374
-            const $avatarImage = $('#dominantSpeakerAvatarContainer');
373
+            const avatarImage = document.getElementById('dominantSpeakerAvatarContainer').getBoundingClientRect();
375
 
374
 
376
-            $element.css(
377
-                'top',
378
-                $avatarImage.offset().top + $avatarImage.height() + 10);
375
+            element.style.top = avatarImage.top + avatarImage.height + 10;
379
         } else {
376
         } else {
380
-            const height = $element.height();
381
-            const parentHeight = $element.parent().height();
377
+            const height = element.getBoundingClientRect().height;
378
+            const parentHeight = element.parentElement.getBoundingClientRect().height;
382
 
379
 
383
-            $element.css('top', (parentHeight / 2) - (height / 2));
380
+            element.style.top = (parentHeight / 2) - (height / 2);
384
         }
381
         }
385
     }
382
     }
386
 
383
 
540
      * @param {boolean} show
537
      * @param {boolean} show
541
      */
538
      */
542
     showAvatar(show) {
539
     showAvatar(show) {
543
-        this.$avatar.css('visibility', show ? 'visible' : 'hidden');
540
+        this.avatar.style.visibility = show ? 'visible' : 'hidden';
544
         this.avatarDisplayed = show;
541
         this.avatarDisplayed = show;
545
 
542
 
546
         APP.API.notifyLargeVideoVisibilityChanged(show);
543
         APP.API.notifyLargeVideoVisibilityChanged(show);

Loading…
取消
儲存