Bläddra i källkod

Merge pull request #1054 from kkrisstoff/task/make-extended-toolbar-dynamically-created-buttons

make extended buttons dynamic
master
hristoterezov 8 år sedan
förälder
incheckning
a7a7f269c3
5 ändrade filer med 162 tillägg och 102 borttagningar
  1. 3
    18
      css/_toolbars.scss
  2. 3
    27
      index.html
  3. 14
    2
      interface_config.js
  4. 1
    1
      modules/UI/UI.js
  5. 141
    54
      modules/UI/toolbars/Toolbar.js

+ 3
- 18
css/_toolbars.scss Visa fil

@@ -42,22 +42,7 @@
42 42
     margin-right: auto;
43 43
     width: auto;
44 44
     border-radius: 3px;
45
-
46
-    /**
47
-     * First button in the toolbar.
48
-     */
49
-    .first {
50
-        border-bottom-left-radius: 3px;
51
-        border-top-left-radius: 3px;
52
-    }
53
-
54
-    /**
55
-     * Last button in the toolbar.
56
-     */
57
-    .last {
58
-        border-bottom-right-radius: 3px;
59
-        border-top-right-radius: 3px;
60
-    }
45
+    overflow: hidden;
61 46
 
62 47
     /**
63 48
      * Splitter button in the toolbar.
@@ -75,8 +60,8 @@
75 60
     display: flex;
76 61
     width: $defaultToolbarSize;
77 62
     height: 100%;
78
-    top: 0px;
79
-    left: 0px;
63
+    top: 0;
64
+    left: 0;
80 65
     padding-top: 10px;
81 66
     box-sizing: border-box;
82 67
     flex-direction: column;

+ 3
- 27
index.html Visa fil

@@ -131,37 +131,13 @@
131 131
                 <div id="notice" class="notice" style="display: none">
132 132
                     <span id="noticeText" class="noticeText"></span>
133 133
                 </div>
134
-                <span id="mainToolbar" class="toolbar"></span>
134
+                <div id="mainToolbar" class="toolbar"></div>
135 135
         </div>
136 136
         <div id="subject" class="hide"></div>
137 137
 
138 138
         <div id="extendedToolbar" class="toolbar">
139
-            <a class="button" id="toolbar_button_profile" data-container="body" data-placement="right" data-i18n="[content]toolbar.profile">
140
-                <img id="avatar" src="images/avatar2.png"/>
141
-            </a>
142
-            <a class="button icon-contactList" id="toolbar_contact_list" shortcut="contactlistpopover">
143
-                <span class="badge-round">
144
-                    <span id="numberOfParticipants"></span>
145
-                </span>
146
-            </a>
147
-            <!--a class="button icon-link" id="toolbar_button_link"></a-->
148
-            <a class="button icon-chat" id="toolbar_button_chat" shortcut="toggleChatPopover">
149
-                <span class="badge-round">
150
-                    <span id="unreadMessages"></span>
151
-                </span>
152
-            </a>
153
-            <a class="button" id="toolbar_button_record" style="display: none"></a>
154
-            <a class="button icon-share-doc" id="toolbar_button_etherpad"></a>
155
-            <a class="button icon-shared-video" id="toolbar_button_sharedvideo" style="display: none">
156
-                <ul id="sharedVideoMutedPopup" class="loginmenu extendedToolbarPopup">
157
-                    <li data-i18n="[html]toolbar.sharedVideoMutedPopup"></li>
158
-                </ul>
159
-            </a>
160
-            <a class="button icon-telephone" id="toolbar_button_sip" style="display: none"></a>
161
-            <a class="button icon-dialpad" id="toolbar_button_dialpad" style="display: none"></a>
162
-            <a class="button icon-settings" id="toolbar_button_settings"></a>
163
-            <a class="button icon-raised-hand" id="toolbar_button_raisehand" shortcut="raiseHandPopover"></a>
164
-            <a class="button icon-toggle-filmstrip" id="toolbar_film_strip" data-container="body" shortcut="filmstripPopover"></a>
139
+            <div id="extendedToolbarButtons"></div>
140
+
165 141
             <a class="button icon-feedback" id="feedbackButton"></a>
166 142
 
167 143
             <div id="sideToolbarContainer">

+ 14
- 2
interface_config.js Visa fil

@@ -24,14 +24,26 @@ var interfaceConfig = { // eslint-disable-line no-unused-vars
24 24
     AUTHENTICATION_ENABLE: true,
25 25
     // the toolbar buttons line is intentionally left in one line, to be able
26 26
     // to easily override values or remove them using regex
27
-    MAIN_TOOLBAR_BUTTONS: ['microphone', 'camera', 'desktop', 'invite', 'fullscreen', 'hangup'], // jshint ignore:line
28 27
     /**
29 28
      * The index of the splitter button in the main toolbar. The splitter
30 29
      * button is a button in the toolbar that will be applied a special styling
31 30
      * visually dividing the toolbar buttons.
32 31
      */
33 32
     //MAIN_TOOLBAR_SPLITTER_INDEX: -1,
34
-    TOOLBAR_BUTTONS: ['profile', 'authentication', 'microphone', 'camera', 'desktop', 'recording', 'security', 'raisehand', 'chat', 'etherpad', 'sharedvideo', 'sip', 'dialpad', 'settings', 'hangup', 'filmstrip', 'contacts'], // jshint ignore:line
33
+    /**
34
+     * the toolbar buttons line is intentionally left in one line, to be able
35
+     * to easily override values or remove them using regex
36
+     */
37
+    TOOLBAR_BUTTONS: [
38
+        //main toolbar
39
+        'microphone', 'camera', 'desktop', 'invite', 'fullscreen', 'hangup',
40
+        //extended toolbar
41
+        'profile', 'contacts', 'chat', 'recording', 'etherpad', 'sharedvideo', 'sip', 'dialpad', 'settings', 'raisehand', 'filmstrip'], // jshint ignore:line
42
+    /**
43
+     * Main Toolbar Buttons
44
+     * All of them should be in TOOLBAR_BUTTONS
45
+     */
46
+    MAIN_TOOLBAR_BUTTONS: ['microphone', 'camera', 'desktop', 'invite', 'fullscreen', 'hangup'], // jshint ignore:line
35 47
     SETTINGS_SECTIONS: ['language', 'devices', 'moderator'],
36 48
     // Determines how the video would fit the screen. 'both' would fit the whole
37 49
     // screen, 'height' would fit the original video height to the height of the

+ 1
- 1
modules/UI/UI.js Visa fil

@@ -1021,7 +1021,7 @@ UI.addMessage = function (from, displayName, message, stamp) {
1021 1021
 // eslint-disable-next-line no-unused-vars
1022 1022
 UI.updateDTMFSupport = function (isDTMFSupported) {
1023 1023
     //TODO: enable when the UI is ready
1024
-    //Toolbar.showDialPadButton(dtmfSupport);
1024
+    //Toolbar.showDialPadButton(isDTMFSupported);
1025 1025
 };
1026 1026
 
1027 1027
 /**

+ 141
- 54
modules/UI/toolbars/Toolbar.js Visa fil

@@ -6,6 +6,11 @@ import SideContainerToggler from "../side_pannels/SideContainerToggler";
6 6
 let emitter = null;
7 7
 let Toolbar;
8 8
 
9
+/**
10
+ * Handlers for toolbar buttons.
11
+ *
12
+ * buttonId {string}: handler {function}
13
+ */
9 14
 const buttonHandlers = {
10 15
     "toolbar_button_profile": function () {
11 16
         JitsiMeetJS.analytics.sendEvent('toolbar.profile.toggled');
@@ -124,6 +129,9 @@ const buttonHandlers = {
124 129
     }
125 130
 };
126 131
 
132
+/**
133
+ * All toolbars buttons description
134
+ */
127 135
 const defaultToolbarButtons = {
128 136
     'microphone': {
129 137
         id: 'toolbar_button_mute',
@@ -194,6 +202,7 @@ const defaultToolbarButtons = {
194 202
     'chat': {
195 203
         id: 'toolbar_button_chat',
196 204
         tooltipKey: 'toolbar.chat',
205
+        className: 'button icon-chat',
197 206
         shortcut: 'C',
198 207
         shortcutAttr: 'toggleChatPopover',
199 208
         shortcutFunc: function() {
@@ -201,21 +210,31 @@ const defaultToolbarButtons = {
201 210
             APP.UI.toggleChat();
202 211
         },
203 212
         shortcutDescription: 'keyboardShortcuts.toggleChat',
204
-        sideContainerId: 'chat_container'
213
+        sideContainerId: 'chat_container',
214
+        html: `<span class="badge-round">
215
+                   <span id="unreadMessages"></span>
216
+               </span>`
205 217
     },
206 218
     'contacts': {
207 219
         id: 'toolbar_contact_list',
208 220
         tooltipKey: 'bottomtoolbar.contactlist',
209
-        sideContainerId: 'contacts_container'
221
+        className: 'button icon-contactList',
222
+        sideContainerId: 'contacts_container',
223
+        html: `<span class="badge-round">
224
+                   <span id="numberOfParticipants"></span>
225
+               </span>`
210 226
     },
211 227
     'profile': {
212 228
         id: 'toolbar_button_profile',
213 229
         tooltipKey: 'profile.setDisplayNameLabel',
214
-        sideContainerId: 'profile_container'
230
+        className: 'button',
231
+        sideContainerId: 'profile_container',
232
+        html: `<img id="avatar" src="images/avatar2.png"/>`
215 233
     },
216 234
     'etherpad': {
217 235
         id: 'toolbar_button_etherpad',
218 236
         tooltipKey: 'toolbar.etherpad',
237
+        className: 'button icon-share-doc'
219 238
     },
220 239
     'fullscreen': {
221 240
         id: 'toolbar_button_fullScreen',
@@ -234,6 +253,7 @@ const defaultToolbarButtons = {
234 253
     'settings': {
235 254
         id: 'toolbar_button_settings',
236 255
         tooltipKey: 'toolbar.Settings',
256
+        className: 'button icon-settings',
237 257
         sideContainerId: "settings_container"
238 258
     },
239 259
     'hangup': {
@@ -246,6 +266,7 @@ const defaultToolbarButtons = {
246 266
     'filmstrip': {
247 267
         id: 'toolbar_film_strip',
248 268
         tooltipKey: 'toolbar.filmstrip',
269
+        className: "button icon-toggle-filmstrip",
249 270
         shortcut: "F",
250 271
         shortcutAttr: "filmstripPopover",
251 272
         shortcutFunc: function() {
@@ -267,6 +288,34 @@ const defaultToolbarButtons = {
267 288
         shortcutDescription: "keyboardShortcuts.raiseHand",
268 289
         content: "Raise Hand",
269 290
         i18n: "[content]toolbar.raiseHand"
291
+    },
292
+    //init and btn handler: Recording.initRecordingButton (Recording.js)
293
+    'recording': {
294
+        id: 'toolbar_button_record',
295
+        tooltipKey: 'liveStreaming.buttonTooltip',
296
+        className: 'button'
297
+    },
298
+    'sharedvideo': {
299
+        id: 'toolbar_button_sharedvideo',
300
+        tooltipKey: 'toolbar.sharedvideo',
301
+        className: 'button icon-shared-video',
302
+        html: `<ul id="sharedVideoMutedPopup" 
303
+                   class="loginmenu extendedToolbarPopup">
304
+                   <li data-i18n="[html]toolbar.sharedVideoMutedPopup"></li>
305
+               </ul>
306
+`
307
+    },
308
+    'sip': {
309
+        id: 'toolbar_button_sip',
310
+        tooltipKey: 'toolbar.sip',
311
+        className: 'button icon-telephone'
312
+    },
313
+    'dialpad': {
314
+        id: 'toolbar_button_dialpad',
315
+        tooltipKey: 'toolbar.dialpad',
316
+        className: 'button icon-dialpad',
317
+        //TODO: remove it after UI.updateDTMFSupport fix
318
+        hidden: true
270 319
     }
271 320
 };
272 321
 
@@ -281,8 +330,7 @@ function showSipNumberInput () {
281 330
     let titleKey = "dialog.sipMsg";
282 331
     let msgString = (`
283 332
             <input name="sipNumber" type="text"
284
-                   value="${defaultNumber}" autofocus>
285
-    `);
333
+                   value="${defaultNumber}" autofocus>`);
286 334
 
287 335
     APP.UI.messageHandler.openTwoButtonDialog({
288 336
         titleKey,
@@ -297,6 +345,19 @@ function showSipNumberInput () {
297 345
     });
298 346
 }
299 347
 
348
+/**
349
+ * Get place for toolbar button.
350
+ * Now it can be in main toolbar or in extended (left) toolbar
351
+ *
352
+ * @param btn {string}
353
+ * @returns {string}
354
+ */
355
+function getToolbarButtonPlace (btn) {
356
+    return interfaceConfig.MAIN_TOOLBAR_BUTTONS.includes(btn) ?
357
+        'main' :
358
+        'extended';
359
+}
360
+
300 361
 Toolbar = {
301 362
     init (eventEmitter) {
302 363
         emitter = eventEmitter;
@@ -305,45 +366,14 @@ Toolbar = {
305 366
         this.toolbarSelector = $("#mainToolbarContainer");
306 367
         this.extendedToolbarSelector = $("#extendedToolbar");
307 368
 
308
-        // First hide all disabled buttons in the extended toolbar.
309
-        // TODO: Make the extended toolbar dynamically created.
310
-        UIUtil.hideDisabledButtons(defaultToolbarButtons);
369
+        // Initialise the toolbar buttons.
370
+        // The main toolbar will only take into account
371
+        // it's own configuration from interface_config.
372
+        this._initToolbarButtons();
311 373
 
312
-        // Initialise the main toolbar. The main toolbar will only take into
313
-        // account it's own configuration from interface_config.
314
-        this._initMainToolbarButtons();
315
-
316
-        Object.keys(defaultToolbarButtons).forEach(
317
-            id => {
318
-                if (UIUtil.isButtonEnabled(id)) {
319
-                    let button = defaultToolbarButtons[id];
320
-                    let buttonElement = document.getElementById(button.id);
321
-
322
-                    let tooltipPosition
323
-                        = (interfaceConfig.MAIN_TOOLBAR_BUTTONS
324
-                                .indexOf(id) > -1)
325
-                            ? "bottom" : "right";
326
-
327
-                    UIUtil.setTooltip(  buttonElement,
328
-                                        button.tooltipKey,
329
-                                        tooltipPosition);
330
-
331
-                    if (button.shortcut)
332
-                        APP.keyboardshortcut.registerShortcut(
333
-                            button.shortcut,
334
-                            button.shortcutAttr,
335
-                            button.shortcutFunc,
336
-                            button.shortcutDescription
337
-                        );
338
-                }
339
-            }
340
-        );
374
+        this._setShortcutsAndTooltips();
341 375
 
342
-        Object.keys(buttonHandlers).forEach(
343
-            buttonId => $(`#${buttonId}`).click(function(event) {
344
-                !$(this).prop('disabled') && buttonHandlers[buttonId](event);
345
-            })
346
-        );
376
+        this._setButtonHandlers();
347 377
 
348 378
         APP.UI.addListener(UIEvents.SIDE_TOOLBAR_CONTAINER_TOGGLED,
349 379
             (containerId, isVisible) => {
@@ -703,16 +733,17 @@ Toolbar = {
703 733
     },
704 734
 
705 735
     /**
706
-     * Initialise main toolbar buttons.
736
+     * Initialise toolbar buttons.
707 737
      */
708
-    _initMainToolbarButtons() {
709
-        interfaceConfig.MAIN_TOOLBAR_BUTTONS.forEach((value, index) => {
738
+    _initToolbarButtons() {
739
+        interfaceConfig.TOOLBAR_BUTTONS.forEach((value, index) => {
740
+            let place = getToolbarButtonPlace(value);
741
+
710 742
             if (value && value in defaultToolbarButtons) {
711 743
                 let button = defaultToolbarButtons[value];
712
-                this._addMainToolbarButton(
744
+                this._addToolbarButton(
713 745
                     button,
714
-                    (index === 0),
715
-                    (index === interfaceConfig.MAIN_TOOLBAR_BUTTONS.length -1),
746
+                    place,
716 747
                     (interfaceConfig.MAIN_TOOLBAR_SPLITTER_INDEX !== undefined
717 748
                         && index
718 749
                             === interfaceConfig.MAIN_TOOLBAR_SPLITTER_INDEX));
@@ -721,7 +752,7 @@ Toolbar = {
721 752
     },
722 753
 
723 754
     /**
724
-     * Adds the given button to the main (top) toolbar.
755
+     * Adds the given button to the main (top) or extended (left) toolbar.
725 756
      *
726 757
      * @param {Object} the button to add.
727 758
      * @param {boolean} isFirst indicates if this is the first button in the
@@ -731,16 +762,26 @@ Toolbar = {
731 762
      * @param {boolean} isSplitter if this button is a splitter button for
732 763
      * the dialog, which means that a special splitter style will be applied
733 764
      */
734
-    _addMainToolbarButton(button, isFirst, isLast, isSplitter) {
765
+    _addToolbarButton(button, place, isSplitter) {
766
+        const places = {
767
+            main: 'mainToolbar',
768
+            extended: 'extendedToolbarButtons'
769
+        };
770
+        let id = places[place];
735 771
         let buttonElement = document.createElement("a");
736 772
         if (button.className)
737 773
             buttonElement.className = button.className
738
-                                    + ((isFirst) ? " first" : "")
739
-                                    + ((isLast) ? " last" : "")
740
-                                    + ((isSplitter) ? " splitter": "");
774
+                + ((isSplitter) ? " splitter": "");
741 775
 
742 776
         buttonElement.id = button.id;
743 777
 
778
+        if (button.html)
779
+            buttonElement.innerHTML = button.html;
780
+
781
+        //TODO: remove it after UI.updateDTMFSupport fix
782
+        if (button.hidden)
783
+            buttonElement.style.display = 'none';
784
+
744 785
         if (button.shortcutAttr)
745 786
             buttonElement.setAttribute("shortcut", button.shortcutAttr);
746 787
 
@@ -754,7 +795,7 @@ Toolbar = {
754 795
         buttonElement.setAttribute("data-placement", "bottom");
755 796
         this._addPopups(buttonElement, button.popups);
756 797
 
757
-        document.getElementById("mainToolbar")
798
+        document.getElementById(id)
758 799
             .appendChild(buttonElement);
759 800
     },
760 801
 
@@ -779,6 +820,52 @@ Toolbar = {
779 820
      */
780 821
      _setToggledState(elementId, isToggled) {
781 822
         $("#" + elementId).toggleClass("toggled", isToggled);
823
+    },
824
+
825
+    /**
826
+     * Sets Shortcuts and Tooltips for all toolbar buttons
827
+     *
828
+     * @private
829
+     */
830
+    _setShortcutsAndTooltips() {
831
+        Object.keys(defaultToolbarButtons).forEach(
832
+            id => {
833
+                if (UIUtil.isButtonEnabled(id)) {
834
+                    let button = defaultToolbarButtons[id];
835
+                    let buttonElement = document.getElementById(button.id);
836
+                    if (!buttonElement) return false;
837
+                    let tooltipPosition
838
+                        = (interfaceConfig.MAIN_TOOLBAR_BUTTONS
839
+                        .indexOf(id) > -1)
840
+                        ? "bottom" : "right";
841
+
842
+                    UIUtil.setTooltip(  buttonElement,
843
+                        button.tooltipKey,
844
+                        tooltipPosition);
845
+
846
+                    if (button.shortcut)
847
+                        APP.keyboardshortcut.registerShortcut(
848
+                            button.shortcut,
849
+                            button.shortcutAttr,
850
+                            button.shortcutFunc,
851
+                            button.shortcutDescription
852
+                        );
853
+                }
854
+            }
855
+        );
856
+    },
857
+
858
+    /**
859
+     * Sets Handlers for all toolbar buttons
860
+     *
861
+     * @private
862
+     */
863
+    _setButtonHandlers() {
864
+        Object.keys(buttonHandlers).forEach(
865
+            buttonId => $(`#${buttonId}`).click(function(event) {
866
+                !$(this).prop('disabled') && buttonHandlers[buttonId](event);
867
+            })
868
+        );
782 869
     }
783 870
 };
784 871
 

Laddar…
Avbryt
Spara