您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Toolbar.js 27KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805
  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. }
  390. },
  391. /**
  392. * Enables / disables the toolbar.
  393. * @param {e} set to {true} to enable the toolbar or {false}
  394. * to disable it
  395. */
  396. enable (e) {
  397. this.enabled = e;
  398. if (!e && this.isVisible())
  399. this.hide(false);
  400. },
  401. /**
  402. * Indicates if the bottom toolbar is currently enabled.
  403. * @return {this.enabled}
  404. */
  405. isEnabled() {
  406. return this.enabled;
  407. },
  408. /**
  409. * Updates the room invite url.
  410. */
  411. updateRoomUrl (newRoomUrl) {
  412. roomUrl = newRoomUrl;
  413. // If the invite dialog has been already opened we update the
  414. // information.
  415. let inviteLink = document.getElementById('inviteLinkRef');
  416. if (inviteLink) {
  417. inviteLink.value = roomUrl;
  418. inviteLink.select();
  419. $('#inviteLinkRef').parent()
  420. .find('button[value=true]').prop('disabled', false);
  421. }
  422. },
  423. /**
  424. * Unlocks the lock button state.
  425. */
  426. unlockLockButton () {
  427. if ($("#toolbar_button_security").hasClass("icon-security-locked"))
  428. UIUtil.buttonClick("toolbar_button_security",
  429. "icon-security icon-security-locked");
  430. },
  431. /**
  432. * Updates the lock button state to locked.
  433. */
  434. lockLockButton () {
  435. if ($("#toolbar_button_security").hasClass("icon-security"))
  436. UIUtil.buttonClick("toolbar_button_security",
  437. "icon-security icon-security-locked");
  438. },
  439. /**
  440. * Shows or hides authentication button
  441. * @param show <tt>true</tt> to show or <tt>false</tt> to hide
  442. */
  443. showAuthenticateButton (show) {
  444. if (UIUtil.isButtonEnabled('authentication') && show) {
  445. $('#authentication').css({display: "inline"});
  446. } else {
  447. $('#authentication').css({display: "none"});
  448. }
  449. },
  450. showEtherpadButton () {
  451. if (!$('#toolbar_button_etherpad').is(":visible")) {
  452. $('#toolbar_button_etherpad').css({display: 'inline-block'});
  453. }
  454. },
  455. // Shows or hides the 'shared video' button.
  456. showSharedVideoButton () {
  457. let $element = $('#toolbar_button_sharedvideo');
  458. if (UIUtil.isButtonEnabled('sharedvideo')
  459. && config.disableThirdPartyRequests !== true) {
  460. $element.css({display: "inline-block"});
  461. UIUtil.setTooltip($element.get(0), 'toolbar.sharedvideo', 'right');
  462. } else {
  463. $('#toolbar_button_sharedvideo').css({display: "none"});
  464. }
  465. },
  466. // checks whether desktop sharing is enabled and whether
  467. // we have params to start automatically sharing
  468. checkAutoEnableDesktopSharing () {
  469. if (UIUtil.isButtonEnabled('desktop')
  470. && config.autoEnableDesktopSharing) {
  471. emitter.emit(UIEvents.TOGGLE_SCREENSHARING);
  472. }
  473. },
  474. // Shows or hides SIP calls button
  475. showSipCallButton (show) {
  476. if (APP.conference.sipGatewayEnabled()
  477. && UIUtil.isButtonEnabled('sip') && show) {
  478. $('#toolbar_button_sip').css({display: "inline-block"});
  479. } else {
  480. $('#toolbar_button_sip').css({display: "none"});
  481. }
  482. },
  483. // Shows or hides the dialpad button
  484. showDialPadButton (show) {
  485. if (UIUtil.isButtonEnabled('dialpad') && show) {
  486. $('#toolbar_button_dialpad').css({display: "inline-block"});
  487. } else {
  488. $('#toolbar_button_dialpad').css({display: "none"});
  489. }
  490. },
  491. /**
  492. * Displays user authenticated identity name(login).
  493. * @param authIdentity identity name to be displayed.
  494. */
  495. setAuthenticatedIdentity (authIdentity) {
  496. if (authIdentity) {
  497. let selector = $('#toolbar_auth_identity');
  498. selector.css({display: "list-item"});
  499. selector.text(authIdentity);
  500. } else {
  501. $('#toolbar_auth_identity').css({display: "none"});
  502. }
  503. },
  504. /**
  505. * Shows/hides login button.
  506. * @param show <tt>true</tt> to show
  507. */
  508. showLoginButton (show) {
  509. if (UIUtil.isButtonEnabled('authentication') && show) {
  510. $('#toolbar_button_login').css({display: "list-item"});
  511. } else {
  512. $('#toolbar_button_login').css({display: "none"});
  513. }
  514. },
  515. /**
  516. * Shows/hides logout button.
  517. * @param show <tt>true</tt> to show
  518. */
  519. showLogoutButton (show) {
  520. if (UIUtil.isButtonEnabled('authentication') && show) {
  521. $('#toolbar_button_logout').css({display: "list-item"});
  522. } else {
  523. $('#toolbar_button_logout').css({display: "none"});
  524. }
  525. },
  526. /**
  527. * Update the state of the button. The button has blue glow if desktop
  528. * streaming is active.
  529. */
  530. updateDesktopSharingButtonState () {
  531. let button = $("#toolbar_button_desktopsharing");
  532. if (APP.conference.isSharingScreen) {
  533. button.addClass("glow");
  534. } else {
  535. button.removeClass("glow");
  536. }
  537. },
  538. /**
  539. * Toggles / untoggles the view for raised hand.
  540. */
  541. _toggleRaiseHand(isRaisedHand) {
  542. $('#toolbar_button_raisehand').toggleClass("toggled", isRaisedHand);
  543. },
  544. /**
  545. * Marks video icon as muted or not.
  546. * @param {boolean} muted if icon should look like muted or not
  547. */
  548. markVideoIconAsMuted (muted) {
  549. $('#toolbar_button_camera').toggleClass("icon-camera-disabled", muted);
  550. },
  551. /**
  552. * Marks video icon as disabled or not.
  553. * @param {boolean} disabled if icon should look like disabled or not
  554. */
  555. markVideoIconAsDisabled (disabled) {
  556. var $btn = $('#toolbar_button_camera');
  557. $btn
  558. .prop("disabled", disabled)
  559. .attr("data-i18n", disabled
  560. ? "[content]toolbar.cameraDisabled"
  561. : "[content]toolbar.videomute")
  562. .attr("shortcut", disabled ? "" : "toggleVideoPopover");
  563. disabled
  564. ? $btn.attr("disabled", "disabled")
  565. : $btn.removeAttr("disabled");
  566. APP.translation.translateElement($btn);
  567. disabled && this.markVideoIconAsMuted(disabled);
  568. },
  569. /**
  570. * Marks audio icon as muted or not.
  571. * @param {boolean} muted if icon should look like muted or not
  572. */
  573. markAudioIconAsMuted (muted) {
  574. $('#toolbar_button_mute').toggleClass("icon-microphone",
  575. !muted).toggleClass("icon-mic-disabled", muted);
  576. },
  577. /**
  578. * Marks audio icon as disabled or not.
  579. * @param {boolean} disabled if icon should look like disabled or not
  580. */
  581. markAudioIconAsDisabled (disabled) {
  582. var $btn = $('#toolbar_button_mute');
  583. $btn
  584. .prop("disabled", disabled)
  585. .attr("data-i18n", disabled
  586. ? "[content]toolbar.micDisabled"
  587. : "[content]toolbar.mute")
  588. .attr("shortcut", disabled ? "" : "mutePopover");
  589. disabled
  590. ? $btn.attr("disabled", "disabled")
  591. : $btn.removeAttr("disabled");
  592. APP.translation.translateElement($btn);
  593. disabled && this.markAudioIconAsMuted(disabled);
  594. },
  595. /**
  596. * Indicates if the toolbar is currently hovered.
  597. * @return {boolean} true if the toolbar is currently hovered,
  598. * false otherwise
  599. */
  600. isHovered() {
  601. var hovered = false;
  602. this.toolbarSelector.find('*').each(function () {
  603. let id = $(this).attr('id');
  604. if ($(`#${id}:hover`).length > 0) {
  605. hovered = true;
  606. // break each
  607. return false;
  608. }
  609. });
  610. if (hovered)
  611. return true;
  612. if ($("#bottomToolbar:hover").length > 0
  613. || $("#extendedToolbar:hover").length > 0
  614. || SideContainerToggler.isHovered()) {
  615. return true;
  616. }
  617. return false;
  618. },
  619. /**
  620. * Returns true if this toolbar is currently visible, or false otherwise.
  621. * @return <tt>true</tt> if currently visible, <tt>false</tt> - otherwise
  622. */
  623. isVisible() {
  624. return this.toolbarSelector.hasClass("slideInY");
  625. },
  626. /**
  627. * Hides the toolbar with animation or not depending on the animate
  628. * parameter.
  629. */
  630. hide() {
  631. this.toolbarSelector.toggleClass("slideInY").toggleClass("slideOutY");
  632. let slideInAnimation = (SideContainerToggler.isVisible)
  633. ? "slideInExtX"
  634. : "slideInX";
  635. let slideOutAnimation = (SideContainerToggler.isVisible)
  636. ? "slideOutExtX"
  637. : "slideOutX";
  638. this.extendedToolbarSelector.toggleClass(slideInAnimation)
  639. .toggleClass(slideOutAnimation);
  640. },
  641. /**
  642. * Shows the toolbar with animation or not depending on the animate
  643. * parameter.
  644. */
  645. show() {
  646. if (this.toolbarSelector.hasClass("slideOutY"))
  647. this.toolbarSelector.toggleClass("slideOutY");
  648. let slideInAnimation = (SideContainerToggler.isVisible)
  649. ? "slideInExtX"
  650. : "slideInX";
  651. let slideOutAnimation = (SideContainerToggler.isVisible)
  652. ? "slideOutExtX"
  653. : "slideOutX";
  654. if (this.extendedToolbarSelector.hasClass(slideOutAnimation))
  655. this.extendedToolbarSelector.toggleClass(slideOutAnimation);
  656. this.toolbarSelector.toggleClass("slideInY");
  657. this.extendedToolbarSelector.toggleClass(slideInAnimation);
  658. },
  659. registerClickListeners(listener) {
  660. $('#mainToolbarContainer').click(listener);
  661. $("#extendedToolbar").click(listener);
  662. },
  663. /**
  664. * Handles the side toolbar toggle.
  665. */
  666. _handleSideToolbarContainerToggled(containerId, isVisible) {
  667. Object.keys(defaultToolbarButtons).forEach(
  668. id => {
  669. if (!UIUtil.isButtonEnabled(id))
  670. return;
  671. var button = defaultToolbarButtons[id];
  672. if (button.sideContainerId
  673. && button.sideContainerId === containerId) {
  674. UIUtil.buttonClick(button.id, "selected");
  675. return;
  676. }
  677. }
  678. );
  679. },
  680. /**
  681. * Initialise main toolbar buttons.
  682. */
  683. _initMainToolbarButtons() {
  684. interfaceConfig.MAIN_TOOLBAR_BUTTONS.forEach((value, index) => {
  685. if (value && value in defaultToolbarButtons) {
  686. let button = defaultToolbarButtons[value];
  687. this._addMainToolbarButton(
  688. button,
  689. (index === 0),
  690. (index === interfaceConfig.MAIN_TOOLBAR_BUTTONS.length -1));
  691. }
  692. });
  693. },
  694. /**
  695. * Adds the given button to the main (top) toolbar.
  696. *
  697. * @param {Object} the button to add.
  698. * @param {boolean} isFirst indicates if this is the first button in the
  699. * toolbar
  700. * @param {boolean} isLast indicates if this is the last button in the
  701. * toolbar
  702. */
  703. _addMainToolbarButton(button, isFirst, isLast) {
  704. let buttonElement = document.createElement("a");
  705. if (button.className)
  706. buttonElement.className = button.className
  707. + ((isFirst) ? " first" : "")
  708. + ((isLast) ? " last" : "");
  709. buttonElement.id = button.id;
  710. if (button.shortcutAttr)
  711. buttonElement.setAttribute("shortcut", button.shortcutAttr);
  712. if (button.content)
  713. buttonElement.setAttribute("content", button.content);
  714. if (button.i18n)
  715. buttonElement.setAttribute("data-i18n", button.i18n);
  716. buttonElement.setAttribute("data-container", "body");
  717. buttonElement.setAttribute("data-placement", "bottom");
  718. this._addPopups(buttonElement, button.popups);
  719. document.getElementById("mainToolbar")
  720. .appendChild(buttonElement);
  721. },
  722. _addPopups(buttonElement, popups = []) {
  723. popups.forEach((popup) => {
  724. let popupElement = document.createElement("ul");
  725. popupElement.id = popup.id;
  726. popupElement.className = popup.className;
  727. let liElement = document.createElement("li");
  728. liElement.setAttribute("data-i18n", popup.dataAttr);
  729. popupElement.appendChild(liElement);
  730. buttonElement.appendChild(popupElement);
  731. });
  732. }
  733. };
  734. export default Toolbar;