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 27KB

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