Bladeren bron

Remove duplication

master
Lyubomir Marinov 8 jaren geleden
bovenliggende
commit
231cd49916
1 gewijzigde bestanden met toevoegingen van 44 en 28 verwijderingen
  1. 44
    28
      modules/UI/toolbars/Toolbar.js

+ 44
- 28
modules/UI/toolbars/Toolbar.js Bestand weergeven

@@ -604,22 +604,44 @@ const Toolbar = {
604 604
      * or disabled
605 605
      */
606 606
     setVideoIconEnabled (enabled) {
607
-        var $btn = $('#toolbar_button_camera');
607
+        this._setMediaIconEnabled(
608
+                '#toolbar_button_camera',
609
+                enabled,
610
+                /* data-i18n attribute value */
611
+                `[content]toolbar.${enabled ? 'videomute' : 'cameraDisabled'}`,
612
+                /* shortcut attribute value */
613
+                'toggleVideoPopover');
614
+
615
+        enabled || this.toggleVideoIcon(!enabled);
616
+    },
617
+
618
+    /**
619
+     * Enables/disables the toolbar button associated with a specific media such
620
+     * as audio or video.
621
+     *
622
+     * @param {string} btn - The jQuery selector <tt>string</tt> which
623
+     * identifies the toolbar button to be enabled/disabled.
624
+     * @param {boolean} enabled - <tt>true</tt> to enable the specified
625
+     * <tt>btn</tt>  or <tt>false</tt> to disable it.
626
+     * @param {string} dataI18n - The value to assign to the <tt>data-i18n</tt>
627
+     * attribute of the specified <tt>btn</tt>.
628
+     * @param {string} shortcut - The value, if any, to assign to the
629
+     * <tt>shortcut</tt> attribute of the specified <tt>btn</tt> if the toolbar
630
+     * button is enabled.
631
+     */
632
+    _setMediaIconEnabled(btn, enabled, dataI18n, shortcut) {
633
+        const $btn = $(btn);
608 634
 
609 635
         $btn
610
-            .prop("disabled", !enabled)
611
-            .attr("data-i18n", enabled
612
-                ? "[content]toolbar.videomute"
613
-                : "[content]toolbar.cameraDisabled")
614
-            .attr("shortcut", enabled ? "toggleVideoPopover" : "");
636
+            .prop('disabled', !enabled)
637
+            .attr('data-i18n', dataI18n)
638
+            .attr('shortcut', enabled && shortcut ? shortcut : '');
615 639
 
616 640
         enabled
617
-            ? $btn.removeAttr("disabled")
618
-            : $btn.attr("disabled", "disabled");
641
+            ? $btn.removeAttr('disabled')
642
+            : $btn.attr('disabled', 'disabled');
619 643
 
620 644
         APP.translation.translateElement($btn);
621
-
622
-        !enabled && this.toggleVideoIcon(!enabled);
623 645
     },
624 646
 
625 647
     /**
@@ -628,8 +650,9 @@ const Toolbar = {
628 650
      * @param {boolean} muted if icon should look like muted or not
629 651
      */
630 652
     toggleAudioIcon(muted) {
631
-        $('#toolbar_button_mute').toggleClass("icon-microphone",
632
-            !muted).toggleClass("icon-mic-disabled", muted);
653
+        $('#toolbar_button_mute')
654
+            .toggleClass("icon-microphone", !muted)
655
+            .toggleClass("icon-mic-disabled", muted);
633 656
 
634 657
         this._setToggledState("toolbar_button_mute", muted);
635 658
     },
@@ -641,22 +664,15 @@ const Toolbar = {
641 664
      * or disabled
642 665
      */
643 666
     setAudioIconEnabled (enabled) {
644
-        var $btn = $('#toolbar_button_mute');
645
-
646
-        $btn
647
-            .prop("disabled", !enabled)
648
-            .attr("data-i18n", enabled
649
-                ? "[content]toolbar.mute"
650
-                : "[content]toolbar.micDisabled")
651
-            .attr("shortcut", enabled ? "mutePopover" : "");
652
-
653
-        enabled
654
-            ? $btn.removeAttr("disabled")
655
-            : $btn.attr("disabled", "disabled");
656
-
657
-        APP.translation.translateElement($btn);
658
-
659
-        !enabled && this.toggleAudioIcon(!enabled);
667
+        this._setMediaIconEnabled(
668
+                '#toolbar_button_mute',
669
+                enabled,
670
+                /* data-i18n attribute value */
671
+                `[content]toolbar.${enabled ? 'mute' : 'micDisabled'}`,
672
+                /* shortcut attribute value */
673
+                'mutePopover');
674
+
675
+        enabled || this.toggleAudioIcon(!enabled);
660 676
     },
661 677
 
662 678
     /**

Laden…
Annuleren
Opslaan