You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Toolbar.js 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750
  1. /* global APP, $, config, interfaceConfig, JitsiMeetJS */
  2. /* jshint -W101 */
  3. import UIUtil from '../util/UIUtil';
  4. import UIEvents from '../../../service/UI/UIEvents';
  5. import SideContainerToggler from "../side_pannels/SideContainerToggler";
  6. let roomUrl = null;
  7. let emitter = null;
  8. /**
  9. * Opens the invite link dialog.
  10. */
  11. function openLinkDialog () {
  12. let inviteAttributes;
  13. if (roomUrl === null) {
  14. inviteAttributes = 'data-i18n="[value]roomUrlDefaultMsg" value="' +
  15. APP.translation.translateString("roomUrlDefaultMsg") + '"';
  16. } else {
  17. inviteAttributes = "value=\"" + encodeURI(roomUrl) + "\"";
  18. }
  19. let title = APP.translation.generateTranslationHTML("dialog.shareLink");
  20. APP.UI.messageHandler.openTwoButtonDialog(
  21. null, null, null,
  22. '<h2>' + title + '</h2>'
  23. + '<input id="inviteLinkRef" type="text" '
  24. + inviteAttributes + ' onclick="this.select();" readonly>',
  25. false, "dialog.Invite",
  26. function (e, v) {
  27. if (v && roomUrl) {
  28. JitsiMeetJS.analytics.sendEvent('toolbar.invite.button');
  29. emitter.emit(UIEvents.USER_INVITED, roomUrl);
  30. }
  31. else {
  32. JitsiMeetJS.analytics.sendEvent('toolbar.invite.cancel');
  33. }
  34. },
  35. function (event) {
  36. if (roomUrl) {
  37. document.getElementById('inviteLinkRef').select();
  38. } else {
  39. if (event && event.target) {
  40. $(event.target).find('button[value=true]')
  41. .prop('disabled', true);
  42. }
  43. }
  44. },
  45. function (e, v, m, f) {
  46. if(!v && !m && !f)
  47. JitsiMeetJS.analytics.sendEvent('toolbar.invite.close');
  48. }
  49. );
  50. }
  51. const buttonHandlers = {
  52. "toolbar_button_profile": function () {
  53. JitsiMeetJS.analytics.sendEvent('toolbar.profile.toggled');
  54. emitter.emit(UIEvents.TOGGLE_PROFILE);
  55. },
  56. "toolbar_button_mute": function () {
  57. let sharedVideoManager = APP.UI.getSharedVideoManager();
  58. if (APP.conference.audioMuted) {
  59. // If there's a shared video with the volume "on" and we aren't
  60. // the video owner, we warn the user
  61. // that currently it's not possible to unmute.
  62. if (sharedVideoManager
  63. && sharedVideoManager.isSharedVideoVolumeOn()
  64. && !sharedVideoManager.isSharedVideoOwner()) {
  65. UIUtil.animateShowElement(
  66. $("#unableToUnmutePopup"), true, 5000);
  67. }
  68. else {
  69. JitsiMeetJS.analytics.sendEvent('toolbar.audio.unmuted');
  70. emitter.emit(UIEvents.AUDIO_MUTED, false, true);
  71. }
  72. } else {
  73. JitsiMeetJS.analytics.sendEvent('toolbar.audio.muted');
  74. emitter.emit(UIEvents.AUDIO_MUTED, true, true);
  75. }
  76. },
  77. "toolbar_button_camera": function () {
  78. if (APP.conference.videoMuted) {
  79. JitsiMeetJS.analytics.sendEvent('toolbar.video.enabled');
  80. emitter.emit(UIEvents.VIDEO_MUTED, false);
  81. } else {
  82. JitsiMeetJS.analytics.sendEvent('toolbar.video.disabled');
  83. emitter.emit(UIEvents.VIDEO_MUTED, true);
  84. }
  85. },
  86. "toolbar_button_security": function () {
  87. JitsiMeetJS.analytics.sendEvent('toolbar.lock.clicked');
  88. emitter.emit(UIEvents.ROOM_LOCK_CLICKED);
  89. },
  90. "toolbar_button_link": function () {
  91. JitsiMeetJS.analytics.sendEvent('toolbar.invite.clicked');
  92. openLinkDialog();
  93. },
  94. "toolbar_button_chat": function () {
  95. JitsiMeetJS.analytics.sendEvent('toolbar.chat.toggled');
  96. emitter.emit(UIEvents.TOGGLE_CHAT);
  97. },
  98. "toolbar_contact_list": function () {
  99. JitsiMeetJS.analytics.sendEvent(
  100. 'toolbar.contacts.toggled');
  101. emitter.emit(UIEvents.TOGGLE_CONTACT_LIST);
  102. },
  103. "toolbar_button_etherpad": function () {
  104. JitsiMeetJS.analytics.sendEvent('toolbar.etherpad.clicked');
  105. emitter.emit(UIEvents.ETHERPAD_CLICKED);
  106. },
  107. "toolbar_button_sharedvideo": function () {
  108. JitsiMeetJS.analytics.sendEvent('toolbar.sharedvideo.clicked');
  109. emitter.emit(UIEvents.SHARED_VIDEO_CLICKED);
  110. },
  111. "toolbar_button_desktopsharing": function () {
  112. if (APP.conference.isSharingScreen) {
  113. JitsiMeetJS.analytics.sendEvent('toolbar.screen.disabled');
  114. } else {
  115. JitsiMeetJS.analytics.sendEvent('toolbar.screen.enabled');
  116. }
  117. emitter.emit(UIEvents.TOGGLE_SCREENSHARING);
  118. },
  119. "toolbar_button_fullScreen": function() {
  120. JitsiMeetJS.analytics.sendEvent('toolbar.fullscreen.enabled');
  121. UIUtil.buttonClick("toolbar_button_fullScreen",
  122. "icon-full-screen icon-exit-full-screen");
  123. emitter.emit(UIEvents.FULLSCREEN_TOGGLE);
  124. },
  125. "toolbar_button_sip": function () {
  126. JitsiMeetJS.analytics.sendEvent('toolbar.sip.clicked');
  127. showSipNumberInput();
  128. },
  129. "toolbar_button_dialpad": function () {
  130. JitsiMeetJS.analytics.sendEvent('toolbar.sip.dialpad.clicked');
  131. dialpadButtonClicked();
  132. },
  133. "toolbar_button_settings": function () {
  134. JitsiMeetJS.analytics.sendEvent('toolbar.settings.toggled');
  135. emitter.emit(UIEvents.TOGGLE_SETTINGS);
  136. },
  137. "toolbar_button_hangup": function () {
  138. JitsiMeetJS.analytics.sendEvent('toolbar.hangup');
  139. emitter.emit(UIEvents.HANGUP);
  140. },
  141. "toolbar_button_login": function () {
  142. JitsiMeetJS.analytics.sendEvent('toolbar.authenticate.login.clicked');
  143. emitter.emit(UIEvents.AUTH_CLICKED);
  144. },
  145. "toolbar_button_logout": function () {
  146. JitsiMeetJS.analytics.sendEvent('toolbar.authenticate.logout.clicked');
  147. // Ask for confirmation
  148. APP.UI.messageHandler.openTwoButtonDialog(
  149. "dialog.logoutTitle",
  150. null,
  151. "dialog.logoutQuestion",
  152. null,
  153. false,
  154. "dialog.Yes",
  155. function (evt, yes) {
  156. if (yes) {
  157. emitter.emit(UIEvents.LOGOUT);
  158. }
  159. }
  160. );
  161. },
  162. "toolbar_film_strip": function () {
  163. JitsiMeetJS.analytics.sendEvent(
  164. 'bottomtoolbar.filmstrip.toggled');
  165. emitter.emit(UIEvents.TOGGLE_FILM_STRIP);
  166. }
  167. };
  168. const defaultToolbarButtons = {
  169. 'microphone': {
  170. id: 'toolbar_button_mute',
  171. className: "button icon-microphone",
  172. shortcut: 'M',
  173. shortcutAttr: 'mutePopover',
  174. shortcutFunc: function() {
  175. JitsiMeetJS.analytics.sendEvent('shortcut.audiomute.toggled');
  176. APP.conference.toggleAudioMuted();
  177. },
  178. shortcutDescription: "keyboardShortcuts.mute",
  179. popups: [
  180. {
  181. id: "micMutedPopup",
  182. className: "loginmenu",
  183. dataAttr: "[html]toolbar.micMutedPopup"
  184. },
  185. {
  186. id: "unableToUnmutePopup",
  187. className: "loginmenu",
  188. dataAttr: "[html]toolbar.unableToUnmutePopup"
  189. }
  190. ],
  191. content: "Mute / Unmute",
  192. i18n: "[content]toolbar.mute"
  193. },
  194. 'camera': {
  195. id: 'toolbar_button_camera',
  196. className: "button icon-camera",
  197. shortcut: 'V',
  198. shortcutAttr: 'toggleVideoPopover',
  199. shortcutFunc: function() {
  200. JitsiMeetJS.analytics.sendEvent('shortcut.videomute.toggled');
  201. APP.conference.toggleVideoMuted();
  202. },
  203. shortcutDescription: "keyboardShortcuts.videoMute",
  204. content: "Start / stop camera",
  205. i18n: "[content]toolbar.videomute"
  206. },
  207. 'desktop': {
  208. id: 'toolbar_button_desktopsharing',
  209. className: 'button icon-share-desktop',
  210. shortcut: 'D',
  211. shortcutAttr: 'toggleDesktopSharingPopover',
  212. shortcutFunc: function() {
  213. JitsiMeetJS.analytics.sendEvent('shortcut.screen.toggled');
  214. APP.conference.toggleScreenSharing();
  215. },
  216. shortcutDescription: 'keyboardShortcuts.toggleScreensharing',
  217. content: 'Share screen',
  218. i18n: '[content]toolbar.sharescreen'
  219. },
  220. 'security': {
  221. id: 'toolbar_button_security'
  222. },
  223. 'invite': {
  224. id: 'toolbar_button_link',
  225. className: 'button icon-link',
  226. content: 'Invite others',
  227. i18n: '[content]toolbar.invite'
  228. },
  229. 'chat': {
  230. id: 'toolbar_button_chat',
  231. shortcut: 'C',
  232. shortcutAttr: 'toggleChatPopover',
  233. shortcutFunc: function() {
  234. JitsiMeetJS.analytics.sendEvent('shortcut.chat.toggled');
  235. APP.UI.toggleChat();
  236. },
  237. shortcutDescription: 'keyboardShortcuts.toggleChat',
  238. sideContainerId: 'chat_container'
  239. },
  240. 'contacts': {
  241. id: 'toolbar_contact_list',
  242. sideContainerId: 'contacts_container'
  243. },
  244. 'profile': {
  245. id: 'toolbar_button_profile',
  246. sideContainerId: 'profile_container'
  247. },
  248. 'etherpad': {
  249. id: 'toolbar_button_etherpad'
  250. },
  251. 'fullscreen': {
  252. id: 'toolbar_button_fullScreen',
  253. className: "button icon-full-screen",
  254. shortcut: 'F',
  255. shortcutAttr: 'toggleFullscreenPopover',
  256. shortcutFunc: function() {
  257. JitsiMeetJS.analytics.sendEvent('shortcut.fullscreen.toggled');
  258. APP.UI.toggleFullScreen();
  259. },
  260. shortcutDescription: "keyboardShortcuts.toggleChat",
  261. content: "Enter / Exit Full Screen",
  262. i18n: "[content]toolbar.fullscreen"
  263. },
  264. 'settings': {
  265. id: 'toolbar_button_settings',
  266. sideContainerId: "settings_container"
  267. },
  268. 'hangup': {
  269. id: 'toolbar_button_hangup',
  270. className: "button icon-hangup",
  271. content: "Hang Up",
  272. i18n: "[content]toolbar.hangup"
  273. },
  274. 'filmstrip': {
  275. id: 'toolbar_film_strip',
  276. shortcut: "F",
  277. shortcutAttr: "filmstripPopover",
  278. shortcutFunc: function() {
  279. JitsiMeetJS.analytics.sendEvent("shortcut.film.toggled");
  280. APP.UI.toggleFilmStrip();
  281. },
  282. shortcutDescription: "keyboardShortcuts.toggleFilmstrip"
  283. }
  284. };
  285. function dialpadButtonClicked() {
  286. //TODO show the dialpad box
  287. }
  288. function showSipNumberInput () {
  289. let defaultNumber = config.defaultSipNumber
  290. ? config.defaultSipNumber
  291. : '';
  292. let sipMsg = APP.translation.generateTranslationHTML("dialog.sipMsg");
  293. APP.UI.messageHandler.openTwoButtonDialog(
  294. null, null, null,
  295. `<h2>${sipMsg}</h2>
  296. <input name="sipNumber" type="text" value="${defaultNumber}" autofocus>`,
  297. false, "dialog.Dial",
  298. function (e, v, m, f) {
  299. if (v && f.sipNumber) {
  300. emitter.emit(UIEvents.SIP_DIAL, f.sipNumber);
  301. }
  302. },
  303. null, null, ':input:first'
  304. );
  305. }
  306. const Toolbar = {
  307. init (eventEmitter) {
  308. emitter = eventEmitter;
  309. // The toolbar is enabled by default.
  310. this.enabled = true;
  311. this.toolbarSelector = $("#mainToolbarContainer");
  312. this.extendedToolbarSelector = $("#extendedToolbar");
  313. this._initMainToolbarButtons();
  314. UIUtil.hideDisabledButtons(defaultToolbarButtons);
  315. Object.keys(defaultToolbarButtons).forEach(
  316. id => {
  317. if (UIUtil.isButtonEnabled(id)) {
  318. var button = defaultToolbarButtons[id];
  319. if (button.shortcut)
  320. APP.keyboardshortcut.registerShortcut(
  321. button.shortcut,
  322. button.shortcutAttr,
  323. button.shortcutFunc,
  324. button.shortcutDescription
  325. );
  326. }
  327. }
  328. );
  329. Object.keys(buttonHandlers).forEach(
  330. buttonId => $(`#${buttonId}`).click(function(event) {
  331. !$(this).prop('disabled') && buttonHandlers[buttonId](event);
  332. })
  333. );
  334. APP.UI.addListener(UIEvents.SIDE_TOOLBAR_CONTAINER_TOGGLED,
  335. function(containerId, isVisible) {
  336. Toolbar._handleSideToolbarContainerToggled( containerId,
  337. isVisible);
  338. });
  339. },
  340. /**
  341. * Enables / disables the toolbar.
  342. * @param {e} set to {true} to enable the toolbar or {false}
  343. * to disable it
  344. */
  345. enable (e) {
  346. this.enabled = e;
  347. if (!e && this.isVisible())
  348. this.hide(false);
  349. },
  350. /**
  351. * Indicates if the bottom toolbar is currently enabled.
  352. * @return {this.enabled}
  353. */
  354. isEnabled() {
  355. return this.enabled;
  356. },
  357. /**
  358. * Updates the room invite url.
  359. */
  360. updateRoomUrl (newRoomUrl) {
  361. roomUrl = newRoomUrl;
  362. // If the invite dialog has been already opened we update the
  363. // information.
  364. let inviteLink = document.getElementById('inviteLinkRef');
  365. if (inviteLink) {
  366. inviteLink.value = roomUrl;
  367. inviteLink.select();
  368. $('#inviteLinkRef').parent()
  369. .find('button[value=true]').prop('disabled', false);
  370. }
  371. },
  372. /**
  373. * Unlocks the lock button state.
  374. */
  375. unlockLockButton () {
  376. if ($("#toolbar_button_security").hasClass("icon-security-locked"))
  377. UIUtil.buttonClick("toolbar_button_security",
  378. "icon-security icon-security-locked");
  379. },
  380. /**
  381. * Updates the lock button state to locked.
  382. */
  383. lockLockButton () {
  384. if ($("#toolbar_button_security").hasClass("icon-security"))
  385. UIUtil.buttonClick("toolbar_button_security",
  386. "icon-security icon-security-locked");
  387. },
  388. /**
  389. * Shows or hides authentication button
  390. * @param show <tt>true</tt> to show or <tt>false</tt> to hide
  391. */
  392. showAuthenticateButton (show) {
  393. if (UIUtil.isButtonEnabled('authentication') && show) {
  394. $('#authentication').css({display: "inline"});
  395. } else {
  396. $('#authentication').css({display: "none"});
  397. }
  398. },
  399. showEtherpadButton () {
  400. if (!$('#toolbar_button_etherpad').is(":visible")) {
  401. $('#toolbar_button_etherpad').css({display: 'inline-block'});
  402. }
  403. },
  404. // Shows or hides the 'shared video' button.
  405. showSharedVideoButton () {
  406. if (UIUtil.isButtonEnabled('sharedvideo')
  407. && config.disableThirdPartyRequests !== true) {
  408. $('#toolbar_button_sharedvideo').css({display: "inline-block"});
  409. } else {
  410. $('#toolbar_button_sharedvideo').css({display: "none"});
  411. }
  412. },
  413. // checks whether desktop sharing is enabled and whether
  414. // we have params to start automatically sharing
  415. checkAutoEnableDesktopSharing () {
  416. if (UIUtil.isButtonEnabled('desktop')
  417. && config.autoEnableDesktopSharing) {
  418. emitter.emit(UIEvents.TOGGLE_SCREENSHARING);
  419. }
  420. },
  421. // Shows or hides SIP calls button
  422. showSipCallButton (show) {
  423. if (APP.conference.sipGatewayEnabled()
  424. && UIUtil.isButtonEnabled('sip') && show) {
  425. $('#toolbar_button_sip').css({display: "inline-block"});
  426. } else {
  427. $('#toolbar_button_sip').css({display: "none"});
  428. }
  429. },
  430. // Shows or hides the dialpad button
  431. showDialPadButton (show) {
  432. if (UIUtil.isButtonEnabled('dialpad') && show) {
  433. $('#toolbar_button_dialpad').css({display: "inline-block"});
  434. } else {
  435. $('#toolbar_button_dialpad').css({display: "none"});
  436. }
  437. },
  438. /**
  439. * Displays user authenticated identity name(login).
  440. * @param authIdentity identity name to be displayed.
  441. */
  442. setAuthenticatedIdentity (authIdentity) {
  443. if (authIdentity) {
  444. let selector = $('#toolbar_auth_identity');
  445. selector.css({display: "list-item"});
  446. selector.text(authIdentity);
  447. } else {
  448. $('#toolbar_auth_identity').css({display: "none"});
  449. }
  450. },
  451. /**
  452. * Shows/hides login button.
  453. * @param show <tt>true</tt> to show
  454. */
  455. showLoginButton (show) {
  456. if (UIUtil.isButtonEnabled('authentication') && show) {
  457. $('#toolbar_button_login').css({display: "list-item"});
  458. } else {
  459. $('#toolbar_button_login').css({display: "none"});
  460. }
  461. },
  462. /**
  463. * Shows/hides logout button.
  464. * @param show <tt>true</tt> to show
  465. */
  466. showLogoutButton (show) {
  467. if (UIUtil.isButtonEnabled('authentication') && show) {
  468. $('#toolbar_button_logout').css({display: "list-item"});
  469. } else {
  470. $('#toolbar_button_logout').css({display: "none"});
  471. }
  472. },
  473. /**
  474. * Update the state of the button. The button has blue glow if desktop
  475. * streaming is active.
  476. */
  477. updateDesktopSharingButtonState () {
  478. let button = $("#toolbar_button_desktopsharing");
  479. if (APP.conference.isSharingScreen) {
  480. button.addClass("glow");
  481. } else {
  482. button.removeClass("glow");
  483. }
  484. },
  485. /**
  486. * Marks video icon as muted or not.
  487. * @param {boolean} muted if icon should look like muted or not
  488. */
  489. markVideoIconAsMuted (muted) {
  490. $('#toolbar_button_camera').toggleClass("icon-camera-disabled", muted);
  491. },
  492. /**
  493. * Marks video icon as disabled or not.
  494. * @param {boolean} disabled if icon should look like disabled or not
  495. */
  496. markVideoIconAsDisabled (disabled) {
  497. var $btn = $('#toolbar_button_camera');
  498. $btn
  499. .prop("disabled", disabled)
  500. .attr("data-i18n", disabled
  501. ? "[content]toolbar.cameraDisabled"
  502. : "[content]toolbar.videomute")
  503. .attr("shortcut", disabled ? "" : "toggleVideoPopover");
  504. disabled
  505. ? $btn.attr("disabled", "disabled")
  506. : $btn.removeAttr("disabled");
  507. APP.translation.translateElement($btn);
  508. disabled && this.markVideoIconAsMuted(disabled);
  509. },
  510. /**
  511. * Marks audio icon as muted or not.
  512. * @param {boolean} muted if icon should look like muted or not
  513. */
  514. markAudioIconAsMuted (muted) {
  515. $('#toolbar_button_mute').toggleClass("icon-microphone",
  516. !muted).toggleClass("icon-mic-disabled", muted);
  517. },
  518. /**
  519. * Marks audio icon as disabled or not.
  520. * @param {boolean} disabled if icon should look like disabled or not
  521. */
  522. markAudioIconAsDisabled (disabled) {
  523. var $btn = $('#toolbar_button_mute');
  524. $btn
  525. .prop("disabled", disabled)
  526. .attr("data-i18n", disabled
  527. ? "[content]toolbar.micDisabled"
  528. : "[content]toolbar.mute")
  529. .attr("shortcut", disabled ? "" : "mutePopover");
  530. disabled
  531. ? $btn.attr("disabled", "disabled")
  532. : $btn.removeAttr("disabled");
  533. APP.translation.translateElement($btn);
  534. disabled && this.markAudioIconAsMuted(disabled);
  535. },
  536. /**
  537. * Indicates if the toolbar is currently hovered.
  538. * @return {boolean} true if the toolbar is currently hovered,
  539. * false otherwise
  540. */
  541. isHovered() {
  542. var hovered = false;
  543. this.toolbarSelector.find('*').each(function () {
  544. let id = $(this).attr('id');
  545. if ($(`#${id}:hover`).length > 0) {
  546. hovered = true;
  547. // break each
  548. return false;
  549. }
  550. });
  551. if (hovered)
  552. return true;
  553. if ($("#bottomToolbar:hover").length > 0
  554. || $("#extendedToolbar:hover").length > 0
  555. || SideContainerToggler.isHovered()) {
  556. return true;
  557. }
  558. return false;
  559. },
  560. /**
  561. * Returns true if this toolbar is currently visible, or false otherwise.
  562. * @return <tt>true</tt> if currently visible, <tt>false</tt> - otherwise
  563. */
  564. isVisible() {
  565. return this.toolbarSelector.hasClass("slideInY");
  566. },
  567. /**
  568. * Hides the toolbar with animation or not depending on the animate
  569. * parameter.
  570. */
  571. hide() {
  572. this.toolbarSelector.toggleClass("slideInY").toggleClass("slideOutY");
  573. let slideInAnimation = (SideContainerToggler.isVisible)
  574. ? "slideInExtX"
  575. : "slideInX";
  576. let slideOutAnimation = (SideContainerToggler.isVisible)
  577. ? "slideOutExtX"
  578. : "slideOutX";
  579. this.extendedToolbarSelector.toggleClass(slideInAnimation)
  580. .toggleClass(slideOutAnimation);
  581. },
  582. /**
  583. * Shows the toolbar with animation or not depending on the animate
  584. * parameter.
  585. */
  586. show() {
  587. if (this.toolbarSelector.hasClass("slideOutY"))
  588. this.toolbarSelector.toggleClass("slideOutY");
  589. let slideInAnimation = (SideContainerToggler.isVisible)
  590. ? "slideInExtX"
  591. : "slideInX";
  592. let slideOutAnimation = (SideContainerToggler.isVisible)
  593. ? "slideOutExtX"
  594. : "slideOutX";
  595. if (this.extendedToolbarSelector.hasClass(slideOutAnimation))
  596. this.extendedToolbarSelector.toggleClass(slideOutAnimation);
  597. this.toolbarSelector.toggleClass("slideInY");
  598. this.extendedToolbarSelector.toggleClass(slideInAnimation);
  599. },
  600. registerClickListeners(listener) {
  601. $('#mainToolbarContainer').click(listener);
  602. $("#extendedToolbar").click(listener);
  603. },
  604. /**
  605. * Handles the side toolbar toggle.
  606. */
  607. _handleSideToolbarContainerToggled(containerId, isVisible) {
  608. Object.keys(defaultToolbarButtons).forEach(
  609. id => {
  610. if (!UIUtil.isButtonEnabled(id))
  611. return;
  612. var button = defaultToolbarButtons[id];
  613. if (button.sideContainerId
  614. && button.sideContainerId === containerId) {
  615. UIUtil.buttonClick(button.id, "selected");
  616. return;
  617. }
  618. }
  619. );
  620. },
  621. /**
  622. * TODO: Fix mic popups
  623. * <a class="button icon-microphone" id="toolbar_button_mute" data-container="body" data-toggle="popover" data-placement="bottom" shortcut="mutePopover" data-i18n="[content]toolbar.mute" content="Mute / Unmute">
  624. * <ul id="micMutedPopup" class="loginmenu">
  625. * <li data-i18n="[html]toolbar.micMutedPopup"></li>
  626. * </ul>
  627. * <ul id="unableToUnmutePopup" class="loginmenu">
  628. * <li data-i18n="[html]toolbar.unableToUnmutePopup"></li>
  629. * </ul>
  630. * </a>
  631. */
  632. _initMainToolbarButtons() {
  633. interfaceConfig.MAIN_TOOLBAR_BUTTONS.forEach((value, index) => {
  634. if (value && value in defaultToolbarButtons) {
  635. let button = defaultToolbarButtons[value];
  636. this._addMainToolbarButton(
  637. button,
  638. (index === 0),
  639. (index === interfaceConfig.MAIN_TOOLBAR_BUTTONS.length -1));
  640. }
  641. });
  642. },
  643. /**
  644. * Adds the given button to the main (top) toolbar.
  645. *
  646. * @param {Object} the button to add.
  647. * @param {boolean} isFirst indicates if this is the first button in the
  648. * toolbar
  649. * @param {boolean} isLast indicates if this is the last button in the
  650. * toolbar
  651. */
  652. _addMainToolbarButton(button, isFirst, isLast) {
  653. let buttonElement = document.createElement("a");
  654. if (button.className)
  655. buttonElement.className = button.className
  656. + ((isFirst) ? " first" : "")
  657. + ((isLast) ? " last" : "");
  658. buttonElement.id = button.id;
  659. if (button.shortcutAttr)
  660. buttonElement.setAttribute("shortcut", button.shortcutAttr);
  661. if (button.content)
  662. buttonElement.setAttribute("content", button.content);
  663. if (button.i18n)
  664. buttonElement.setAttribute("data-i18n", button.i18n);
  665. buttonElement.setAttribute("data-container", "body");
  666. buttonElement.setAttribute("data-toggle", "popover");
  667. buttonElement.setAttribute("data-placement", "bottom");
  668. this._addPopups(buttonElement, button.popups);
  669. document.getElementById("mainToolbar")
  670. .appendChild(buttonElement);
  671. },
  672. _addPopups(buttonElement, popups = []) {
  673. popups.forEach((popup) => {
  674. let popupElement = document.createElement("ul");
  675. popupElement.id = popup.id;
  676. popupElement.className = popup.className;
  677. let liElement = document.createElement("li");
  678. liElement.setAttribute("data-i18n", popup.dataAttr);
  679. popupElement.appendChild(liElement);
  680. buttonElement.appendChild(popupElement);
  681. });
  682. }
  683. };
  684. export default Toolbar;