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

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